* [PATCH 1/1] io_uring: fix corner case forgetting to vunmap
@ 2024-11-25 23:10 Pavel Begunkov
2024-11-27 22:05 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2024-11-25 23:10 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
io_pages_unmap() is a bit tricky in trying to figure whether the pages
were previously vmap'ed or not. In particular If there is juts one page
it belives there is no need to vunmap. Paired io_pages_map(), however,
could've failed io_mem_alloc_compound() and attempted to
io_mem_alloc_single(), which does vmap, and that leads to unpaired vmap.
The solution is to fail if io_mem_alloc_compound() can't allocate a
single page. That's the easiest way to deal with it, and those two
functions are getting removed soon, so no need to overcomplicate it.
Cc: [email protected]
Fixes: 3ab1db3c6039e ("io_uring: get rid of remap_pfn_range() for mapping rings/sqes")
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/memmap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 3d71756bc598..2b6be273e893 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -73,6 +73,8 @@ void *io_pages_map(struct page ***out_pages, unsigned short *npages,
ret = io_mem_alloc_compound(pages, nr_pages, size, gfp);
if (!IS_ERR(ret))
goto done;
+ if (nr_pages == 1)
+ goto fail;
ret = io_mem_alloc_single(pages, nr_pages, size, gfp);
if (!IS_ERR(ret)) {
@@ -81,7 +83,7 @@ void *io_pages_map(struct page ***out_pages, unsigned short *npages,
*npages = nr_pages;
return ret;
}
-
+fail:
kvfree(pages);
*out_pages = NULL;
*npages = 0;
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] io_uring: fix corner case forgetting to vunmap
2024-11-25 23:10 [PATCH 1/1] io_uring: fix corner case forgetting to vunmap Pavel Begunkov
@ 2024-11-27 22:05 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2024-11-27 22:05 UTC (permalink / raw)
To: io-uring, Pavel Begunkov
On Mon, 25 Nov 2024 23:10:31 +0000, Pavel Begunkov wrote:
> io_pages_unmap() is a bit tricky in trying to figure whether the pages
> were previously vmap'ed or not. In particular If there is juts one page
> it belives there is no need to vunmap. Paired io_pages_map(), however,
> could've failed io_mem_alloc_compound() and attempted to
> io_mem_alloc_single(), which does vmap, and that leads to unpaired vmap.
>
> The solution is to fail if io_mem_alloc_compound() can't allocate a
> single page. That's the easiest way to deal with it, and those two
> functions are getting removed soon, so no need to overcomplicate it.
>
> [...]
Applied, thanks!
[1/1] io_uring: fix corner case forgetting to vunmap
commit: 43eef70e7e2ac74e7767731dd806720c7fb5e010
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-27 22:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-25 23:10 [PATCH 1/1] io_uring: fix corner case forgetting to vunmap Pavel Begunkov
2024-11-27 22:05 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox