Linux RAID subsystem development
 help / color / mirror / Atom feed
From: Eric Hagberg <ehagberg@janestreet.com>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Jason Chu <jaschu@janestreet.com>,
	Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	Eric Hagberg <ehagberg@janestreet.com>
Subject: [PATCH RESEND 1/3] md/raid10: do not skip past the range that sync_request examined
Date: Fri,  4 Dec 2026 12:46:18 -0500	[thread overview]
Message-ID: <20261204174621.3475573-2-ehagberg@janestreet.com> (raw)
In-Reply-To: <20261204174621.3475573-1-ehagberg@janestreet.com>

From: Jason Chu <jaschu@janestreet.com>

When a range needs no I/O, raid10_sync_request() returns the number of
sectors that md may skip. Before it looks at a range it lowers max_sector
to resync_max and, if near_copies < raid_disks, to the end of the current
chunk, because the mapping between member sectors and array sectors
changes at every chunk boundary. The bitmap and the bad block lists are
then consulted for that range only.

Since commit 7435b73f05fb ("md/raid10: cleanup skip handling in
raid10_sync_request") the two "nothing to do here" paths return max_sync.
max_sync is limited by what the bitmap says about the array sector that
sector_nr maps to, and by bad blocks, but not by max_sector. It can be as
large as RESYNC_BLOCK_SIZE, which is 64KiB.

During recovery of an array with near_copies < raid_disks and a chunk
size below 64KiB, one clean chunk therefore makes md advance over the
following chunks of the same member. Those chunks hold other array
sectors, and the bitmap is never asked about them. If they are dirty
their copies are not rebuilt, the member is still marked In_sync, and
reads from it return old data.

Before that commit the giveup path limited the skip to the examined
range:

	if (sector_nr + max_sync < max_sector)
		max_sector = sector_nr + max_sync;

	sectors_skipped += (max_sector - sector_nr);

Reproduced on v7.4-rc5 in a KVM guest with the "recovery-small-chunk" test
of the script in the cover letter: 3 members, near=2, 4KiB chunks, 64KiB
bitmap chunks; member 1 is removed, eight 64KiB regions are written, and
member 1 is re-added. Recovery is not interrupted.

  before: verdict=FAIL stale_regions_read_without_member0=8/8
          mismatch_cnt=320
  after:  verdict=PASS stale_regions_read_without_member0=0/8
          mismatch_cnt=0

The same test passes on 6.12.117, which does not have 7435b73f05fb.

Return the smaller of max_sync and the examined range from the recovery
path. Do the same in the resync path that is taken when fewer than two
copies are readable: its bad block lookups are for the member addresses of
the current chunk, and it must not pass resync_max either. The resync
path was changed by reading the code; the reproducer covers the recovery
path only.

Two other returns are not changed. The clean-bitmap return in the resync
path ("We can skip this block") can still move the cursor past
resync_max, without doing I/O there. The return after a failed
bio_add_page() still returns max_sync.

Fixes: 7435b73f05fb ("md/raid10: cleanup skip handling in raid10_sync_request")
Cc: stable@vger.kernel.org
Signed-off-by: Jason Chu <jaschu@janestreet.com>
Signed-off-by: Eric Hagberg <ehagberg@janestreet.com>
---
 drivers/md/raid10.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 066c431..3ef0143 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3457,8 +3457,14 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
 				rb2->master_bio = NULL;
 				put_buf(rb2);
 			}
+			/*
+			 * Only this range was examined: it ends at
+			 * resync_max and at the chunk boundary where the
+			 * mapping changes.
+			 */
 			*skipped = 1;
-			return max_sync;
+			return min_t(sector_t, max_sync,
+				     max_sector - sector_nr);
 		}
 	} else {
 		/* resync. Schedule a read for every block at this virt offset */
@@ -3575,7 +3581,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
 			}
 			put_buf(r10_bio);
 			*skipped = 1;
-			return max_sync;
+			return min_t(sector_t, max_sync,
+				     max_sector - sector_nr);
 		}
 	}
 
-- 
2.43.7


  reply	other threads:[~2026-12-04 17:46 UTC|newest]

Thread overview: 10+ 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
2026-12-04 17:46 ` [PATCH RESEND 0/3] md/raid10: fix old data left by skipped and interrupted sync Eric Hagberg
2026-12-04 17:46   ` Eric Hagberg [this message]
2026-12-04 17:46   ` [PATCH RESEND 2/3] md/raid10: re-arm in-progress bitmap chunks when recovery is interrupted Eric Hagberg
2026-12-04 18:16     ` sashiko-bot
2026-12-04 19:17       ` Eric Hagberg
2026-12-04 17:46   ` [PATCH RESEND 3/3] md/raid10: keep look-ahead bitmap chunks when resync " Eric Hagberg
2026-12-04 18:09     ` sashiko-bot
2026-12-04 19:18       ` Eric Hagberg

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=20261204174621.3475573-2-ehagberg@janestreet.com \
    --to=ehagberg@janestreet.com \
    --cc=jaschu@janestreet.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox