* [PATCH] io_uring: fix io_prep_async_link locking
@ 2021-07-26 13:14 Pavel Begunkov
2021-07-28 19:49 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2021-07-26 13:14 UTC (permalink / raw)
To: Jens Axboe, io-uring; +Cc: asml.silence
io_prep_async_link() may be called after arming a linked timeout,
automatically making it unsafe to traverse the linked list. Guard
with completion_lock if there was a linked timeout.
Cc: [email protected] # 5.9+
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 7d995d97beeb..6c2cc374a2a5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1279,8 +1279,17 @@ static void io_prep_async_link(struct io_kiocb *req)
{
struct io_kiocb *cur;
- io_for_each_link(cur, req)
- io_prep_async_work(cur);
+ if (req->flags & REQ_F_LINK_TIMEOUT) {
+ struct io_ring_ctx *ctx = req->ctx;
+
+ spin_lock_irq(&ctx->completion_lock);
+ io_for_each_link(cur, req)
+ io_prep_async_work(cur);
+ spin_unlock_irq(&ctx->completion_lock);
+ } else {
+ io_for_each_link(cur, req)
+ io_prep_async_work(cur);
+ }
}
static void io_queue_async_work(struct io_kiocb *req)
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring: fix io_prep_async_link locking
2021-07-26 13:14 [PATCH] io_uring: fix io_prep_async_link locking Pavel Begunkov
@ 2021-07-28 19:49 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-07-28 19:49 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 7/26/21 7:14 AM, Pavel Begunkov wrote:
> io_prep_async_link() may be called after arming a linked timeout,
> automatically making it unsafe to traverse the linked list. Guard
> with completion_lock if there was a linked timeout.
Don't seem to have emailed this out, but I did apply this the other
day. Thanks!
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-28 19:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-26 13:14 [PATCH] io_uring: fix io_prep_async_link locking Pavel Begunkov
2021-07-28 19:49 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox