All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Hagberg" <ehagberg@janestreet.com>, linux-raid@vger.kernel.org
Cc: yukuai@fygo.io
Subject: Re: [REGRESSION] md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y)
Date: Mon, 30 Nov 2026 19:48:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-241916@kernel.org> (raw)
In-Reply-To: <20261130193139.1401044-1-ehagberg@janestreet.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] md/raid10: missing Signed-off-by trailer and informal inquiry
  commit message
- [High] md/raid10: premature end-of-sync teardown and false abort in
  raid10_sync_request()
- [High] md/raid10: infinite loop or 0-length bio in
  raid10_sync_request() at resync_max
- [Medium] md/raid10: broken sectors_skipped accounting and tight skip
  loop in raid10_sync_request()
- [Low] md/raid10: missing Fixes trailer for commit bc49694a9e8f in
  commit message
--

commit d99e7ee24942d79bda6cdab910442b35145994a1
Author: Eric Hagberg <ehagberg@janestreet.com>

> md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y)
>
> Hi,
>
> On 6.12.y and 6.18.y, re-adding a member to a RAID10 array with the far
> layout and an internal bitmap can complete "successfully" ([UU]) while
> the re-added member still holds stale data for regions written while it
> was absent. 6.1.y is not affected. This was seen on 2-disk
> far=2 arrays (NVMe, internal bitmap, 64 MiB bitmap chunk) after a member
> dropped out and came back; filesystems on the arrays were corrupted and
> "check" reported non-zero mismatch_cnt.
>
> #regzbot introduced: bc49694a9e8f
>
> Reproducer (loop devices, 2 x 16 GiB zero-filled sparse files):
>
>   mdadm --create /dev/md/r10 --run --assume-clean --metadata=1.2 \
>         --level=10 --raid-devices=2 --layout=f2 --chunk=512 \
>         --bitmap=internal --bitmap-chunk=65536 /dev/loopA /dev/loopB
>   mdadm /dev/md/r10 --fail /dev/loopB --remove /dev/loopB
>   # write a 64 MiB random payload with O_DIRECT to every third
>   # 64 MiB bitmap chunk (85 regions)
>   mdadm /dev/md/r10 --re-add /dev/loopB      # bitmap-based recovery
>   mdadm --wait /dev/md/r10                   # until [UU]
>   echo check > /sys/block/mdX/md/sync_action; mdadm --wait /dev/md/r10
>   cat /sys/block/mdX/md/mismatch_cnt
>   mdadm /dev/md/r10 --fail /dev/loopA --remove /dev/loopA
>   # read the 85 regions back (now served only by loopB) and compare
>
> Results ("OK" = mismatch_cnt 0 and every region read back correctly from
> the re-added member):
>
>   kernel        far=2        near=2
>   6.1           OK           OK
>   6.12          CORRUPTION   OK
>   6.18          CORRUPTION   OK
>
> We have not yet tested 7.x. A full script is available on request.
>
> Our analysis, which we would appreciate having checked:
>
> Commit bc49694a9e8f ("md: pass in max_sectors for pers->sync_request()"),
> merged in v6.11, removed the recomputation of max_sector at the
> 'skipped:' label in raid10_sync_request(). The giveup path still shrinks
> max_sector to sector_nr + max_sync, advances sector_nr to it and jumps
> back to the label, where "sector_nr >= max_sector" is now true. The
> function then takes the end-of-sync branch and calls the bitmap's
> close_sync(), which clears RESYNC on every bitmap chunk whose sync has
> started, as if it had completed.
>
> During a bitmap-based recovery, every region that is clean in the bitmap
> takes the giveup path. With the far layout, the data covered by one
> bitmap chunk is split between the first and second halves of the
> recovering member. Once a clean region is skipped, chunks whose first
> half has been recovered are treated as done, their second half is
> skipped, and the member is marked In_sync with stale data. Near layouts
> recover each bitmap chunk contiguously, which matches what we see.
>
> In mainline, 7435b73f05fb ("md/raid10: cleanup skip handling in
> raid10_sync_request"), in v7.0, removed the skip loop and carries
> "Fixes: bc49694a9e8f", but has no Cc: stable and is not in 6.12.y or
> 6.18.y. It is patch 11 of a 12-patch series and appears to depend on
> earlier patches in it (it stops checking rdev_set_badblocks() return
> values, which relies on "md: mark rdev Faulty when badblocks setting
> fails").
>
> Questions:
>
> 1. Does this analysis look right to you?
> 2. What is the preferred fix for 6.12.y and 6.18.y: backporting
>    7435b73f05fb together with the patches it depends on, or a smaller
>    targeted fix?
>
> As a starting point for discussion only (not a formal submission), the
> minimal change we tried restores the pre-6.11 recomputation by resetting
> max_sector to the caller's value at the label. With it, the reproducer
> passes for both layouts on 6.12 and 6.18. We have since had
> concerns raised about it internally and would value your view on
> whether it is safe:

[Severity: High]
This commit is missing a Signed-off-by: trailer and has an informal
mailing-list inquiry as its changelog rather than a commit description.

[Severity: Low]
For a formal submission fixing the regression, the commit message should
also carry:

  Fixes: bc49694a9e8f ("md: pass in max_sectors for pers->sync_request()")

> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 2a9c4ee982e02..bddab5f9909e2 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -3150,6 +3150,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>  	sector_t chunk_mask = conf->geo.chunk_mask;
>  	int page_idx = 0;
>  	int error_disk = -1;
> +	sector_t orig_max_sector = max_sector;
>  
>  	/*
>  	 * Allow skipping a full rebuild for incremental assembly
> @@ -3171,6 +3172,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
>  			return 0;
>  
>   skipped:
> +	max_sector = orig_max_sector;
>  	if (sector_nr >= max_sector) {
>  		conf->cluster_sync_low = 0;
>  		conf->cluster_sync_high = 0;

[Severity: High]
Can resetting max_sector at skipped: trigger premature end-of-sync
teardown and a false abort when a skipped region reaches the end of the
array?

md_do_sync() only updates mddev->curr_resync after ->sync_request()
returns, and only calls ->sync_request(mddev, max_sectors, max_sectors,
&skipped) to run the sector_nr >= max_sector teardown block after waiting
for mddev->recovery_active to drain.  When a mid-sync call skips clean
bitmap blocks up to orig_max_sector via giveup:, sector_nr reaches
max_sector inside the active iteration while mddev->curr_resync is still
the starting offset j (< max_sector):

drivers/md/raid10.c:raid10_sync_request() {
	...
	if (sector_nr >= max_sector) {
		...
		if (mddev->curr_resync < max_sector) { /* aborted */
			if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
				md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
						   &sync_blocks, 1);
			else for (i = 0; i < conf->geo.raid_disks; i++) {
				sector_t sect =
					raid10_find_virt(conf, mddev->curr_resync, i);
				md_bitmap_end_sync(mddev->bitmap, sect,
						   &sync_blocks, 1);
			}
		} else {
			...
		}
		md_bitmap_close_sync(mddev->bitmap);
		close_sync(conf);
		*skipped = 1;
		return sectors_skipped;
	}
}

Because mddev->curr_resync < max_sector is always true here, this takes
the aborted branch (calling md_bitmap_end_sync(..., 1), which can re-mark
already-synced bitmap chunks with NEEDED_MASK, and skipping replacement
recovery_offset = MaxSector and conf->fullsync = 0).  It also runs
md_bitmap_close_sync() while earlier recovery I/Os are still in flight,
and destroys conf->r10buf_pool in close_sync(conf) before md_do_sync()
makes its final end-of-sync call (which then re-initializes and
re-destroys r10buf_pool).

[Severity: High]
What happens when mddev->resync_max is set below orig_max_sector (for
example via /sys/block/mdX/md/sync_max) and the giveup -> skipped loop
advances sector_nr up to mddev->resync_max?

At skipped:, resetting max_sector = orig_max_sector makes sector_nr >=
max_sector false because sector_nr == mddev->resync_max < orig_max_sector.
Later in raid10_sync_request(), max_sector is clamped back down to
mddev->resync_max:

drivers/md/raid10.c:raid10_sync_request() {
	...
	if (max_sector > mddev->resync_max)
		max_sector = mddev->resync_max; /* Don't do IO beyond here */
	...
}

Execution then continues with sector_nr == max_sector.  If the block at
resync_max is clean in the bitmap, chunks_skipped is set to -1 and giveup:
adds 0 to sector_nr, increments chunks_skipped back to 0, and jumps to
skipped: in an unbreakable infinite loop.  If the block at resync_max
needs syncing, the page-adding loop sees len == 0 on page_idx == 0 and
submits a 0-sector bio with no pages.

[Severity: Medium]
Does re-enabling the internal giveup -> skipped loop across clean bitmap
regions also break sectors_skipped accounting when a dirty chunk follows
a skipped clean region?

When raid10_sync_request() skips clean bitmap blocks and then submits I/O
for a dirty block in the same call, it finishes with:

drivers/md/raid10.c:raid10_sync_request() {
	...
	if (sectors_skipped)
		/* pretend they weren't skipped, it makes
		 * no important difference in this case
		 */
		md_done_sync(mddev, sectors_skipped, 1);

	return sectors_skipped + nr_sectors;
}

This has several bad interactions with md_do_sync():

1. md_done_sync() takes a signed int blocks argument (truncating 64-bit
   sector_t sectors_skipped above 1 TiB) and subtracts it from
   mddev->recovery_active before raid10_sync_request() returns and before
   md_do_sync() adds the returned sectors to mddev->recovery_active,
   transiently underflowing recovery_active.
2. Because *skipped is 0, md_do_sync() adds sectors_skipped + nr_sectors
   to io_sectors, counting skipped clean bitmap space as completed disk
   I/O and inflating currspeed above speed_max(mddev), which stalls
   recovery in msleep(500) for up to 30 seconds.
3. Because clean bitmap blocks set chunks_skipped = -1 and cap max_sync at
   128 KiB, the internal loop scans clean regions in 128 KiB steps without
   cond_resched() or MD_RECOVERY_INTR checks when conf->nr_waiting == 0,
   and sleeps 1 jiffy per 128 KiB in schedule_timeout_uninterruptible(1)
   whenever conf->nr_waiting > 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130193139.1401044-1-ehagberg@janestreet.com?part=1

      reply	other threads:[~2026-11-30 19:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 19:31 [REGRESSION] md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y) Eric Hagberg
2026-11-30 19:48 ` sashiko-bot [this message]

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=sashiko-outbox-241916@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ehagberg@janestreet.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yukuai@fygo.io \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.