Skip to content

Commit 737adda

Browse files
axboegregkh
authored andcommitted
io_uring/tw: serialize ctx->retry_llist with ->uring_lock
Commit 17666e2 upstream. The DEFER_TASKRUN local task work paths all run under ctx->uring_lock, which serializes them with each other and with the rest of the ring's hot paths. io_move_task_work_from_local() is the exception - it's called from io_ring_exit_work() on a kworker without holding the lock and from the iopoll cancelation side right after dropping it. ->work_llist is fine with this, as it's only ever updated via the expected paths. But the ->retry_llist is updated while runing, and hence it could potentially race between normal task_work running and the task-has-exited shutdown path. Simply grab ->uring_lock while moving the local work to the fallback list for exit purposes, which nicely serializes it across both the normal additions and the exit prune path. Cc: stable@vger.kernel.org Fixes: f46b9cd ("io_uring: limit local tw done") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2563d78 commit 737adda

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

io_uring/io_uring.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,18 @@ void io_req_task_work_add_remote(struct io_kiocb *req, unsigned flags)
13701370

13711371
static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx)
13721372
{
1373-
struct llist_node *node = llist_del_all(&ctx->work_llist);
1373+
struct llist_node *node;
13741374

1375+
/*
1376+
* Running the work items may utilize ->retry_llist as a means
1377+
* for capping the number of task_work entries run at the same
1378+
* time. But that list can potentially race with moving the work
1379+
* from here, if the task is exiting. As any normal task_work
1380+
* running holds ->uring_lock already, just guard this slow path
1381+
* with ->uring_lock to avoid racing on ->retry_llist.
1382+
*/
1383+
guard(mutex)(&ctx->uring_lock);
1384+
node = llist_del_all(&ctx->work_llist);
13751385
__io_fallback_tw(node, false);
13761386
node = llist_del_all(&ctx->retry_llist);
13771387
__io_fallback_tw(node, false);

0 commit comments

Comments
 (0)