All of lore.kernel.org
 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] md/raid10: don't take a recovering member as the resync source
Date: Sat, 05 Dec 2026 19:29:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-251859@kernel.org> (raw)
In-Reply-To: <20261205190740.1519480-1-mc@raidlab.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] md/raid10: sync_request_write() lacks Faulty check after
  sync_copy_valid()
- [Low] md/raid10: data race on rdev->recovery_offset in
  sync_copy_valid()
--

commit 722f3c309b30c64a76fdb814b1a1c2ccb688d55e
Author: Miroslav Cimerman <mc@raidlab.org>

md/raid10: don't take a recovering member as the resync source

This commit adds sync_copy_valid() to prevent RAID10 resync from using
data above recovery_offset on a non-In_sync member as the resync source
and to overwrite such copies with the valid source.

> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 68f42cad32a59..2139c7030bfef 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -2292,6 +2292,19 @@ static void end_sync_write(struct bio *bio)
>  	end_sync_request(r10_bio);
>  }
>  
> +/*
> + * A member that is not In_sync holds valid data only below its
> + * recovery_offset, see read_balance().
> + */
> +static bool sync_copy_valid(struct r10conf *conf, struct r10bio *r10_bio,
> +			    int i)
> +{
> +	struct md_rdev *rdev = conf->mirrors[r10_bio->devs[i].devnum].rdev;
> +	sector_t end = r10_bio->devs[i].addr + r10_bio->sectors;
> +
> +	return test_bit(In_sync, &rdev->flags) || end <= rdev->recovery_offset;
> +}

[Severity: Low]
Can this plain read of rdev->recovery_offset race with md_reload_sb() on
clustered RAID10 arrays?

raid10d() calls sync_request_write() without holding mddev->reconfig_mutex.
On a clustered RAID10 near array, recv_daemon() can concurrently handle a
METADATA_UPDATED message and reload the superblock for non-Faulty members
with MD_FEATURE_RECOVERY_OFFSET set:

CPU0 (raid10d)                    CPU1 (recv_daemon)
sync_request_write()              process_metadata_update()
  sync_copy_valid()                 mddev_trylock(mddev)
                                    md_reload_sb()
                                      read_rdev()
    read rdev->recovery_offset          rdev->recovery_offset = ...
      <-- data race

While the resyncing node holds resync_lockres, read_rdev() normally writes
the same value, causing a data race under CONFIG_KCSAN_STRICT.  If a peer
broadcasts a stale recovery_offset, a 32-bit kernel can also observe a torn
64-bit load.

[ ... ]

> @@ -2349,7 +2363,15 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
>  		tpages = get_resync_pages(tbio)->pages;
>  		d = r10_bio->devs[i].devnum;
>  		rdev = conf->mirrors[d].rdev;
> -		if (!r10_bio->devs[i].bio->bi_status) {
> +		if (!r10_bio->devs[i].bio->bi_status &&
> +		    !sync_copy_valid(conf, r10_bio, i)) {
> +			/*
> +			 * Not recovered yet: don't compare, write the source
> +			 * to it, unless this is a check.
> +			 */
> +			if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
> +				continue;
> +		} else if (!r10_bio->devs[i].bio->bi_status) {

[Severity: Medium]
Can this submit write bios to a disk that has just been marked Faulty?

Assembled In_sync members keep rdev->recovery_offset at 0.  If a disk fails
while resync r10_bios are in flight or queued on conf->retry_list (for
example via raid10_error() from an I/O error or mdadm --fail), raid10_error()
clears In_sync and sets Faulty while leaving recovery_offset at 0:

CPU0 (raid10d)                    CPU1
                                  raid10_error()
                                    clear_bit(In_sync, &rdev->flags)
                                    set_bit(Faulty, &rdev->flags)
sync_request_write()
  !sync_copy_valid() -> true
  submit_bio_noacct(tbio)  <-- writes to Faulty disk

For every remaining r10_bio whose read on that disk succeeded,
sync_copy_valid() now returns false even when the data matches, so this
branch skips memcmp() and falls through to submit REQ_OP_WRITE bios to the
Faulty disk.  That mutates the failed device, keeps rdev->nr_pending and
mddev->recovery_active elevated while draining, and can spuriously record
write errors in end_sync_write().

Checking test_bit(Faulty, &rdev->flags) before writing (as raid1's
sync_request_write() does) would avoid issuing writes to a failed member.

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

      reply	other threads:[~2026-12-05 19:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 19:07 [PATCH] md/raid10: don't take a recovering member as the resync source Miroslav Cimerman
2026-12-05 19:29 ` sashiko-bot [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=sashiko-outbox-251859@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 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.