All of lore.kernel.org
 help / color / mirror / Atom feed
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 4/8] md: defer the io_opt update out of the sync thread
Date: Thu, 10 Sep 2026 08:37:20 +0000	[thread overview]
Message-ID: <20260910083720.B635D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910081114.1605746-5-jinpu.wang@ionos.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ABBA/4-thread deadlock in __md_stop() when synchronously flushing io_opt_work while holding reconfig_mutex.
--

commit d238224db360133630dc01a16a121d6c63417309
Author: Jack Wang <jinpu.wang@cloud.ionos.com>

md: defer the io_opt update out of the sync thread

This patch defers the mddev_update_io_opt() call from the sync thread into a
work item to avoid hanging a finishing reshape when taking q->limits_lock.
The __md_stop() function is updated to flush this work item during array
suspension.

> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 3067ea05ba276..87e17ba86d93a 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c

[ ... ]

> @@ -7139,6 +7172,8 @@ static void __md_stop(struct mddev *mddev)
>  {
>  	struct md_personality *pers = mddev->pers;
>  
> +	/* the deferred io_opt update suspends the array, so let it finish */
> +	flush_work(&mddev->io_opt_work);

[Severity: High]
Can this flush_work() call lead to a deadlock when the array is stopped while
I/O is active?

The array stop sequence holds reconfig_mutex while calling __md_stop(), which
blocks here waiting for md_io_opt_work() to complete.

Meanwhile, md_io_opt_work() calls mddev_suspend(), which blocks indefinitely
waiting for the active_io refcount to drop to zero:

drivers/md/md.c:md_io_opt_work() {
    ...
	lim = queue_limits_start_update(q);
	if (mddev_suspend(mddev, false) < 0) {
    ...
}

However, a concurrent write I/O can increment active_io and then block in
md_write_start() waiting for the MD management thread to clear
MD_SB_CHANGE_PENDING:

drivers/md/md.c:md_write_start() {
    ...
	wait_event(mddev->sb_wait,
		   !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags));
    ...
}

The MD management thread cannot clear this flag because it wakes up to update
the superblock but fails to acquire reconfig_mutex:

drivers/md/md.c:md_check_recovery() {
    ...
	if (mddev_trylock(mddev)) {
    ...
}

Since the array stop sequence holds reconfig_mutex, this creates a 4-thread
circular dependency:

1. array stop thread waits for md_io_opt_work() to complete
2. md_io_opt_work() thread waits for active_io to reach zero
3. write I/O holding active_io waits for MD thread to clear
   MD_SB_CHANGE_PENDING
4. MD thread waits for array stop thread to release reconfig_mutex

Does the flush_work() call need to be moved outside the section holding
reconfig_mutex, or could the workqueue be drained earlier?

>  	mddev_detach(mddev);
>  	md_bitmap_destroy(mddev);
>  	spin_lock(&mddev->lock);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910081114.1605746-1-jinpu.wang@ionos.com?part=4

  reply	other threads:[~2026-09-10  8:37 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 [this message]
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
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=20260910083720.B635D1F000FF@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 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.