Re: [PATCH v3 04/21] md: add helper to split bios at reshape offset
From: sashiko-bot@kernel.org
Date: 2026-07-28 09:03:19
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Lockless read of the 64-bit `mddev->reshape_position` and missing memory barriers after `MD_RECOVERY_RESHAPE` cause torn reads and inconsistent state observation. --
--- Patch [4]: [PATCH v3 04/21] md: add helper to split bios at reshape offset ---commit df6c72a7c4a6271ac6b7e8dc1420ce49f5ef19d3 Author: Yu Kuai [off-list ref] md: add helper to split bios at reshape offset This commit adds mddev_bio_split_at_reshape_offset() so personalities can share reshape-offset bio splitting instead of open-coding the same helper in multiple places.
quoted hunk ↗ jump to hunk
diff --git a/drivers/md/md.c b/drivers/md/md.c index 0b59c676f7c03..c18a7f3c27e65 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c@@ -9361,6 +9361,45 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev, } EXPORT_SYMBOL_GPL(md_submit_discard_bio); +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 = mddev->reshape_position;
[Severity: High] Can this lockless read of mddev->reshape_position lead to torn reads? Since reshape_position is a 64-bit value, reading it concurrently with background reshape updates from sync_thread might result in a torn read on 32-bit architectures. A torn read could produce an arbitrary split boundary, potentially causing misaligned bio splits and IO errors. Additionally, are memory barriers needed after testing MD_RECOVERY_RESHAPE to ensure a consistent value is observed on weakly ordered architectures? -- Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785206690.git.yukuai@fygo.io?part=4