Skip to content

Commit 43597aa

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix ctx-exit io_rsrc_put_work() deadlock
__io_rsrc_put_work() might need ->uring_lock, so nobody should wait for rsrc nodes holding the mutex. However, that's exactly what io_ring_ctx_free() does with io_wait_rsrc_data(). Split it into rsrc wait + dealloc, and move the first one out of the lock. Cc: [email protected] Fixes: b60c8dc ("io_uring: preparation for rsrc tagging") Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/0130c5c2693468173ec1afab714e0885d2c9c363.1628559783.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent c018db4 commit 43597aa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/io_uring.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8652,13 +8652,10 @@ static void io_req_caches_free(struct io_ring_ctx *ctx)
86528652
mutex_unlock(&ctx->uring_lock);
86538653
}
86548654

8655-
static bool io_wait_rsrc_data(struct io_rsrc_data *data)
8655+
static void io_wait_rsrc_data(struct io_rsrc_data *data)
86568656
{
8657-
if (!data)
8658-
return false;
8659-
if (!atomic_dec_and_test(&data->refs))
8657+
if (data && !atomic_dec_and_test(&data->refs))
86608658
wait_for_completion(&data->done);
8661-
return true;
86628659
}
86638660

86648661
static void io_ring_ctx_free(struct io_ring_ctx *ctx)
@@ -8670,10 +8667,14 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
86708667
ctx->mm_account = NULL;
86718668
}
86728669

8670+
/* __io_rsrc_put_work() may need uring_lock to progress, wait w/o it */
8671+
io_wait_rsrc_data(ctx->buf_data);
8672+
io_wait_rsrc_data(ctx->file_data);
8673+
86738674
mutex_lock(&ctx->uring_lock);
8674-
if (io_wait_rsrc_data(ctx->buf_data))
8675+
if (ctx->buf_data)
86758676
__io_sqe_buffers_unregister(ctx);
8676-
if (io_wait_rsrc_data(ctx->file_data))
8677+
if (ctx->file_data)
86778678
__io_sqe_files_unregister(ctx);
86788679
if (ctx->rings)
86798680
__io_cqring_overflow_flush(ctx, true);

0 commit comments

Comments
 (0)