Linux RAID subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miroslav Cimerman" <mc@raidlab.org>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH 5/8] md/raid1,raid10: hold writes that fail on a faulty device
Date: Fri, 27 Nov 2026 00:57:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-236382@kernel.org> (raw)
In-Reply-To: <20261127003231.1180197-6-mc@raidlab.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] md/raid10: unheld write and nr_pending leak when repl_bio
  fails
--

commit 13f36c8d107f279dd87814c77406033640b24af3
Author: Miroslav Cimerman <mc@raidlab.org>

md/raid1,raid10: hold writes that fail on a faulty device

This commit holds writes whose mirror copy fails on an already Faulty
device in raid1 and raid10 until the superblock records the failure, while
skipping narrow_write_error() retries on Faulty devices.

> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 838ae71205c1a..519b6ac0accd0 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -473,7 +473,6 @@ static void raid10_end_write_request(struct bio *bio)
>  	struct r10conf *conf = r10_bio->mddev->private;
>  	int slot, repl;
>  	struct md_rdev *rdev = NULL;
> -	struct bio *to_put = NULL;
>  	bool ignore_error = !raid1_should_handle_error(bio) ||
>  		(bio->bi_status && bio_op(bio) == REQ_OP_DISCARD);
>  
> @@ -505,17 +504,10 @@ static void raid10_end_write_request(struct bio *bio)
>  			}
>  
>  			/*
> -			 * When the device is faulty, it is not necessary to
> -			 * handle write error.
> +			 * Hold the write until the superblock records the
> +			 * failure, also on a Faulty device.
>  			 */
> -			if (!test_bit(Faulty, &rdev->flags))
> -				set_bit(R10BIO_WriteError, &r10_bio->state);
> -			else {
> -				/* Fail the request */
> -				r10_bio->devs[slot].bio = NULL;
> -				to_put = bio;
> -				dec_rdev = 1;
> -			}
> +			set_bit(R10BIO_WriteError, &r10_bio->state);
>  		}
>  	} else {
>  		/*
> @@ -560,8 +552,6 @@ static void raid10_end_write_request(struct bio *bio)
>  	one_write_done(r10_bio);
>  	if (dec_rdev)
>  		rdev_dec_pending(rdev, conf->mddev);
> -	if (to_put)
> -		bio_put(to_put);
>  }
>  
>  /*
> @@ -2926,7 +2916,9 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
>  				rdev_dec_pending(rdev, conf->mddev);
>  			} else if (bio != NULL && bio->bi_status) {
>  				fail = true;
> -				narrow_write_error(r10_bio, m);
> +				/* No retries on a Faulty device */
> +				if (!test_bit(Faulty, &rdev->flags))
> +					narrow_write_error(r10_bio, m);
>  				rdev_dec_pending(rdev, conf->mddev);
>  			}
>  			bio = r10_bio->devs[m].repl_bio;

[Severity: Medium]
Can a failing r10_bio->devs[slot].repl_bio complete without being held or
leak rdev->nr_pending?

In raid10_end_write_request(), if conf->mirrors[dev].replacement is still
present (repl == 1), a write failure only calls md_error() and never sets
R10BIO_WriteError, so the write completes immediately instead of waiting
for the superblock update.

If instead raid10_remove_disk() concurrently promotes p->replacement to
p->rdev and clears p->replacement while repl_bio is in flight,
raid10_end_write_request() falls back to repl = 0, sets dec_rdev = 0 and
R10BIO_WriteError (now even when the promoted device is Faulty):

drivers/md/raid10.c:raid10_end_write_request() {
	if (repl)
		rdev = conf->mirrors[dev].replacement;
	if (!rdev) {
		smp_rmb();
		repl = 0;
		rdev = conf->mirrors[dev].rdev;
	}
	if (bio->bi_status && !ignore_error) {
		if (repl)
			md_error(rdev->mddev, rdev);
		else {
			rdev_record_write_error(rdev);
			dec_rdev = 0;
			...
			set_bit(R10BIO_WriteError, &r10_bio->state);
		}
	}
}

Because the failed bio sits in r10_bio->devs[m].repl_bio rather than
r10_bio->devs[m].bio, handle_write_completed() never sees bio->bi_status on
it:

CPU0                              CPU1
raid10_remove_disk()
  WRITE_ONCE(p->rdev, p->replacement);
  WRITE_ONCE(p->replacement, NULL);
                                  raid10_end_write_request(repl_bio)
                                    rdev = conf->mirrors[dev].replacement;
                                    /* NULL -> repl = 0, rdev = p->rdev */
                                    dec_rdev = 0;
                                    set_bit(R10BIO_WriteError, ...);
                                  raid10d()
                                    handle_write_completed()
                                      bio = r10_bio->devs[m].bio;
                                      /* bio->bi_status == 0 */
                                      bio = r10_bio->devs[m].repl_bio;
                                      /* only IO_MADE_GOOD is checked */
                                      <-- rdev->nr_pending leaked,
                                          write not held

That permanently leaks rdev->nr_pending (preventing later disk removal) and
skips holding the write.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127003231.1180197-1-mc@raidlab.org?part=5

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

Thread overview: 11+ 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 ` [PATCH 1/8] md/raid1,raid10: fail held writes when the array fails Miroslav Cimerman
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-27  0:32 ` [PATCH 4/8] md/raid1,raid10: fail held writes that no working device has Miroslav Cimerman
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 [this message]
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

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=sashiko-outbox-236382@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mc@raidlab.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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