io_uring: account user memory freed when exit has been queued
authorJens Axboe <axboe@kernel.dk>
Fri, 10 Jul 2020 15:13:34 +0000 (09:13 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 Jul 2020 06:13:29 +0000 (08:13 +0200)
commit55460694b74bf8cd654007879982f8b1fee49ad3
treef22872b82fb023f0420f0521c871226e7b4c60a0
parent2e77ec769daf9d7428bdfef94f11bf2350e12fc7
io_uring: account user memory freed when exit has been queued

commit 309fc03a3284af62eb6082fb60327045a1dabf57 upstream.

We currently account the memory after the exit work has been run, but
that leaves a gap where a process has closed its ring and until the
memory has been accounted as freed. If the memlocked ulimit is
borderline, then that can introduce spurious setup errors returning
-ENOMEM because the free work hasn't been run yet.

Account this as freed when we close the ring, as not to expose a tiny
gap where setting up a new ring can fail.

Fixes: 85faa7b8346e ("io_uring: punt final io_ring_ctx wait-and-free to workqueue")
Cc: stable@vger.kernel.org # v5.7
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/io_uring.c