io_uring/kbuf: defer release of mapped buffer rings
authorJens Axboe <axboe@kernel.dk>
Mon, 27 Nov 2023 23:47:04 +0000 (16:47 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Dec 2023 07:52:20 +0000 (08:52 +0100)
commit7138ebbe65caf65f52b923d4ef819c77d04ea671
tree424098a831f170c4ad9777c2ad05c87c1b8b1eee
parent4ca5f54af7d3b60613991b201223c2dc6ebdf1c8
io_uring/kbuf: defer release of mapped buffer rings

commit c392cbecd8eca4c53f2bf508731257d9d0a21c2d upstream.

If a provided buffer ring is setup with IOU_PBUF_RING_MMAP, then the
kernel allocates the memory for it and the application is expected to
mmap(2) this memory. However, io_uring uses remap_pfn_range() for this
operation, so we cannot rely on normal munmap/release on freeing them
for us.

Stash an io_buf_free entry away for each of these, if any, and provide
a helper to free them post ->release().

Cc: stable@vger.kernel.org
Fixes: c56e022c0a27 ("io_uring: add support for user mapped provided buffer ring")
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/io_uring_types.h
io_uring/io_uring.c
io_uring/kbuf.c
io_uring/kbuf.h