public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: ensure that cached task references are always put on exit
@ 2022-09-24  0:52 Jens Axboe
  0 siblings, 0 replies; only message in thread
From: Jens Axboe @ 2022-09-24  0:52 UTC (permalink / raw)
  To: io-uring

io_uring caches task references to avoid doing atomics for each of them
per request. If a request is put from the same task that allocated it,
then we can maintain a per-ctx cache of them. This obviously relies
on io_uring always pruning caches in a reliable way, and there's
currently a case off io_uring fd release where we can miss that.

One example is a ring setup with IOPOLL, which relies on the task
polling for completions, which will free them. However, if such a task
submits a request and then exits or closes the ring without reaping
the completion, then ring release will reap and put. If release happens
from that very same task, the completed request task refs will get
put back into the cache pool. This is problematic, as we're now beyond
the point of pruning caches.

Manually drop these caches after doing an IOPOLL reap. This releases
references from the current task, which is enough. If another task
happens to be doing the release, then the caching will not be
triggered and there's no issue.

Cc: [email protected]
Fixes: e98e49b2bbf7 ("io_uring: extend task put optimisations")
Reported-by: Homin Rhee <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>

---

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index b9640ad5069f..2965b354efc8 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2648,6 +2648,9 @@ static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
 		io_kill_timeouts(ctx, NULL, true);
 		/* if we failed setting up the ctx, we might not have any rings */
 		io_iopoll_try_reap_events(ctx);
+		/* drop cached put refs after potentially doing completions */
+		if (current->io_uring)
+			io_uring_drop_tctx_refs(current);
 	}
 
 	INIT_WORK(&ctx->exit_work, io_ring_exit_work);

-- 
Jens Axboe

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

only message in thread, other threads:[~2022-09-24  0:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-24  0:52 [PATCH] io_uring: ensure that cached task references are always put on exit Jens Axboe

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