Re: [PATCH v5 11/29] md: add helper to split bios at reshape offset
From: sashiko-bot@kernel.org
Date: 2026-08-02 20:19:21
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Torn read of 64-bit reshape_position on 32-bit architectures leads to silent data corruption. --
--- Patch [11]: [PATCH v5 11/29] md: add helper to split bios at reshape offset ---commit 7816e7809a77baa291a2c8013717413f881d0cdc Author: Yu Kuai [off-list ref] md: add helper to split bios at reshape offset This commit adds mddev_bio_split_at_reshape_offset() to allow md personalities to share reshape-offset bio splitting. It snapshots mddev->reshape_position to determine if the bio crosses the reshape boundary and limits the front bio accordingly.
quoted hunk ↗ jump to hunk
diff --git a/drivers/md/md.c b/drivers/md/md.c --- a/drivers/md/md.c +++ b/drivers/md/md.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -9388,6 +9388,45 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev, +struct bio *mddev_bio_split_at_reshape_offset(struct mddev *mddev, + struct bio *bio, + unsigned int *max_sectors, + struct bio_set *bs) +{ + sector_t boundary; + sector_t start; + sector_t end; + unsigned int split_sectors; + + split_sectors = bio_sectors(bio); + if (max_sectors && *max_sectors && *max_sectors < split_sectors) + split_sectors = *max_sectors; + + if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) + goto split; + + boundary = READ_ONCE(mddev->reshape_position);
[Severity: Critical] Is it safe to use READ_ONCE() on a 64-bit value here? On 32-bit architectures, sector_t is 64-bit, so READ_ONCE() will generate two non-atomic 32-bit memory load instructions. If the reshape thread updates mddev->reshape_position concurrently, this could result in a torn read. A torn read would make boundary completely incorrect, causing split_sectors to be miscalculated. Because the reshape boundary separates two different physical data layouts, could sending IO based on a torn boundary write data to the wrong physical disk locations and cause data corruption?
+ start = bio->bi_iter.bi_sector; + end = bio_end_sector(bio); + if (start >= boundary || end <= boundary) + goto split; + + if (boundary - start < split_sectors) + split_sectors = boundary - start; + +split:
[ ... ] -- Sashiko AI review · https://sashiko.dev/#/patchset/20260802195038.164272-1-yukuai@kernel.org?part=11