* [PATCH 5.14] io_uring: fix ctx-exit io_rsrc_put_work() deadlock
@ 2021-08-10 1:44 Pavel Begunkov
2021-08-10 2:01 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2021-08-10 1:44 UTC (permalink / raw)
To: Jens Axboe, io-uring; +Cc: asml.silence
__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: b60c8dce33895 ("io_uring: preparation for rsrc tagging")
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 331b866b39cf..d59e34e58b14 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8645,13 +8645,10 @@ static void io_req_caches_free(struct io_ring_ctx *ctx)
mutex_unlock(&ctx->uring_lock);
}
-static bool io_wait_rsrc_data(struct io_rsrc_data *data)
+static void io_wait_rsrc_data(struct io_rsrc_data *data)
{
- if (!data)
- return false;
- if (!atomic_dec_and_test(&data->refs))
+ if (data && !atomic_dec_and_test(&data->refs))
wait_for_completion(&data->done);
- return true;
}
static void io_ring_ctx_free(struct io_ring_ctx *ctx)
@@ -8663,10 +8660,14 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
ctx->mm_account = NULL;
}
+ /* __io_rsrc_put_work() may need uring_lock to progress, wait w/o it */
+ io_wait_rsrc_data(ctx->buf_data);
+ io_wait_rsrc_data(ctx->file_data);
+
mutex_lock(&ctx->uring_lock);
- if (io_wait_rsrc_data(ctx->buf_data))
+ if (ctx->buf_data)
__io_sqe_buffers_unregister(ctx);
- if (io_wait_rsrc_data(ctx->file_data))
+ if (ctx->file_data)
__io_sqe_files_unregister(ctx);
if (ctx->rings)
__io_cqring_overflow_flush(ctx, true);
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 5.14] io_uring: fix ctx-exit io_rsrc_put_work() deadlock
2021-08-10 1:44 [PATCH 5.14] io_uring: fix ctx-exit io_rsrc_put_work() deadlock Pavel Begunkov
@ 2021-08-10 2:01 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-08-10 2:01 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 8/9/21 7:44 PM, Pavel Begunkov wrote:
> __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.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-08-10 2:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-10 1:44 [PATCH 5.14] io_uring: fix ctx-exit io_rsrc_put_work() deadlock Pavel Begunkov
2021-08-10 2:01 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox