All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miroslav Cimerman <mc@raidlab.org>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
	NeilBrown <neil@brown.name>,
	Mariusz Tkaczyk <mtkaczyk@kernel.org>, Kenta Akagi <k@mgml.me>,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/8] md/raid1,raid10: fail held writes when the array fails
Date: Fri, 27 Nov 2026 00:32:24 +0000	[thread overview]
Message-ID: <20261127003231.1180197-2-mc@raidlab.org> (raw)
In-Reply-To: <20261127003231.1180197-1-mc@raidlab.org>

raid1 and raid10 hold a write that failed on one device until the
superblock records that device as faulty.

If the superblock write then fails on the last working device, the
error handler sets MD_BROKEN, keeps that device In_sync and requests no
new superblock update. md_update_sb() clears MD_SB_CHANGE_PENDING, and
the held write completes with success. No superblock records the failed
device. After a restart, both devices assemble as in sync, and reads
can return the old data of the failed one.

Fail the held writes when MD_BROKEN is set. dm-raid does not reject
writes when MD_BROKEN is set, so leave it unchanged.

Found with FuzzyRAID, a fault injection fuzzer for RAID
implementations.

Fixes: 55ce74d4bfe1 ("md/raid1: ensure device failure recorded before write request returns.")
Fixes: 95af587e95aa ("md/raid10: ensure device failure recorded before write request returns.")
Cc: stable@vger.kernel.org # v5.19+
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
 drivers/md/raid1.c  | 8 ++++++++
 drivers/md/raid10.c | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 25b80ad52f00..37d120a63778 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2629,6 +2629,14 @@ static void raid1d(struct md_thread *thread)
 			list_del(&r1_bio->retry_list);
 			idx = sector_to_idx(r1_bio->sector);
 			atomic_dec(&conf->nr_queued[idx]);
+			/*
+			 * If the array failed while this write was held, the
+			 * failed copy might not be recorded. Fail the write,
+			 * except for dm-raid.
+			 */
+			if (!mddev_is_dm(mddev) &&
+			    test_bit(MD_BROKEN, &mddev->flags))
+				clear_bit(R1BIO_Uptodate, &r1_bio->state);
 			if (test_bit(R1BIO_WriteError, &r1_bio->state))
 				close_write(r1_bio);
 			raid_end_bio_io(r1_bio);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 68f42cad32a5..a65bd65ae7bd 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2942,6 +2942,14 @@ static void raid10d(struct md_thread *thread)
 						   retry_list);
 			list_del(&r10_bio->retry_list);
 
+			/*
+			 * If the array failed while this write was held, the
+			 * failed copy might not be recorded. Fail the write,
+			 * except for dm-raid.
+			 */
+			if (!mddev_is_dm(mddev) &&
+			    test_bit(MD_BROKEN, &mddev->flags))
+				clear_bit(R10BIO_Uptodate, &r10_bio->state);
 			if (test_bit(R10BIO_WriteError,
 				     &r10_bio->state))
 				close_write(r10_bio);
-- 
2.53.0


  reply	other threads:[~2026-11-27  0:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  0:32 [PATCH 0/8] md/raid1,raid10: fix writes acknowledged before a failure is recorded Miroslav Cimerman
2026-11-27  0:32 ` Miroslav Cimerman [this message]
2026-11-27  0:32 ` [PATCH 2/8] md/raid10: wait for the devices of the write in wait_blocked_dev() Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 3/8] md/raid1,raid10: fail writes that waited while the array failed Miroslav Cimerman
2026-11-29  6:31   ` yu kuai
2026-11-27  0:32 ` [PATCH 4/8] md/raid1,raid10: fail held writes that no working device has Miroslav Cimerman
2026-11-29  6:35   ` yu kuai
2026-11-27  0:32 ` [PATCH 5/8] md/raid1,raid10: hold writes that fail on a faulty device Miroslav Cimerman
2026-11-27  0:57   ` sashiko-bot
2026-11-27  0:32 ` [PATCH 6/8] md/raid1: set MD_SB_CHANGE_PENDING under device_lock in raid1_error() Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 7/8] md/raid1,raid10: hold writes that skip a newly failed device Miroslav Cimerman
2026-11-27  1:01   ` sashiko-bot
2026-11-27  0:32 ` [PATCH 8/8] md/raid1: hold write-behind writes that failed on a device Miroslav Cimerman
2026-11-29  6:45 ` [PATCH 0/8] md/raid1,raid10: fix writes acknowledged before a failure is recorded yu kuai
2026-11-29 20:07   ` Miroslav Cimerman

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=20261127003231.1180197-2-mc@raidlab.org \
    --to=mc@raidlab.org \
    --cc=k@mgml.me \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=mtkaczyk@kernel.org \
    --cc=neil@brown.name \
    --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 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.