Skip to contentSkip to conversation

block: fix regression where bio_integrity_process uses wrong bio_vec iterator

PATCH In review Darrick J. Wong 3 participants 3 messages Nov 26, 2014 – Dec 2, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 block: fix regression where bio_integrity_process uses wrong bio_vec iterator

bio integrity handling is broken on a system with LVM layered atop a DIF/DIX SCSI drive because device mapper clones the bio, modifies the clone, and sends the clone to the lower layers for processing. However, the clone bio has bi_vcnt == 0, which means that when the sd driver calls bio_integrity_process to attach DIX data, the for_each_segment_all() call (which uses bi_vcnt) returns immediately and random garbage is sent to the disk on a disk write. The disk of course returns an error.

Therefore, teach bio_integrity_process() to use bio_for_each_segment() to iterate the bio_vecs, since the per-bio iterator tracks which bio_vecs are associated with that particular bio. The integrity handling code is effectively part of the "driver" (it's not the bio owner), so it must use the correct iterator function.

v2: Fix a compiler warning about abandoned local variables. This patch supersedes "block: bio_integrity_process uses wrong bio_vec iterator". Patch applies against 3.18-rc6.

---
 block/bio-integrity.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
block/bio-integrity.c +7 -6
index 0984232..5cbd5d9 100644
@@ -216,9 +216,10 @@ static int bio_integrity_process(struct bio *bio,
 {
 	struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
 	struct blk_integrity_iter iter;
-	struct bio_vec *bv;
+	struct bvec_iter bviter;
+	struct bio_vec bv;
 	struct bio_integrity_payload *bip = bio_integrity(bio);
-	unsigned int i, ret = 0;
+	unsigned int ret = 0;
 	void *prot_buf = page_address(bip->bip_vec->bv_page) +
 		bip->bip_vec->bv_offset;
 
@@ -227,11 +228,11 @@ static int bio_integrity_process(struct bio *bio,
 	iter.seed = bip_get_seed(bip);
 	iter.prot_buf = prot_buf;
 
-	bio_for_each_segment_all(bv, bio, i) {
-		void *kaddr = kmap_atomic(bv->bv_page);
+	bio_for_each_segment(bv, bio, bviter) {
+		void *kaddr = kmap_atomic(bv.bv_page);
 
-		iter.data_buf = kaddr + bv->bv_offset;
-		iter.data_size = bv->bv_len;
+		iter.data_buf = kaddr + bv.bv_offset;
+		iter.data_size = bv.bv_len;
 
 		ret = proc_fn(&iter);
 		if (ret) {
Acked-by on v2 1/1
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Darrick" == Darrick J Wong <[email protected]> writes:

Darrick> Therefore, teach bio_integrity_process() to use Darrick> bio_for_each_segment() to iterate the bio_vecs, since the Darrick> per-bio iterator tracks which bio_vecs are associated with that Darrick> particular bio. The integrity handling code is effectively Darrick> part of the "driver" (it's not the bio owner), so it must use Darrick> the correct iterator function.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer
#2 lore raw
Quoted 10 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Darrick" == Darrick J Wong <[email protected]> writes:

Darrick> Therefore, teach bio_integrity_process() to use Darrick> bio_for_each_segment() to iterate the bio_vecs, since the Darrick> per-bio iterator tracks which bio_vecs are associated with that Darrick> particular bio. The integrity handling code is effectively Darrick> part of the "driver" (it's not the bio owner), so it must use Darrick> the correct iterator function.

Applied for 3.18.

Signature · 1 line
Jens Axboe