From: sashiko-bot@kernel.org
To: "Yu Kuai" <yukuai@kernel.org>
Cc: yukuai@fygo.io, linux-raid@vger.kernel.org
Subject: Re: [PATCH v3 11/21] md/md-llbitmap: add reshape range mapping helpers
Date: Tue, 28 Jul 2026 09:11:38 +0000 [thread overview]
Message-ID: <20260728091138.D4EDF1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <2964489adb127bd678251deeb9ece095fa39495c.1785206690.git.yukuai@fygo.io>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Missing post-map sync-size clamp in llbitmap_map_layout() allows mapped physical sectors to exceed the bitmap capacity, causing OOB array accesses.
- [Critical] The `bitmap_array_sectors` callback is not implemented for any personality (e.g. RAID5), causing the pre-map clamp to incorrectly use component coordinates against array-sector IOs.
- [Critical] Coordinate mapping is completely skipped for the old geometry during reshape, leading to array coordinates being treated as component coordinates.
- [Critical] Bios crossing the reshape boundary are not split before bitmap accounting, causing `llbitmap` to encode the entire range with a single geometry.
--
--- Patch [11]: [PATCH v3 11/21] md/md-llbitmap: add reshape range mapping helpers ---
commit b480f867a40652c2963e56247233a10fff0a56b8
Author: Yu Kuai <yukuai@fygo.io>
md/md-llbitmap: add reshape range mapping helpers
This commit adds reshape range mapping helpers to llbitmap to differentiate
between old and new geometry during a reshape. It also introduces
discard-specific range encoding and clamps pre-map ranges in the same
coordinate space as incoming IO.
Link: https://lore.kernel.org/all/20260726185916.2223460-1-mykola@meshstor.io/
> steady-state RAID5 must use bitmap_array_sectors() before mapping and keep
> the existing sync-size clamp after mapping.
Does the implementation match this commit message description? Looking at
llbitmap_map_layout(), it appears the post-map sync-size clamp was omitted.
> diff --git a/drivers/md/md-llbitmap.c b/drivers/md/md-llbitmap.c
> --- a/drivers/md/md-llbitmap.c
> +++ b/drivers/md/md-llbitmap.c
[ ... ]
> @@ -449,6 +450,16 @@ static sector_t llbitmap_personality_sync_size(struct llbitmap *llbitmap,
> return mddev->pers->bitmap_sync_size(mddev, previous);
> }
>
> +static sector_t llbitmap_logical_size(struct llbitmap *llbitmap, bool previous)
> +{
> + struct mddev *mddev = llbitmap->mddev;
> +
> + if (!mddev->private || !mddev->pers ||
> + !mddev->pers->bitmap_array_sectors)
> + return llbitmap_personality_sync_size(llbitmap, previous);
[Severity: Critical]
Is bitmap_array_sectors implemented for the personalities that need it?
If personalities like RAID5 do not wire up bitmap_array_sectors, this falls
back to returning llbitmap_personality_sync_size(), which uses the much
smaller component coordinates.
Because RAID5 receives IOs in array coordinates, and array coordinates are
significantly larger than component coordinates, wouldn't any write targeting
the upper portion of a RAID5 array evaluate to start >= limit inside
llbitmap_map_layout() and be silently dropped? This could lead to silent data
corruption on an unclean shutdown.
> + return mddev->pers->bitmap_array_sectors(mddev, previous);
> +}
> +
> static void llbitmap_refresh_reshape(struct llbitmap *llbitmap)
[ ... ]
> +static void llbitmap_map_layout(struct llbitmap *llbitmap, sector_t *offset,
> + unsigned long *sectors, bool previous)
> +{
> + sector_t limit = llbitmap_logical_size(llbitmap, previous);
> + sector_t start = *offset;
> + sector_t end = start + *sectors;
> +
> + if (start >= limit) {
> + *sectors = 0;
> + return;
> + }
> + if (end > limit)
> + end = limit;
> +
> + *offset = start;
> + *sectors = end - start;
> + if (!*sectors)
> + return;
> +
> + if (llbitmap->mddev->pers->bitmap_sector_map)
> + llbitmap->mddev->pers->bitmap_sector_map(llbitmap->mddev, offset,
> + sectors, previous);
> + else if (!previous && llbitmap->mddev->pers->bitmap_sector)
> + llbitmap->mddev->pers->bitmap_sector(llbitmap->mddev, offset,
> + sectors);
[Severity: Critical]
Does this logic incorrectly skip coordinate mapping for the old geometry?
During an active reshape, IOs targeting the old geometry evaluate previous to
true. Since the !previous condition prevents bitmap_sector() from being called,
array-sector offsets are passed directly to llbitmap_encode_range().
Because array offsets are much larger than component sectors, this produces
chunk indices that wildly exceed llbitmap->chunks. This can lead to
out-of-bounds memory accesses on the pctl array or corrupt the bitmap by
dirtying the wrong chunks.
[Severity: Critical]
Is a post-map sync-size clamp missing at the end of this function?
When a RAID array's size is not perfectly aligned to a multiple of chunk sizes,
bitmap_sector() rounds the end offset up to the next chunk boundary. Without
clamping the result against llbitmap_personality_sync_size(), the mapped
component sector range can exceed the physical capacity.
This un-clamped offset can yield an out-of-bounds page_end when passed into
llbitmap_start_write(), causing an out-of-bounds dereference on the
dynamically allocated llbitmap->pctl array via llbitmap_raise_barrier().
> +}
> +
> +static void llbitmap_encode_range(struct llbitmap *llbitmap, sector_t *offset,
[ ... ]
> @@ -1385,11 +1470,35 @@ static void llbitmap_destroy(struct mddev *mddev)
> mutex_unlock(&mddev->bitmap_info.mutex);
> }
>
> +static bool llbitmap_map_previous(struct llbitmap *llbitmap, sector_t offset,
> + unsigned long sectors)
> +{
> + struct mddev *mddev = llbitmap->mddev;
> + sector_t boundary = mddev->reshape_position;
> +
> + if (!llbitmap_reshaping(llbitmap))
> + return false;
> +
> + WARN_ON_ONCE(sectors && offset < boundary && offset + sectors > boundary);
[Severity: Critical]
Will this WARN_ON_ONCE trigger if bios crossing the reshape boundary are not
split beforehand?
The block layer currently accounts the entire contiguous bio as a single range
in md_account_bio(). While the helper mddev_bio_split_at_reshape_offset is
exported in this patch series, it appears it is never actually invoked by the
personalities (such as in raid5_make_request) prior to accounting.
Because this function returns a single geometry decision for the entire IO,
llbitmap_encode_range() will map the entire crossing bio using a single
chunksize. This miscalculates chunk indices for the portion of the bio sitting
in the other geometry, dirtying the wrong chunks and risking data corruption if
resync skips the correctly-associated chunks after a crash.
> +
> + return mddev->reshape_backwards ? offset < boundary : offset >= boundary;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785206690.git.yukuai@fygo.io?part=11
next prev parent reply other threads:[~2026-07-28 9:11 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 8:49 [PATCH v3 00/21] md/md-llbitmap: support reshape for RAID10 and RAID5 Yu Kuai
2026-07-28 8:49 ` [PATCH v3 01/21] md/raid5: round bitmap stripes with sector division Yu Kuai
2026-07-28 9:03 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 02/21] md: add exact bitmap mapping and reshape hooks Yu Kuai
2026-07-28 8:49 ` [PATCH v3 03/21] md: skip bitmap accounting for empty write ranges Yu Kuai
2026-07-28 8:49 ` [PATCH v3 04/21] md: add helper to split bios at reshape offset Yu Kuai
2026-07-28 9:03 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 05/21] md/md-llbitmap: track bitmap sync_size explicitly Yu Kuai
2026-07-28 9:16 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 06/21] md/md-llbitmap: allocate page controls independently Yu Kuai
2026-07-28 9:06 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 07/21] md/md-llbitmap: grow the page cache in place for reshape Yu Kuai
2026-07-28 9:09 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 08/21] md/md-llbitmap: track target reshape geometry fields Yu Kuai
2026-07-28 9:12 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 09/21] md/md-llbitmap: finish reshape geometry Yu Kuai
2026-07-28 9:14 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 10/21] md/md-llbitmap: refuse reshape while llbitmap still needs sync Yu Kuai
2026-07-28 9:12 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 11/21] md/md-llbitmap: add reshape range mapping helpers Yu Kuai
2026-07-28 9:11 ` sashiko-bot [this message]
2026-07-28 8:49 ` [PATCH v3 12/21] md/md-llbitmap: don't skip reshape ranges from bitmap state Yu Kuai
2026-07-28 8:49 ` [PATCH v3 13/21] md/md-llbitmap: remap checkpointed bits as reshape progresses Yu Kuai
2026-07-28 9:06 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 14/21] md/md-llbitmap: clamp state-machine walks to tracked bits Yu Kuai
2026-07-28 9:13 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 15/21] md/raid10: reject llbitmap reshape when md chunk shrinks Yu Kuai
2026-07-28 9:15 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 16/21] md/raid10: wire llbitmap reshape lifecycle Yu Kuai
2026-07-28 9:22 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 17/21] md/raid10: split reshape bios before bitmap accounting Yu Kuai
2026-07-28 9:15 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 18/21] md/raid5: add exact old and new llbitmap mapping helpers Yu Kuai
2026-07-28 9:25 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 19/21] md/raid5: reject llbitmap reshape when md chunk shrinks Yu Kuai
2026-07-28 9:22 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 20/21] md/raid5: wire llbitmap reshape lifecycle Yu Kuai
2026-07-28 9:21 ` sashiko-bot
2026-07-28 8:49 ` [PATCH v3 21/21] md/raid5: split reshape bios before bitmap accounting Yu Kuai
2026-07-28 9:26 ` sashiko-bot
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=20260728091138.D4EDF1F00A3E@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