[PATCH RESEND 1/3] md/raid10: do not skip past the range that sync_request examined

From: Eric Hagberg

Date: Fri Dec 04 2026 - 12:46:43 EST


From: Jason Chu <jaschu@xxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxx
Signed-off-by: Jason Chu <jaschu@xxxxxxxxxxxxxx>
Signed-off-by: Eric Hagberg <ehagberg@xxxxxxxxxxxxxx>
---
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