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], Ming Lei <[email protected]>
Subject: [PATCH for-next 2/4] io_uring: turn implicit assumptions into a warning
Date: Fri,  5 Apr 2024 16:50:03 +0100	[thread overview]
Message-ID: <1013b60c35d431d0698cafbc53c06f5917348c20.1712331455.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

io_req_complete_post() is now io-wq only and shouldn't be used outside
of it, i.e. it relies that io-wq holds a ref for the request as
explained in a comment below. Let's add a warning to enforce the
assumption and make sure nobody would try to do anything weird.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/io_uring.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index b7f742fe9d41..c84650b0f7f2 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -931,6 +931,13 @@ static void io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 
+	/*
+	 * All execution paths but io-wq use the deferred completions by
+	 * passing IO_URING_F_COMPLETE_DEFER and thus should not end up here.
+	 */
+	if (WARN_ON_ONCE(!(issue_flags & IO_URING_F_IOWQ)))
+		return;
+
 	/*
 	 * Handle special CQ sync cases via task_work. DEFER_TASKRUN requires
 	 * the submitter task context, IOPOLL protects with uring_lock.
@@ -948,7 +955,10 @@ static void io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
 	}
 	io_cq_unlock_post(ctx);
 
-	/* called from io-wq submit work only, the ref won't drop to zero */
+	/*
+	 * We don't free the request here because we know it's called from
+	 * io-wq only, which holds a reference, so it cannot be the last put.
+	 */
 	req_ref_put(req);
 }
 
-- 
2.44.0


  parent reply	other threads:[~2024-04-05 15:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 15:50 [PATCH for-next 0/4] clean up io_req_complete_post Pavel Begunkov
2024-04-05 15:50 ` [PATCH for-next 1/4] io_uring: kill dead code in io_req_complete_post Pavel Begunkov
2024-04-05 15:50 ` Pavel Begunkov [this message]
2024-04-06 13:21   ` [PATCH for-next 2/4] io_uring: turn implicit assumptions into a warning Ming Lei
2024-04-05 15:50 ` [PATCH for-next 3/4] io_uring: remove async request cache Pavel Begunkov
2024-04-06 13:26   ` Ming Lei
2024-04-05 15:50 ` [PATCH for-next 4/4] io_uring: remove io_req_put_rsrc_locked() Pavel Begunkov
2024-04-06 13:28   ` Ming Lei
2024-04-06  2:06 ` [PATCH for-next 0/4] clean up io_req_complete_post 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=1013b60c35d431d0698cafbc53c06f5917348c20.1712331455.git.asml.silence@gmail.com \
    [email protected] \
    [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