Skip to content

Commit b4d78cf

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm-integrity: align the outgoing bio in integrity_recheck
It is possible to set up dm-integrity with smaller sector size than the logical sector size of the underlying device. In this situation, dm-integrity guarantees that the outgoing bios have the same alignment as incoming bios (so, if you create a filesystem with 4k block size, dm-integrity would send 4k-aligned bios to the underlying device). This guarantee was broken when integrity_recheck was implemented. integrity_recheck sends bio that is aligned to ic->sectors_per_block. So if we set up integrity with 512-byte sector size on a device with logical block size 4k, we would be sending unaligned bio. This triggered a bug in one of our internal tests. This commit fixes it by determining the actual alignment of the incoming bio and then makes sure that the outgoing bio in integrity_recheck has the same alignment. Fixes: c88f5e5 ("dm-integrity: recheck the integrity tag after a failure") Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 6e7132e commit b4d78cf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/md/dm-integrity.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,6 @@ static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checks
16991699
struct bio_vec bv;
17001700
sector_t sector, logical_sector, area, offset;
17011701
struct page *page;
1702-
void *buffer;
17031702

17041703
get_area_and_offset(ic, dio->range.logical_sector, &area, &offset);
17051704
dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset,
@@ -1708,13 +1707,14 @@ static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checks
17081707
logical_sector = dio->range.logical_sector;
17091708

17101709
page = mempool_alloc(&ic->recheck_pool, GFP_NOIO);
1711-
buffer = page_to_virt(page);
17121710

17131711
__bio_for_each_segment(bv, bio, iter, dio->bio_details.bi_iter) {
17141712
unsigned pos = 0;
17151713

17161714
do {
1715+
sector_t alignment;
17171716
char *mem;
1717+
char *buffer = page_to_virt(page);
17181718
int r;
17191719
struct dm_io_request io_req;
17201720
struct dm_io_region io_loc;
@@ -1727,6 +1727,14 @@ static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checks
17271727
io_loc.sector = sector;
17281728
io_loc.count = ic->sectors_per_block;
17291729

1730+
/* Align the bio to logical block size */
1731+
alignment = dio->range.logical_sector | bio_sectors(bio) | (PAGE_SIZE >> SECTOR_SHIFT);
1732+
alignment &= -alignment;
1733+
io_loc.sector = round_down(io_loc.sector, alignment);
1734+
io_loc.count += sector - io_loc.sector;
1735+
buffer += (sector - io_loc.sector) << SECTOR_SHIFT;
1736+
io_loc.count = round_up(io_loc.count, alignment);
1737+
17301738
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
17311739
if (unlikely(r)) {
17321740
dio->bi_status = errno_to_blk_status(r);

0 commit comments

Comments
 (0)