On 17/04/25 06:29AM, Jens Axboe wrote: >kbuf imports have the front offset adjusted and segments removed, but >the tail segments are still included in the segment count that gets >passed in the iov_iter. As the segments aren't necessarily all the >same size, move importing to a separate helper and iterate the >mapped length to get an exact count. > >Signed-off-by: Jens Axboe > >--- > >Same as the one I sent out yesterday, but just for the kbuf part. > >diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c >index 4099b8225670..04e19689d2f3 100644 >--- a/io_uring/rsrc.c >+++ b/io_uring/rsrc.c >@@ -1032,6 +1032,26 @@ static int validate_fixed_range(u64 buf_addr, size_t len, > return 0; > } > >+static int io_import_kbuf(int ddir, struct iov_iter *iter, >+ struct io_mapped_ubuf *imu, size_t len, size_t offset) >+{ >+ size_t count = len + offset; >+ >+ iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, count); >+ iov_iter_advance(iter, offset); >+ >+ if (count < imu->len) { >+ const struct bio_vec *bvec = iter->bvec; >+ >+ while (len > bvec->bv_len) { >+ len -= bvec->bv_len; >+ bvec++; >+ } >+ iter->nr_segs = 1 + bvec - iter->bvec; >+ } >+ return 0; >+} >+ > static int io_import_fixed(int ddir, struct iov_iter *iter, > struct io_mapped_ubuf *imu, > u64 buf_addr, size_t len) >@@ -1052,11 +1072,8 @@ static int io_import_fixed(int ddir, struct iov_iter *iter, > > offset = buf_addr - imu->ubuf; > >- if (imu->is_kbuf) { >- iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, offset + len); >- iov_iter_advance(iter, offset); >- return 0; >- } >+ if (imu->is_kbuf) >+ return io_import_kbuf(ddir, iter, imu, len, offset); > > /* > * Don't use iov_iter_advance() here, as it's really slow for > Looks good. Reviewed-by: Nitesh Shetty