On Tue, May 14, 2024 at 1:25 PM Chenliang Li <cliang01.li@xxxxxxxxxxx> wrote: > > Store the folio shift and folio mask into imu struct and use it in > iov_iter adjust, as we will have non PAGE_SIZE'd chunks if a > multi-hugepage buffer get coalesced. > > Signed-off-by: Chenliang Li <cliang01.li@xxxxxxxxxxx> > --- > io_uring/rsrc.c | 6 ++++-- > io_uring/rsrc.h | 2 ++ > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c > index d08224c0c5b0..578d382ca9bc 100644 > --- a/io_uring/rsrc.c > +++ b/io_uring/rsrc.c > @@ -1015,6 +1015,8 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, > imu->ubuf = (unsigned long) iov->iov_base; > imu->ubuf_end = imu->ubuf + iov->iov_len; > imu->nr_bvecs = nr_pages; > + imu->folio_shift = PAGE_SHIFT; > + imu->folio_mask = PAGE_MASK; > *pimu = imu; > ret = 0; > > @@ -1153,12 +1155,12 @@ int io_import_fixed(int ddir, struct iov_iter *iter, > > /* skip first vec */ > offset -= bvec->bv_len; > - seg_skip = 1 + (offset >> PAGE_SHIFT); > + seg_skip = 1 + (offset >> imu->folio_shift); > > iter->bvec = bvec + seg_skip; > iter->nr_segs -= seg_skip; > iter->count -= bvec->bv_len + offset; > - iter->iov_offset = offset & ~PAGE_MASK; > + iter->iov_offset = offset & ~imu->folio_mask; > } > } > > diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h > index b2a9d66b76dd..93da02e652bc 100644 > --- a/io_uring/rsrc.h > +++ b/io_uring/rsrc.h > @@ -46,7 +46,9 @@ struct io_mapped_ubuf { > u64 ubuf; > u64 ubuf_end; > unsigned int nr_bvecs; > + unsigned int folio_shift; > unsigned long acct_pages; > + unsigned long folio_mask; > struct bio_vec bvec[] __counted_by(nr_bvecs); > }; > > -- > 2.34.1 > > Looks good. Reviewed-by: Anuj Gupta <anuj20.g@xxxxxxxxxxx> -- Anuj Gupta