Skip to content

Commit bd99c71

Browse files
Hao Xuaxboe
authored andcommitted
io_uring: fix race between poll completion and cancel_hash insertion
If poll arming and poll completion runs in parallel, there maybe races. For instance, run io_poll_add in iowq and io_poll_task_func in original context, then: iowq original context io_poll_add vfs_poll (interruption happens tw queued to original context) io_poll_task_func generate cqe del from cancel_hash[] if !poll.done insert to cancel_hash[] The entry left in cancel_hash[], similar case for fast poll. Fix it by set poll.done = true when del from cancel_hash[]. Fixes: 5082620 ("io_uring: terminate multishot poll for CQ ring overflow") Signed-off-by: Hao Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 87c1696 commit bd99c71

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/io_uring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,10 +5337,8 @@ static bool __io_poll_complete(struct io_kiocb *req, __poll_t mask)
53375337
}
53385338
if (req->poll.events & EPOLLONESHOT)
53395339
flags = 0;
5340-
if (!io_cqring_fill_event(ctx, req->user_data, error, flags)) {
5341-
req->poll.done = true;
5340+
if (!io_cqring_fill_event(ctx, req->user_data, error, flags))
53425341
flags = 0;
5343-
}
53445342
if (flags & IORING_CQE_F_MORE)
53455343
ctx->cq_extra++;
53465344

@@ -5371,6 +5369,7 @@ static void io_poll_task_func(struct io_kiocb *req, bool *locked)
53715369
if (done) {
53725370
io_poll_remove_double(req);
53735371
hash_del(&req->hash_node);
5372+
req->poll.done = true;
53745373
} else {
53755374
req->result = 0;
53765375
add_wait_queue(req->poll.head, &req->poll.wait);
@@ -5508,6 +5507,7 @@ static void io_async_task_func(struct io_kiocb *req, bool *locked)
55085507

55095508
hash_del(&req->hash_node);
55105509
io_poll_remove_double(req);
5510+
apoll->poll.done = true;
55115511
spin_unlock(&ctx->completion_lock);
55125512

55135513
if (!READ_ONCE(apoll->poll.canceled))

0 commit comments

Comments
 (0)