Linux RAID subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yu Kuai" <yukuai@kernel.org>
Cc: yukuai@fygo.io, linux-raid@vger.kernel.org
Subject: Re: [PATCH v4 22/25] md/raid5: add exact old and new llbitmap mapping helpers
Date: Sat, 01 Aug 2026 18:05:53 +0000	[thread overview]
Message-ID: <20260801180554.3006E1F00ACA@smtp.kernel.org> (raw)
In-Reply-To: <20260801172519.2982121-23-yukuai@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The newly introduced `raid5_bitmap_array_sectors` incorrectly calculates the previous array size when shrinking, returning the new smaller size instead of the exact old size.

Pre-existing issues:
- [Critical] Bitmap mapping logic uses the current `conf->max_degraded` to compute the previous layout's data disks, corrupting mapping during RAID level migration.
- [High] Integer overflow on 32-bit architectures in `raid5_bitmap_sector` when computing `*sectors` during reshape of large arrays.
--

--- Patch [22]: [PATCH v4 22/25] md/raid5: add exact old and new llbitmap mapping helpers ---
commit 2b6e9c9ff8dbd00ebcd0c4b00c57f4d4ef3e5964
Author: Yu Kuai <yukuai@fygo.io>

md/raid5: add exact old and new llbitmap mapping helpers
    
Teach RAID5 to export exact old and new llbitmap mappings and the
corresponding sync and array sizes for reshape-aware bitmap users.

> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index 8b3483674398d..af7775278af6d 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -5942,28 +5942,46 @@ static enum reshape_loc get_reshape_loc(struct mddev *mddev,
>  	return LOC_BEHIND_RESHAPE;
>  }
>  
> -static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset,
> -				unsigned long *sectors)
> +static void raid5_bitmap_sector_map(struct mddev *mddev, sector_t *offset,
> +				    unsigned long *sectors,
> +				    bool previous)
>  {
>  	struct r5conf *conf = mddev->private;
>  	sector_t start = *offset;
>  	sector_t end = start + *sectors;
> -	sector_t prev_start = start;
> -	sector_t prev_end = end;
>  	int sectors_per_chunk;
> -	enum reshape_loc loc;
>  	int dd_idx;
>  
> -	sectors_per_chunk = conf->chunk_sectors *
> -		(conf->raid_disks - conf->max_degraded);
> +	if (previous)
> +		sectors_per_chunk = conf->prev_chunk_sectors *
> +			(conf->previous_raid_disks - conf->max_degraded);

[Severity: Critical]
This is a pre-existing issue, but I noticed we are using the current layout's
max_degraded value to compute the previous layout's physical sectors here.

During a RAID5 to RAID6 migration, conf->max_degraded is updated to 2
immediately at the start of the reshape. However, the old RAID5 layout only
had 1 parity disk.

If we subtract 2 instead of 1, does this corrupt the logical-to-physical chunk
translation for the previous layout? It seems write operations ahead of the
reshape might dirty the wrong bits in the bitmap, potentially leading to silent
data corruption or skipped resyncs after a crash.

I also noticed raid5_compute_sector() applies the current max_degraded to the
previous layout's data_disks computation:

drivers/md/raid5.c:raid5_compute_sector() {
        ...
        int raid_disks = previous ? conf->previous_raid_disks
                                  : conf->raid_disks;
        int data_disks = raid_disks - conf->max_degraded;
        ...
}

Should we be tracking the previous layout's parity disk count separately?

> +	else
> +		sectors_per_chunk = conf->chunk_sectors *
> +			(conf->raid_disks - conf->max_degraded);
>  	sector_div(start, sectors_per_chunk);
>  	start *= sectors_per_chunk;

[ ... ]

> @@ -5992,7 +6001,7 @@ static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset,
>  	 * we set bits for both.
>  	 */
>  	*offset = min(start, prev_start);
> -	*sectors = max(end, prev_end) - *offset;
> +	*sectors = max(end, prev_start + prev_sectors) - *offset;

[Severity: High]
This is a pre-existing issue, but could this subtraction result in an integer
overflow on 32-bit architectures?

For large arrays (e.g., >24TB), the physical sector distance between the old
and new mappings for a single logical address can exceed ULONG_MAX.

Since *sectors is a 32-bit unsigned long pointer on 32-bit architectures, it
seems this subtraction could truncate the 64-bit sector_t value. If that
happens, might the bitmap logic only mark a small lower portion of the span
as dirty due to the integer wrap-around?

>  }
>  
>  static enum stripe_result make_stripe_request(struct mddev *mddev,

[ ... ]

> @@ -9059,6 +9068,20 @@ static void raid5_prepare_suspend(struct mddev *mddev)
>  	wake_up(&conf->wait_for_reshape);
>  }
>  
> +static sector_t raid5_bitmap_sync_size(struct mddev *mddev, bool previous)
> +{
> +	return mddev->dev_sectors;
> +}
> +
> +static sector_t raid5_bitmap_array_sectors(struct mddev *mddev, bool previous)
> +{
> +	struct r5conf *conf = mddev->private;
> +
> +	if (previous)
> +		return raid5_size(mddev, 0, 0);

[Severity: High]
When shrinking an array, the previous array size is larger than the new array
size.

By passing 0 for the raid_disks argument, raid5_size() calculates the size
using min(conf->raid_disks, conf->previous_raid_disks).

Will this evaluate to the new, smaller size instead of the exact previous
capacity? If reshape-aware bitmap users are tracking the tail of the array
during a backwards reshape, this might fail to export the exact original tail
boundaries and lead to missed bitmap synchronizations.

> +	return raid5_size(mddev, mddev->dev_sectors, conf->raid_disks);
> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260801172519.2982121-1-yukuai@kernel.org?part=22

  reply	other threads:[~2026-08-01 18:05 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01 17:24 [PATCH v4 00/25] md: improve lockless bitmap reshape support Yu Kuai
2026-08-01 17:24 ` [PATCH v4 01/25] md/md-llbitmap: clear flush state after daemon flush Yu Kuai
2026-08-01 17:43   ` sashiko-bot
2026-08-01 17:24 ` [PATCH v4 02/25] md/md-llbitmap: use GFP_NOIO for cache allocations Yu Kuai
2026-08-01 17:41   ` sashiko-bot
2026-08-01 17:24 ` [PATCH v4 03/25] md/md-llbitmap: only end fully synced chunks Yu Kuai
2026-08-01 17:42   ` sashiko-bot
2026-08-01 17:24 ` [PATCH v4 04/25] md/raid5: reject zero-sector reshape chunks Yu Kuai
2026-08-01 17:45   ` sashiko-bot
2026-08-01 17:24 ` [PATCH v4 05/25] md/raid5: round bitmap stripes with sector division Yu Kuai
2026-08-01 17:39   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 06/25] md: add exact bitmap mapping and reshape hooks Yu Kuai
2026-08-01 17:25 ` [PATCH v4 07/25] md: skip bitmap accounting for empty write ranges Yu Kuai
2026-08-01 18:05   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 08/25] md: add helper to split bios at reshape offset Yu Kuai
2026-08-01 17:41   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 09/25] md/md-llbitmap: track bitmap sync_size explicitly Yu Kuai
2026-08-01 17:44   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 10/25] md/md-llbitmap: allocate page controls independently Yu Kuai
2026-08-01 17:47   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 11/25] md/md-llbitmap: grow the page cache in place for reshape Yu Kuai
2026-08-01 18:03   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 12/25] md/md-llbitmap: track target reshape geometry fields Yu Kuai
2026-08-01 17:51   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 13/25] md/md-llbitmap: finish reshape geometry Yu Kuai
2026-08-01 17:59   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 14/25] md/md-llbitmap: refuse reshape while llbitmap still needs sync Yu Kuai
2026-08-01 17:50   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 15/25] md/md-llbitmap: add reshape range mapping helpers Yu Kuai
2026-08-01 17:47   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 16/25] md/md-llbitmap: don't skip reshape ranges from bitmap state Yu Kuai
2026-08-01 17:41   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 17/25] md/md-llbitmap: remap checkpointed bits as reshape progresses Yu Kuai
2026-08-01 18:12   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 18/25] md/md-llbitmap: clamp state-machine walks to tracked bits Yu Kuai
2026-08-01 17:55   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 19/25] md/raid10: reject llbitmap reshape when md chunk shrinks Yu Kuai
2026-08-01 17:25 ` [PATCH v4 20/25] md/raid10: wire llbitmap reshape lifecycle Yu Kuai
2026-08-01 18:28   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 21/25] md/raid10: split reshape bios before bitmap accounting Yu Kuai
2026-08-01 17:59   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 22/25] md/raid5: add exact old and new llbitmap mapping helpers Yu Kuai
2026-08-01 18:05   ` sashiko-bot [this message]
2026-08-01 17:25 ` [PATCH v4 23/25] md/raid5: reject llbitmap reshape when md chunk shrinks Yu Kuai
2026-08-01 17:25 ` [PATCH v4 24/25] md/raid5: wire llbitmap reshape lifecycle Yu Kuai
2026-08-01 18:12   ` sashiko-bot
2026-08-01 17:25 ` [PATCH v4 25/25] md/raid5: split reshape bios before bitmap accounting Yu Kuai
2026-08-01 18:43   ` sashiko-bot
2026-08-02 16:13 ` [PATCH v4 00/25] md: improve lockless bitmap reshape support Mykola Marzhan
2026-08-02 19:13   ` yu kuai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260801180554.3006E1F00ACA@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yukuai@fygo.io \
    --cc=yukuai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox