public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH for-next 3/5] io_uring: simplify fallback execution
Date: Mon, 16 Jan 2023 16:48:59 +0000	[thread overview]
Message-ID: <56170e6a0cbfc8edee2794c6613e8f6f1d76d276.1673887636.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Lock the ring with uring_lock in io_fallback_req_func(), which should
make it a bit safer and easier. With that we also don't need refs
pinning as io_ring_exit_work() will wait until uring_lock is freed.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/io_uring.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 1b72ff558c17..e690c884dc95 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -245,17 +245,15 @@ static __cold void io_fallback_req_func(struct work_struct *work)
 						fallback_work.work);
 	struct llist_node *node = llist_del_all(&ctx->fallback_llist);
 	struct io_kiocb *req, *tmp;
-	bool locked = false;
+	bool locked = true;
 
-	percpu_ref_get(&ctx->refs);
+	mutex_lock(&ctx->uring_lock);
 	llist_for_each_entry_safe(req, tmp, node, io_task_work.node)
 		req->io_task_work.func(req, &locked);
-
-	if (locked) {
-		io_submit_flush_completions(ctx);
-		mutex_unlock(&ctx->uring_lock);
-	}
-	percpu_ref_put(&ctx->refs);
+	if (WARN_ON_ONCE(!locked))
+		return;
+	io_submit_flush_completions(ctx);
+	mutex_unlock(&ctx->uring_lock);
 }
 
 static int io_alloc_hash_table(struct io_hash_table *table, unsigned bits)
-- 
2.38.1


  parent reply	other threads:[~2023-01-16 17:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 16:48 [PATCH for-next 0/5] random for-next patches Pavel Begunkov
2023-01-16 16:48 ` [PATCH for-next 1/5] io_uring: return back links tw run optimisation Pavel Begunkov
2023-01-16 18:43   ` Jens Axboe
2023-01-16 19:47     ` Pavel Begunkov
2023-01-16 21:04       ` Jens Axboe
2023-01-16 21:14         ` Pavel Begunkov
2023-01-16 21:17           ` Jens Axboe
2023-01-16 21:15         ` Pavel Begunkov
2023-01-16 21:18           ` Jens Axboe
2023-01-16 16:48 ` [PATCH for-next 2/5] io_uring: don't export io_put_task() Pavel Begunkov
2023-01-16 16:48 ` Pavel Begunkov [this message]
2023-01-16 16:49 ` [PATCH for-next 4/5] io_uring: optimise ctx flags layout Pavel Begunkov
2023-01-16 16:49 ` [PATCH for-next 5/5] io_uring: refactor __io_req_complete_post Pavel Begunkov
2023-01-16 21:09 ` [PATCH for-next 0/5] random for-next patches Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56170e6a0cbfc8edee2794c6613e8f6f1d76d276.1673887636.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox