* [PATCH] io_uring/rsrc: ensure segments counts are correct on kbuf buffers
@ 2025-04-17 12:29 Jens Axboe
[not found] ` <CGME20250417140224epcas5p1f881e8a204df88d33365f3e8acba6a89@epcas5p1.samsung.com>
0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2025-04-17 12:29 UTC (permalink / raw)
To: io-uring; +Cc: Pavel Begunkov, Nitesh Shetty
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 <axboe@kernel.dk>
---
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
--
Jens Axboe
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring/rsrc: ensure segments counts are correct on kbuf buffers
[not found] ` <CGME20250417140224epcas5p1f881e8a204df88d33365f3e8acba6a89@epcas5p1.samsung.com>
@ 2025-04-17 13:53 ` Nitesh Shetty
0 siblings, 0 replies; 2+ messages in thread
From: Nitesh Shetty @ 2025-04-17 13:53 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring, Pavel Begunkov
[-- Attachment #1: Type: text/plain, Size: 1814 bytes --]
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 <axboe@kernel.dk>
>
>---
>
>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 <nj.shetty@samsung.com>
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-17 15:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 12:29 [PATCH] io_uring/rsrc: ensure segments counts are correct on kbuf buffers Jens Axboe
[not found] ` <CGME20250417140224epcas5p1f881e8a204df88d33365f3e8acba6a89@epcas5p1.samsung.com>
2025-04-17 13:53 ` Nitesh Shetty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox