Skip to content

Commit 3a3c6d6

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: don't rely on user vaddr alignment
There is no guaranteed alignment for user pointers, however the calculation of an offset of the first page into a folio after coalescing uses some weird bit mask logic, get rid of it. Cc: [email protected] Reported-by: David Hildenbrand <[email protected]> Fixes: a8edbb4 ("io_uring/rsrc: enable multi-hugepage buffer coalescing") Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/io-uring/e387b4c78b33f231105a601d84eefd8301f57954.1750771718.git.asml.silence@gmail.com/ Signed-off-by: Jens Axboe <[email protected]>
1 parent 5afb4bf commit 3a3c6d6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

io_uring/rsrc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ bool io_check_coalesce_buffer(struct page **page_array, int nr_pages,
734734

735735
data->nr_pages_mid = folio_nr_pages(folio);
736736
data->folio_shift = folio_shift(folio);
737+
data->first_folio_page_idx = folio_page_idx(folio, page_array[0]);
737738

738739
/*
739740
* Check if pages are contiguous inside a folio, and all folios have
@@ -827,7 +828,11 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
827828
if (coalesced)
828829
imu->folio_shift = data.folio_shift;
829830
refcount_set(&imu->refs, 1);
830-
off = (unsigned long) iov->iov_base & ((1UL << imu->folio_shift) - 1);
831+
832+
off = (unsigned long)iov->iov_base & ~PAGE_MASK;
833+
if (coalesced)
834+
off += data.first_folio_page_idx << PAGE_SHIFT;
835+
831836
node->buf = imu;
832837
ret = 0;
833838

io_uring/rsrc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct io_imu_folio_data {
4949
unsigned int nr_pages_mid;
5050
unsigned int folio_shift;
5151
unsigned int nr_folios;
52+
unsigned long first_folio_page_idx;
5253
};
5354

5455
bool io_rsrc_cache_init(struct io_ring_ctx *ctx);

0 commit comments

Comments
 (0)