Re: [PATCH v5 11/29] md: add helper to split bios at reshape offset
[email protected] Sun, 02 Aug 2026 20:19:20 +0000
| Newsgroups | gmane.linux.raid |
|---|---|
| Message-ID | <[email protected]> |
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 l= eads to silent data corruption. -- --- Patch [11]: [PATCH v5 11/29] md: add helper to split bios at reshape of= fset --- commit 7816e7809a77baa291a2c8013717413f881d0cdc Author: Yu Kuai <[email protected]> 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. > diff --git a/drivers/md/md.c b/drivers/md/md.c > --- a/drivers/md/md.c > +++ b/drivers/md/md.c [ ... ] > @@ -9388,6 +9388,45 @@ void md_submit_discard_bio(struct mddev *mddev, st= ruct 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 =3D bio_sectors(bio); > + if (max_sectors && *max_sectors && *max_sectors < split_sectors) > + split_sectors =3D *max_sectors; > + > + if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) > + goto split; > + > + boundary =3D 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 t= wo 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 =3D bio->bi_iter.bi_sector; > + end =3D bio_end_sector(bio); > + if (start >=3D boundary || end <=3D boundary) > + goto split; > + > + if (boundary - start < split_sectors) > + split_sectors =3D boundary - start; > + > +split: [ ... ] --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260802195038.1642= [email protected]?part=3D11