From: Nitesh Shetty <nj.shetty@samsung.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring <io-uring@vger.kernel.org>,
Pavel Begunkov <asml.silence@gmail.com>
Subject: Re: [PATCH] io_uring/rsrc: ensure segments counts are correct on kbuf buffers
Date: Thu, 17 Apr 2025 19:23:57 +0530 [thread overview]
Message-ID: <20250417135357.aiobpzii6mviujyu@ubuntu> (raw)
In-Reply-To: <9c129aed-6e07-4f23-934b-951d3585cd5a@kernel.dk>
[-- 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 --]
prev parent reply other threads:[~2025-04-17 15:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250417135357.aiobpzii6mviujyu@ubuntu \
--to=nj.shetty@samsung.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox