* [PATCH] io_uring: move local task_work in exit cancel loop
@ 2026-01-14 8:54 Ming Lei
2026-01-14 17:18 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2026-01-14 8:54 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring, Caleb Sander Mateos, Ming Lei, stable
With IORING_SETUP_DEFER_TASKRUN, task work is queued to ctx->work_llist
(local work) rather than the fallback list. During io_ring_exit_work(),
io_move_task_work_from_local() was called once before the cancel loop,
moving work from work_llist to fallback_llist.
However, task work can be added to work_llist during the cancel loop
itself. There are two cases:
1) io_kill_timeouts() is called from io_uring_try_cancel_requests() to
cancel pending timeouts, and it adds task work via io_req_queue_tw_complete()
for each cancelled timeout:
2) URING_CMD requests like ublk can be completed via
io_uring_cmd_complete_in_task() from ublk_queue_rq() during canceling,
given ublk request queue is only quiesced when canceling the 1st uring_cmd.
Since io_allowed_defer_tw_run() returns false in io_ring_exit_work()
(kworker != submitter_task), io_run_local_work() is never invoked,
and the work_llist entries are never processed. This causes
io_uring_try_cancel_requests() to loop indefinitely, resulting in
100% CPU usage in kworker threads.
Fix this by moving io_move_task_work_from_local() inside the cancel
loop, ensuring any work on work_llist is moved to fallback before
each cancel attempt.
Cc: <stable@vger.kernel.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
io_uring/io_uring.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 87a87396e940..b7a077c11c21 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3003,12 +3003,12 @@ static __cold void io_ring_exit_work(struct work_struct *work)
mutex_unlock(&ctx->uring_lock);
}
- if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
- io_move_task_work_from_local(ctx);
-
/* The SQPOLL thread never reaches this path */
- while (io_uring_try_cancel_requests(ctx, NULL, true, false))
+ do {
+ if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
+ io_move_task_work_from_local(ctx);
cond_resched();
+ } while (io_uring_try_cancel_requests(ctx, NULL, true, false));
if (ctx->sq_data) {
struct io_sq_data *sqd = ctx->sq_data;
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring: move local task_work in exit cancel loop
2026-01-14 8:54 [PATCH] io_uring: move local task_work in exit cancel loop Ming Lei
@ 2026-01-14 17:18 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2026-01-14 17:18 UTC (permalink / raw)
To: Ming Lei; +Cc: io-uring, Caleb Sander Mateos, stable
On Wed, 14 Jan 2026 16:54:05 +0800, Ming Lei wrote:
> With IORING_SETUP_DEFER_TASKRUN, task work is queued to ctx->work_llist
> (local work) rather than the fallback list. During io_ring_exit_work(),
> io_move_task_work_from_local() was called once before the cancel loop,
> moving work from work_llist to fallback_llist.
>
> However, task work can be added to work_llist during the cancel loop
> itself. There are two cases:
>
> [...]
Applied, thanks!
[1/1] io_uring: move local task_work in exit cancel loop
commit: da579f05ef0faada3559e7faddf761c75cdf85e1
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-14 17:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 8:54 [PATCH] io_uring: move local task_work in exit cancel loop Ming Lei
2026-01-14 17:18 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox