1 bio_integrity_verify() doesn't verify the data integrity at all.
2 In that function, after reading the data, bio->bi_idx will be
3 equal to bio->bi_vcnt because of bio_advance(),
4 so bio_for_each_segment_all() should be used, not
5 bio_for_each_segment().
6 bio_advance() should not change the integrity data
7 bio_integrity_advance() unless the BIO is being trimmed.
8 Linux-commit: 63573e359d052e506d305c263576499f06355985
10 Index: linux-3.10.0-693.21.1.el7.x86_64/fs/bio.c
11 ===================================================================
12 --- linux-3.10.0-693.21.1.el7.x86_64.orig/fs/bio.c
13 +++ linux-3.10.0-693.21.1.el7.x86_64/fs/bio.c
14 @@ -870,9 +870,6 @@ EXPORT_SYMBOL(submit_bio_wait);
16 void bio_advance(struct bio *bio, unsigned bytes)
18 - if (bio_integrity(bio))
19 - bio_integrity_advance(bio, bytes);
21 bio->bi_sector += bytes >> 9;
22 bio->bi_size -= bytes;
24 @@ -1973,6 +1970,9 @@ void bio_trim(struct bio *bio, int offse
26 clear_bit(BIO_SEG_VALID, &bio->bi_flags);
28 + if (bio_integrity(bio))
29 + bio_integrity_advance(bio, offset << 9);
31 bio_advance(bio, offset << 9);
34 Index: linux-3.10.0-693.21.1.el7.x86_64/fs/bio-integrity.c
35 ===================================================================
36 --- linux-3.10.0-693.21.1.el7.x86_64.orig/fs/bio-integrity.c
37 +++ linux-3.10.0-693.21.1.el7.x86_64/fs/bio-integrity.c
38 @@ -463,7 +463,11 @@ static int bio_integrity_verify(struct b
39 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
40 bix.sector_size = bi->sector_size;
42 - bio_for_each_segment(bv, bio, i) {
44 + * bio->bi_idx might be equal to bio->bi_vcnt after __bio_advance(),
45 + * So use bio_for_each_segment_all() not bio_for_each_segment().
47 + bio_for_each_segment_all(bv, bio, i) {
48 void *kaddr = kmap_atomic(bv->bv_page);
49 bix.data_buf = kaddr + bv->bv_offset;
50 bix.data_size = bv->bv_len;