]> git.itanic.dy.fi Git - linux-stable/commit
io_uring: ensure that cached task references are always put on exit
authorJens Axboe <axboe@kernel.dk>
Fri, 23 Sep 2022 19:44:56 +0000 (13:44 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 24 Sep 2022 00:51:08 +0000 (18:51 -0600)
commite775f93f2ab976a2cdb4a7b53063cbe890904f73
tree97e967e5e4f926f464c06c8e01ff9520d5c131c5
parent9bd3f728223ebcfef8e9d087bdd142f0e388215d
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: e98e49b2bbf7 ("io_uring: extend task put optimisations")
Reported-by: Homin Rhee <hominlab@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io_uring.c