mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: zhanghao <zh_exit@163.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, zhanghao <zh_exit@163.com>
Subject: [PATCH v2] md/raid5: fix inverted condition in rdev_set_badblocks call
Date: Sat, 17 Oct 2026 16:37:37 +0800	[thread overview]
Message-ID: <20261017083737.61793-1-zh_exit@163.com> (raw)
In-Reply-To: <20261017074343.59513-1-zh_exit@163.com>

Commit fd4d44c14ff6 ("md: mark rdev Faulty when badblocks setting fails")
attempted to unify badblock handling but introduced a logic inversion in
raid5_end_read_request().

The original check was:

    if (!(set_bad && In_sync && rdev_set_badblocks(...)))
            md_error(...);

which records badblocks when `set_bad && In_sync`, and calls md_error()
either when recording fails or when the rdev is not In_sync. The new
condition `if (!(set_bad && In_sync))` skips rdev_set_badblocks() exactly
during recovery/reshape (In_sync is set), so failed badblock updates no
longer trigger md_error() and the rdev is not marked Faulty. This allows
reconstruction to continue on a disk with a saturated badblock table,
potentially propagating corrupted data to the replacement disk.

Restore the intended behavior by recording badblocks when `set_bad &&
In_sync`, and calling md_error() in the else branch so that non-In_sync
rdevs, replacement devices, and the too-many-read-errors path are still
marked Faulty.

Fixes: fd4d44c14ff6 ("md: mark rdev Faulty when badblocks setting fails")
Cc: stable@vger.kernel.org
Signed-off-by: zhanghao <zh_exit@163.com>
---
v2:
- Add the else branch calling md_error() for the !(set_bad && In_sync)
  cases, as pointed out by Sashiko: replacement device read errors,
  the too-many-read-errors path, and non-In_sync uncorrectable reads
  would otherwise no longer mark the rdev Faulty.

 drivers/md/raid5.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d52adf81065a..25395a9c996a 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2866,9 +2866,11 @@ static void raid5_end_read_request(struct bio * bi)
 		else {
 			clear_bit(R5_ReadError, &sh->dev[i].flags);
 			clear_bit(R5_ReWrite, &sh->dev[i].flags);
-			if (!(set_bad && test_bit(In_sync, &rdev->flags)))
+			if (set_bad && test_bit(In_sync, &rdev->flags))
 				rdev_set_badblocks(rdev, sh->sector,
 						   RAID5_STRIPE_SECTORS(conf), 0);
+			else
+				md_error(conf->mddev, rdev);
 		}
 	}
 	rdev_dec_pending(rdev, conf->mddev);
-- 
2.43.0


      reply	other threads:[~2026-10-17  8:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17  7:43 [PATCH] " zhanghao
2026-10-17  8:37 ` zhanghao [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=20261017083737.61793-1-zh_exit@163.com \
    --to=zh_exit@163.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®