diff mbox series

[for-next,2/4] io_uring: turn implicit assumptions into a warning

Message ID 1013b60c35d431d0698cafbc53c06f5917348c20.1712331455.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series clean up io_req_complete_post | expand

Commit Message

Pavel Begunkov April 5, 2024, 3:50 p.m. UTC
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 <asml.silence@gmail.com>
---
 io_uring/io_uring.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Ming Lei April 6, 2024, 1:21 p.m. UTC | #1
On Fri, Apr 05, 2024 at 04:50:03PM +0100, Pavel Begunkov wrote:
> 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 <asml.silence@gmail.com>

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming
diff mbox series

Patch

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);
 }