Skip to content

Commit e775f93

Browse files
committed
io_uring: ensure that cached task references are always put on exit
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: stable@vger.kernel.org Fixes: e98e49b ("io_uring: extend task put optimisations") Reported-by: Homin Rhee <hominlab@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 9bd3f72 commit e775f93

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

io_uring/io_uring.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,9 @@ static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
26482648
io_kill_timeouts(ctx, NULL, true);
26492649
/* if we failed setting up the ctx, we might not have any rings */
26502650
io_iopoll_try_reap_events(ctx);
2651+
/* drop cached put refs after potentially doing completions */
2652+
if (current->io_uring)
2653+
io_uring_drop_tctx_refs(current);
26512654
}
26522655

26532656
INIT_WORK(&ctx->exit_work, io_ring_exit_work);

0 commit comments

Comments
 (0)