public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: io-uring@vger.kernel.org,
	Caleb Sander Mateos <csander@purestorage.com>,
	huang-jl <huang-jl@deepseek.com>,
	Nitesh Shetty <nj.shetty@samsung.com>,
	Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 2/3] block: don't initialize bi_vcnt for cloned bio in bio_iov_bvec_set()
Date: Thu, 18 Dec 2025 17:31:43 +0800	[thread overview]
Message-ID: <20251218093146.1218279-3-ming.lei@redhat.com> (raw)
In-Reply-To: <20251218093146.1218279-1-ming.lei@redhat.com>

For a cloned bio, bi_vcnt should not be initialized since the bio_vec
array is shared and owned by the original bio. Instead, initialize
bi_iter.bi_idx to 0 to properly start iteration from the beginning
of the shared bio_vec array.

This also avoids to touch iov_iter.nr_segs, which belongs to iov_iter
implementation detail.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index e726c0e280a8..79d1fef8ad0f 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1162,8 +1162,8 @@ void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter)
 {
 	WARN_ON_ONCE(bio->bi_max_vecs);
 
-	bio->bi_vcnt = iter->nr_segs;
 	bio->bi_io_vec = (struct bio_vec *)iter->bvec;
+	bio->bi_iter.bi_idx = 0;
 	bio->bi_iter.bi_bvec_done = iter->iov_offset;
 	bio->bi_iter.bi_size = iov_iter_count(iter);
 	bio_set_flag(bio, BIO_CLONED);
-- 
2.47.0


  parent reply	other threads:[~2025-12-18  9:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18  9:31 [PATCH 0/3] block: fix bi_vcnt misuse for cloned bio Ming Lei
2025-12-18  9:31 ` [PATCH 1/3] block: fix bio_may_need_split() by using bvec iterator way Ming Lei
2025-12-18  9:37   ` Christoph Hellwig
2025-12-18  9:45     ` Ming Lei
2025-12-18 15:16       ` Nitesh Shetty
2025-12-18 16:08         ` Ming Lei
2025-12-20  8:16           ` Nitesh Shetty
2025-12-20  8:19   ` Nitesh Shetty
2025-12-18  9:31 ` Ming Lei [this message]
2025-12-18  9:38   ` [PATCH 2/3] block: don't initialize bi_vcnt for cloned bio in bio_iov_bvec_set() Christoph Hellwig
2025-12-18  9:48     ` Ming Lei
2025-12-18  9:31 ` [PATCH 3/3] io_uring: don't re-calculate iov_iter nr_segs in io_import_kbuf() Ming Lei

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=20251218093146.1218279-3-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=huang-jl@deepseek.com \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=nj.shetty@samsung.com \
    /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