io_uring/kbuf: use vm_insert_pages() for mmap'ed pbuf ring
authorJens Axboe <axboe@kernel.dk>
Wed, 13 Mar 2024 02:24:21 +0000 (20:24 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 29 Mar 2024 15:40:35 +0000 (09:40 -0600)
commite5c3ad99f808baf1edea8f4b05af7bb856854768
tree4ab23d3d69b1b4e159809d8cc43881a5492b02a3
parent51cdc570979398765feb63cb9f63fdaa95dd8dc7
io_uring/kbuf: use vm_insert_pages() for mmap'ed pbuf ring

Rather than use remap_pfn_range() for this and manually free later,
switch to using vm_insert_page() and have it Just Work.

This requires a bit of effort on the mmap lookup side, as the ctx
uring_lock isn't held, which  otherwise protects buffer_lists from being
torn down, and it's not safe to grab from mmap context that would
introduce an ABBA deadlock between the mmap lock and the ctx uring_lock.
Instead, lookup the buffer_list under RCU, as the the list is RCU freed
already. Use the existing reference count to determine whether it's
possible to safely grab a reference to it (eg if it's not zero already),
and drop that reference when done with the mapping. If the mmap
reference is the last one, the buffer_list and the associated memory can
go away, since the vma insertion has references to the inserted pages at
that point.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/io_uring_types.h
io_uring/io_uring.c
io_uring/io_uring.h
io_uring/kbuf.c
io_uring/kbuf.h