diff mbox series

Revert "io_uring/rsrc: simplify the bvec iter count calculation"

Message ID 20250310184825.569371-1-kbusch@meta.com (mailing list archive)
State New
Headers show
Series Revert "io_uring/rsrc: simplify the bvec iter count calculation" | expand

Commit Message

Keith Busch March 10, 2025, 6:48 p.m. UTC
From: Keith Busch <kbusch@kernel.org>

This reverts commit 2a51c327d4a4a2eb62d67f4ea13a17efd0f25c5c.

The kernel registered bvecs do use the iov_iter_advance() API, so we
can't rely on this simplification anymore.

Fixes: 27cb27b6d5ea40 ("io_uring: add support for kernel registered bvecs")
Reported-by: Caleb Sander Mateos <csander@purestorage.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 io_uring/rsrc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Caleb Sander Mateos March 10, 2025, 6:50 p.m. UTC | #1
On Mon, Mar 10, 2025 at 11:48 AM Keith Busch <kbusch@meta.com> wrote:
>
> From: Keith Busch <kbusch@kernel.org>
>
> This reverts commit 2a51c327d4a4a2eb62d67f4ea13a17efd0f25c5c.
>
> The kernel registered bvecs do use the iov_iter_advance() API, so we
> can't rely on this simplification anymore.
>
> Fixes: 27cb27b6d5ea40 ("io_uring: add support for kernel registered bvecs")
> Reported-by: Caleb Sander Mateos <csander@purestorage.com>

Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>

> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
>  io_uring/rsrc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 5dd1e08275594..5fff6ba2b7c05 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -1024,7 +1024,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
>          * and advance us to the beginning.
>          */
>         offset = buf_addr - imu->ubuf;
> -       iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, len);
> +       iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, offset + len);
>
>         if (offset) {
>                 /*
> @@ -1051,6 +1051,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
>                  * to use the slow iter advance.
>                  */
>                 if (offset < bvec->bv_len) {
> +                       iter->count -= offset;
>                         iter->iov_offset = offset;
>                 } else if (imu->is_kbuf) {
>                         iov_iter_advance(iter, offset);
> @@ -1063,6 +1064,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
>
>                         iter->bvec += seg_skip;
>                         iter->nr_segs -= seg_skip;
> +                       iter->count -= bvec->bv_len + offset;
>                         iter->iov_offset = offset & ((1UL << imu->folio_shift) - 1);
>                 }
>         }
> --
> 2.47.1
>
Jens Axboe March 10, 2025, 7:37 p.m. UTC | #2
On Mon, 10 Mar 2025 11:48:25 -0700, Keith Busch wrote:
> This reverts commit 2a51c327d4a4a2eb62d67f4ea13a17efd0f25c5c.
> 
> The kernel registered bvecs do use the iov_iter_advance() API, so we
> can't rely on this simplification anymore.
> 
> 

Applied, thanks!

[1/1] Revert "io_uring/rsrc: simplify the bvec iter count calculation"
      commit: c93edef0374b203a7109e876ecd396446cb6e1d3

Best regards,
diff mbox series

Patch

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 5dd1e08275594..5fff6ba2b7c05 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1024,7 +1024,7 @@  static int io_import_fixed(int ddir, struct iov_iter *iter,
 	 * and advance us to the beginning.
 	 */
 	offset = buf_addr - imu->ubuf;
-	iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, len);
+	iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, offset + len);
 
 	if (offset) {
 		/*
@@ -1051,6 +1051,7 @@  static int io_import_fixed(int ddir, struct iov_iter *iter,
 		 * to use the slow iter advance.
 		 */
 		if (offset < bvec->bv_len) {
+			iter->count -= offset;
 			iter->iov_offset = offset;
 		} else if (imu->is_kbuf) {
 			iov_iter_advance(iter, offset);
@@ -1063,6 +1064,7 @@  static int io_import_fixed(int ddir, struct iov_iter *iter,
 
 			iter->bvec += seg_skip;
 			iter->nr_segs -= seg_skip;
+			iter->count -= bvec->bv_len + offset;
 			iter->iov_offset = offset & ((1UL << imu->folio_shift) - 1);
 		}
 	}