Re: [PATCH v3 01/21] md/raid5: round bitmap stripes with sector division

[email protected] Tue, 28 Jul 2026 09:03:07 +0000
Newsgroups org.kernel.vger.linux-raid
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The commit message references a non-existent function `raid5_bitmap_sector_map()`.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the logic for calculating the previous array layout's upper bound `prev_end` incorrectly rounds down instead of rounding up, truncating the bitmap update range during an array reshape.
--

--- Patch [1]: [PATCH v3 01/21] md/raid5: round bitmap stripes with sector division ---
commit a735680352819f937150899bfef4b4a4111690e0
Author: Yu Kuai <[email protected]>

md/raid5: round bitmap stripes with sector division

This commit fixes rounding logic when aligning the array range to full RAID5
stripe widths. It replaces the mask-based round_down() and round_up() logic
with sector_div() based arithmetic to correctly handle stripe widths that are
not powers of two.

Link: https://lore.kernel.org/all/[email protected]/

> md/raid5: round bitmap stripes with sector division
> 
> raid5_bitmap_sector_map() aligns the array range to full RAID5 stripe
> widths before converting it to component sectors. That width is

[Severity: Medium]
Does the commit message reference a function that isn't included in this
patch? The modifications appear to be applied directly inline within
raid5_bitmap_sector(), rather than a new raid5_bitmap_sector_map() helper.

> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index 0c5c9fb0606ee..35910bc6683bf 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -5956,8 +5956,11 @@ static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset,
>  
>  	sectors_per_chunk = conf->chunk_sectors *
>  		(conf->raid_disks - conf->max_degraded);
> -	start = round_down(start, sectors_per_chunk);
> -	end = round_up(end, sectors_per_chunk);
> +	sector_div(start, sectors_per_chunk);
> +	start *= sectors_per_chunk;
> +	if (sector_div(end, sectors_per_chunk))
> +		end++;
> +	end *= sectors_per_chunk;
>  
>  	start = raid5_compute_sector(conf, start, 0, &dd_idx, NULL);
>  	end = raid5_compute_sector(conf, end, 0, &dd_idx, NULL);

[ ... ]

> @@ -5975,8 +5978,10 @@ static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset,
>  
>  	sectors_per_chunk = conf->prev_chunk_sectors *
>  		(conf->previous_raid_disks - conf->max_degraded);
> -	prev_start = round_down(prev_start, sectors_per_chunk);
> -	prev_end = round_down(prev_end, sectors_per_chunk);
> +	sector_div(prev_start, sectors_per_chunk);
> +	prev_start *= sectors_per_chunk;
> +	sector_div(prev_end, sectors_per_chunk);
> +	prev_end *= sectors_per_chunk;

[Severity: High]
This isn't a bug introduced by this patch, but does the division logic for
prev_end truncate the tracked bitmap range during an array reshape?

Because prev_end serves as an exclusive upper bound, mathematically rounding
it down (which the previous round_down() logic also did) means that if an I/O
write crosses a chunk boundary, it gets a remainder when divided by
sectors_per_chunk. 

Since the remainder doesn't trigger an increment (like it now does for end),
dirty sectors at the end of the I/O are not marked in the bitmap for the
previous layout. If a crash occurs, these unmarked sectors wouldn't be
resynced, which could lead to stale parity and silent data corruption.

-- 
Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1