Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: move local task_work in exit cancel loop

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
Fixes: c0e0d6ba25f1 ("io_uring: add IORING_SETUP_DEFER_TASKRUN")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ming Lei and committed by
Jens Axboe
da579f05 e4fdbca2

+4 -4
+4 -4
io_uring/io_uring.c
··· 3003 3003 mutex_unlock(&ctx->uring_lock); 3004 3004 } 3005 3005 3006 - if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) 3007 - io_move_task_work_from_local(ctx); 3008 - 3009 3006 /* The SQPOLL thread never reaches this path */ 3010 - while (io_uring_try_cancel_requests(ctx, NULL, true, false)) 3007 + do { 3008 + if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) 3009 + io_move_task_work_from_local(ctx); 3011 3010 cond_resched(); 3011 + } while (io_uring_try_cancel_requests(ctx, NULL, true, false)); 3012 3012 3013 3013 if (ctx->sq_data) { 3014 3014 struct io_sq_data *sqd = ctx->sq_data;