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 --- 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