io_uring/memmap: flag regions with user pages

In preparation to kernel allocated regions add a flag telling if
the region contains user pinned pages or not.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/0dc91564642654405bab080b7ec911cb4a43ec6e.1732886067.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Pavel Begunkov 2024-11-29 13:34:25 +00:00 committed by Jens Axboe
parent 36cdb4f782
commit 2d38132989

View File

@ -205,12 +205,17 @@ void *__io_uaddr_map(struct page ***pages, unsigned short *npages,
enum { enum {
/* memory was vmap'ed for the kernel, freeing the region vunmap's it */ /* memory was vmap'ed for the kernel, freeing the region vunmap's it */
IO_REGION_F_VMAP = 1, IO_REGION_F_VMAP = 1,
/* memory is provided by user and pinned by the kernel */
IO_REGION_F_USER_PROVIDED = 2,
}; };
void io_free_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr) void io_free_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr)
{ {
if (mr->pages) { if (mr->pages) {
unpin_user_pages(mr->pages, mr->nr_pages); if (mr->flags & IO_REGION_F_USER_PROVIDED)
unpin_user_pages(mr->pages, mr->nr_pages);
else
release_pages(mr->pages, mr->nr_pages);
kvfree(mr->pages); kvfree(mr->pages);
} }
if ((mr->flags & IO_REGION_F_VMAP) && mr->ptr) if ((mr->flags & IO_REGION_F_VMAP) && mr->ptr)
@ -267,7 +272,7 @@ int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr,
mr->pages = pages; mr->pages = pages;
mr->ptr = vptr; mr->ptr = vptr;
mr->nr_pages = nr_pages; mr->nr_pages = nr_pages;
mr->flags |= IO_REGION_F_VMAP; mr->flags |= IO_REGION_F_VMAP | IO_REGION_F_USER_PROVIDED;
return 0; return 0;
out_free: out_free:
if (pages_accounted) if (pages_accounted)