[PATCH 04/10] block: avoid unpinning/freeing the bio_vec incase of cloned bio

Kanchan Joshi
2024-04-25T18:47:03Z

From: Anuj Gupta <anuj20.g@samsung.com>

Do it only once when the parent bio completes.

Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
block/bio-integrity.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index b4042414a08f..b698eb77515d 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -119,7 +119,8 @@ static void bio_integrity_uncopy_user(struct bio_integrity_payload *bip)
ret = copy_to_iter(bvec_virt(&src_bvec), bytes, &iter);
WARN_ON_ONCE(ret != bytes);

- bio_integrity_unpin_bvec(copy, nr_vecs, true);
+ if (!bio_flagged((bip->bip_bio), BIO_CLONED))
+ bio_integrity_unpin_bvec(copy, nr_vecs, true);
}

static void bio_integrity_unmap_user(struct bio_integrity_payload *bip)
@@ -129,11 +130,14 @@ static void bio_integrity_unmap_user(struct bio_integrity_payload *bip)
if (bip->bip_flags & BIP_COPY_USER) {
if (dirty)
bio_integrity_uncopy_user(bip);
- kfree(bvec_virt(bip->bip_vec));
+ if (!bio_flagged((bip->bip_bio), BIO_CLONED))
+ kfree(bvec_virt(bip->bip_vec));
return;
}

- bio_integrity_unpin_bvec(bip->bip_vec, bip->bip_max_vcnt, dirty);
+ if (!bio_flagged((bip->bip_bio), BIO_CLONED))
+ bio_integrity_unpin_bvec(bip->bip_vec, bip->bip_max_vcnt,
+ dirty);
}

/**
--
2.25.1