From: Woraphat Khiaodaeng <worapat.kd2@gmail.com>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dev>,
Woraphat Khiaodaeng <worapat.kd2@gmail.com>
Subject: [PATCH] io_uring: restore RCU read section in io_req_local_work_add()
Date: Thu, 9 Jul 2026 10:51:00 +0700 [thread overview]
Message-ID: <20260709035100.2269-1-worapat.kd2@gmail.com> (raw)
The task-work refactor that moved io_req_local_work_add() out of
io_uring.c into the new io_uring/tw.c dropped the whole-body guard(rcu)()
that used to cover the function body.
For DEFER_TASKRUN rings the ring teardown still relies on that RCU read
section pairing with its grace period:
/* pairs with RCU read section in io_req_local_work_add() */
if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
synchronize_rcu();
io_ring_ctx_free(ctx);
io_req_local_work_add() keeps dereferencing ctx after mpscq_push() has
published the request to the work list (ctx->cq_wait_nr, and
ctx->submitter_task in the final wake_up_state()), without holding a ctx
reference across that window. The RCU read section was the only thing
guaranteeing an in-flight adder had finished touching ctx before
io_ring_ctx_free() ran; synchronize_rcu() only waits for readers that
are actually inside an RCU read-side critical section. With the guard
gone the grace period no longer pairs with anything on the add side, so
ctx can be freed and reused while io_req_local_work_add() is still using
it.
Restore the guard(rcu)() over the function body, matching the teardown
pairing and the pre-refactor code (the guard was present when the
function still lived in io_uring.c in v6.12).
Fixes: d46ab2c98aba ("io_uring: switch local task_work to a mpscq")
Signed-off-by: Woraphat Khiaodaeng <worapat.kd2@gmail.com>
---
io_uring/tw.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/io_uring/tw.c b/io_uring/tw.c
index a4c872870..4f7a0d107 100644
--- a/io_uring/tw.c
+++ b/io_uring/tw.c
@@ -153,6 +153,9 @@ void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
struct io_ring_ctx *ctx = req->ctx;
int nr_wait;
+ /* pairs with synchronize_rcu() in io_ring_exit_work() */
+ guard(rcu)();
+
/*
* We don't know how many requests there are in the link and whether
* they can even be queued lazily, fall back to non-lazy.
--
2.43.0
next reply other threads:[~2026-07-09 3:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 3:51 Woraphat Khiaodaeng [this message]
2026-07-09 17:44 ` [PATCH] io_uring: restore RCU read section in io_req_local_work_add() Jens Axboe
2026-07-09 17:46 ` 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=20260709035100.2269-1-worapat.kd2@gmail.com \
--to=worapat.kd2@gmail.com \
--cc=axboe@kernel.dev \
--cc=io-uring@vger.kernel.org \
/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