From: sashiko-bot@kernel.org
To: "Jack Wang" <jinpu.wang@ionos.com>
Cc: yukuai@fygo.io, linux-raid@vger.kernel.org
Subject: Re: [PATCH v2 7/8] md: open new legs before locking the array
Date: Thu, 10 Sep 2026 08:48:15 +0000 [thread overview]
Message-ID: <20260910084816.3CFE81F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910081114.1605746-8-jinpu.wang@ionos.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The patch leaves export_rdev() calls inside the mddev->reconfig_mutex critical section on error paths, failing to completely break the disk->open_mutex deadlock cycle.
- [Medium] The snapshot check in md_add_new_disk() is bypassed when nd->rdev is NULL, allowing concurrent array reconfigurations to trigger a WARN_ON_ONCE.
--
commit 140222a8600d2514747d88643188f131c16b6c50
Author: Jack Wang <jinpu.wang@cloud.ionos.com>
md: open new legs before locking the array
This commit aims to resolve a lockdep cycle between disk->open_mutex and
mddev->reconfig_mutex by opening new devices before acquiring the array
lock. It updates functions like md_import_new_disk() and new_dev_store()
to snapshot configuration and validate it after locking.
> diff --git a/drivers/md/md-autodetect.c b/drivers/md/md-autodetect.c
> index e15ae2fb58a2d..e592577356ad3 100644
> --- a/drivers/md/md-autodetect.c
> +++ b/drivers/md/md-autodetect.c
> @@ -216,7 +217,21 @@ static void __init md_setup_drive(struct md_setup_args *args)
> (1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC);
> }
>
> - md_add_new_disk(mddev, &dinfo, NULL);
> + /*
> + * Opening a leg takes disk->open_mutex, which must not nest
> + * inside reconfig_mutex, see md_import_new_disk(). Drop the
> + * array lock around it; this is __init and the array is not
> + * reachable yet, so nothing else can touch it in between.
> + */
> + mddev_unlock(mddev);
> + if (md_import_new_disk(mddev, &dinfo, &nd)) {
> + mddev_lock_nointr(mddev);
> + continue;
> + }
> + mddev_lock_nointr(mddev);
> +
> + md_add_new_disk(mddev, &dinfo, &nd, NULL);
> + md_put_new_disk(&nd);
[Severity: High]
Does md_put_new_disk() recreate the lockdep cycle we are trying to fix?
Since md_put_new_disk() calls export_rdev() internally, and export_rdev()
acquires disk->open_mutex, calling it here while mddev_lock_nointr() is
held appears to preserve the reconfig_mutex -> disk->open_mutex lock order.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 5be956e80563d..fa033d7d38318 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
[ ... ]
> @@ -7685,12 +7706,35 @@ static int get_disk_info(struct mddev *mddev, void __user * arg)
> return 0;
> }
>
> +/*
> + * @nd carries an rdev the caller opened before locking the array, for the
> + * branch its snapshot selected. Every caller must open first; doing it
> + * here would nest disk->open_mutex inside reconfig_mutex.
> + */
> int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info,
> - struct queue_limits *lim)
> + struct md_new_disk *nd, struct queue_limits *lim)
> {
> struct md_rdev *rdev;
> dev_t dev = MKDEV(info->major,info->minor);
>
> + /*
> + * The open ran unlocked, so anything that selects a different branch
> + * below, or a different superblock format, means it was done against
> + * an array that no longer looks like this one.
> + */
> + if (nd && nd->rdev &&
> + (nd->have_raid_disks != (mddev->raid_disks != 0) ||
> + nd->have_pers != !!mddev->pers ||
> + nd->persistent != mddev->persistent ||
> + nd->major_version != mddev->major_version ||
> + nd->minor_version != mddev->minor_version)) {
[Severity: Medium]
Is this validation check bypassed if nd->rdev is NULL?
If md_import_new_disk() is called on an array where ADD_NEW_DISK is
unsupported (for example, raid_disks != 0 and pers == NULL), it returns 0
with nd->rdev = NULL. If a concurrent ioctl like STOP_ARRAY resets
raid_disks to 0 before md_add_new_disk() acquires the lock, the condition
checking nd->rdev evaluates to false, skipping the validation entirely.
This allows the function to proceed into the !mddev->raid_disks branch
and hit the WARN_ON_ONCE(!nd || !nd->rdev) below, triggering a kernel splat.
> + pr_warn("%s: array reconfigured while opening %pg\n",
> + mdname(mddev), nd->rdev->bdev);
> + export_rdev(nd->rdev);
> + nd->rdev = NULL;
> + return -EBUSY;
> + }
[Severity: High]
This new failure path also executes with reconfig_mutex held, directly
calling export_rdev() and recreating the lockdep cycle.
Could this leave the system vulnerable to the same deadlock on error paths?
This pattern also occurs in new_dev_store(), where the error path calls
export_rdev() before mddev_unlock_and_resume().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910081114.1605746-1-jinpu.wang@ionos.com?part=7
next prev parent reply other threads:[~2026-09-10 8:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 8:11 [PATCH v2 0/8] md: don't wait for q->limits_lock while md holds back I/O Jack Wang
2026-09-10 8:11 ` [PATCH v2 1/8] md: pass a queue_limits down to ->hot_add_disk() Jack Wang
2026-09-10 8:31 ` sashiko-bot
2026-09-11 10:46 ` Nilay Shroff
2026-09-10 8:11 ` [PATCH v2 2/8] md: don't wait for q->limits_lock in check_sb_changes() Jack Wang
2026-09-10 8:36 ` sashiko-bot
2026-09-10 8:11 ` [PATCH v2 3/8] md: pass a queue_limits through the rdev sysfs stores Jack Wang
2026-09-10 8:11 ` [PATCH v2 4/8] md: defer the io_opt update out of the sync thread Jack Wang
2026-09-10 8:37 ` sashiko-bot
2026-09-10 8:11 ` [PATCH v2 5/8] md: take q->limits_lock before locking and suspending the array Jack Wang
2026-09-10 8:51 ` sashiko-bot
2026-09-10 8:11 ` [PATCH v2 6/8] md: pass a queue_limits through ->run() Jack Wang
2026-09-10 8:49 ` sashiko-bot
2026-09-11 10:54 ` Nilay Shroff
2026-09-10 8:11 ` [PATCH v2 7/8] md: open new legs before locking the array Jack Wang
2026-09-10 8:48 ` sashiko-bot [this message]
2026-09-10 8:11 ` [PATCH v2 8/8] md: link a new leg's holder " Jack Wang
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=20260910084816.3CFE81F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jinpu.wang@ionos.com \
--cc=linux-raid@vger.kernel.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