public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: remove poll entry from list when canceling all
@ 2022-03-22  1:14 Jens Axboe
  0 siblings, 0 replies; only message in thread
From: Jens Axboe @ 2022-03-22  1:14 UTC (permalink / raw)
  To: io-uring; +Cc: Dylan Yudaken

When the ring is exiting, as part of the shutdown, poll requests are
removed. But io_poll_remove_all() does not remove entries when finding
them, and since completions are done out-of-band, we can find and remove
the same entry multiple times.

We do guard the poll execution by poll ownership, but that does not
exclude us from reissuing a new one once the previous removal ownership
goes away.

This can race with poll execution as well, where we then end up seeing
req->apoll be NULL because a previous task_work requeue finished the
request.

Remove the poll entry when we find it and get ownership of it. This
prevents multiple invocations from finding it.

Fixes: aa43477b0402 ("io_uring: poll rework")
Reported-by: Dylan Yudaken <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>

---

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 48f4540d7dd5..53bd71363a44 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6275,6 +6275,7 @@ static __cold bool io_poll_remove_all(struct io_ring_ctx *ctx,
 		list = &ctx->cancel_hash[i];
 		hlist_for_each_entry_safe(req, tmp, list, hash_node) {
 			if (io_match_task_safe(req, tsk, cancel_all)) {
+				hlist_del_init(&req->hash_node);
 				io_poll_cancel_req(req);
 				found = true;
 			}

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-22  1:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-22  1:14 [PATCH] io_uring: remove poll entry from list when canceling all Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox