[PATCH 3/8] md/raid1,raid10: fail writes that waited while the array failed
From: Miroslav Cimerman
Date: Thu Nov 26 2026 - 19:33:06 EST
md_submit_bio() fails new writes once MD_BROKEN is set. A write that
arrives while a failed device is being recorded passes that check and
waits for the superblock update. If the update fails on the last
working device, MD_BROKEN is set during the wait. The write then
continues, reaches only the remaining device and completes with
success. After a restart, both devices assemble as in sync, and reads
can return the old data.
Check MD_BROKEN again after the wait, and fail the write. dm-raid does
not go through md_submit_bio(), so leave it unchanged. Large raid10
discards go through raid10_handle_discard() and are left as they are.
Fixes: 9631abdbf406 ("md: Set MD_BROKEN for RAID1 and RAID10")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
drivers/md/raid1.c | 12 ++++++++++++
drivers/md/raid10.c | 11 +++++++++++
2 files changed, 23 insertions(+)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 37d120a63778..88bbe81c7798 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1489,6 +1489,18 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio,
wait_blocked_rdev(mddev, bio);
+ /*
+ * If the array failed while this write waited, the failed device
+ * might not be recorded. Fail the write, as md_submit_bio() does,
+ * except for dm-raid.
+ */
+ if (unlikely(!mddev_is_dm(mddev) &&
+ test_bit(MD_BROKEN, &mddev->flags))) {
+ bio_io_error(bio);
+ allow_barrier(conf, sector);
+ return false;
+ }
+
r1_bio = alloc_r1bio(mddev, bio);
r1_bio->sectors = max_sectors;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a97831823c68..a38b95585e35 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1378,6 +1378,17 @@ static bool raid10_write_request(struct mddev *mddev, struct bio *bio,
wait_blocked_dev(mddev, r10_bio);
+ /*
+ * If the array failed while this write waited, the failed device
+ * might not be recorded. Fail the write, as md_submit_bio() does,
+ * except for dm-raid.
+ */
+ if (unlikely(!mddev_is_dm(mddev) &&
+ test_bit(MD_BROKEN, &mddev->flags))) {
+ raid_end_bio_io(r10_bio);
+ return false;
+ }
+
max_sectors = r10_bio->sectors;
for (i = 0; i < conf->copies; i++) {
--
2.53.0