From: sashiko-bot@kernel.org
To: "Thanh Nguyen" <thanhnguyentuan2007@gmail.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH v2] md: flush running sync_work in stop_sync_thread()
Date: Wed, 02 Dec 2026 04:33:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-244847@kernel.org> (raw)
In-Reply-To: <20261202041327.616-1-thanhnguyentuan2007@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] md: stop_sync_thread() retry interrupts new sync in
md_idle_sync_thread()
--
commit 71abb1be4745952743263f8a77a5e5ef3f06af23
Author: Thanh Nguyen <thanhnguyentuan2007@gmail.com>
md: flush running sync_work in stop_sync_thread()
This commit updates stop_sync_thread() to check work_busy() instead of
work_pending(), flush mddev->sync_work even when MD_RECOVERY_RUNNING is
already cleared, and retry after re-acquiring reconfig_mutex if a new
sync_work was queued while unlocked.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 47da9edc1c606..6be40840b8499 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -5210,10 +5210,16 @@ static void stop_sync_thread(struct mddev *mddev, bool locked)
> {
> int sync_seq = atomic_read(&mddev->sync_seq);
>
> +retry:
> if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
> - if (!locked)
> - mddev_unlock(mddev);
> - return;
> + if (!work_busy(&mddev->sync_work)) {
> + if (!locked)
> + mddev_unlock(mddev);
> + return;
> + }
> + mddev_unlock(mddev);
> + flush_work(&mddev->sync_work);
> + goto relock;
> }
>
> mddev_unlock(mddev);
> @@ -5224,7 +5230,7 @@ static void stop_sync_thread(struct mddev *mddev, bool locked)
> * never happen
> */
> md_wakeup_thread_directly(&mddev->sync_thread);
> - if (work_pending(&mddev->sync_work))
> + if (work_busy(&mddev->sync_work))
> flush_work(&mddev->sync_work);
>
> wait_event(resync_wait,
> @@ -5232,8 +5238,14 @@ static void stop_sync_thread(struct mddev *mddev, bool locked)
> (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery) &&
> sync_seq != atomic_read(&mddev->sync_seq)));
>
> - if (locked)
> +relock:
> + if (locked) {
> mddev_lock_nointr(mddev);
> + if (work_busy(&mddev->sync_work) ||
> + (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery) &&
> + test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)))
> + goto retry;
> + }
> }
>
> void md_idle_sync_thread(struct mddev *mddev)
[Severity: Medium]
When called from md_idle_sync_thread(), can the unconditional
work_busy(&mddev->sync_work) check at relock cause stop_sync_thread() to
abort the newly started sync cycle and return while it is still running?
md_idle_sync_thread() clears MD_RECOVERY_FROZEN to stop the current sync
thread while allowing a subsequent sync operation to start. Once the first
sync thread is reaped, mddev->thread can queue mddev->sync_work for the
next sync cycle before stop_sync_thread() re-acquires reconfig_mutex:
CPU0 (md_idle_sync_thread) CPU1 (mddev->thread)
stop_sync_thread(mddev, true)
sync_seq = atomic_read(...)
mddev_unlock(mddev)
set_bit(MD_RECOVERY_INTR, ...)
wait_event(resync_wait, ...)
md_check_recovery()
md_reap_sync_thread()
atomic_inc(&mddev->sync_seq)
clear_bit(MD_RECOVERY_RUNNING, ...)
set_bit(MD_RECOVERY_NEEDED, ...)
wake_up(&resync_wait)
mddev_unlock(mddev)
md_check_recovery()
set_bit(MD_RECOVERY_RUNNING, ...)
clear_bit(MD_RECOVERY_INTR, ...)
queue_work(..., &mddev->sync_work)
mddev_lock_nointr(mddev)
work_busy(&mddev->sync_work)
goto retry
mddev_unlock(mddev)
set_bit(MD_RECOVERY_INTR, ...) <-- aborts the new sync cycle
flush_work(&mddev->sync_work)
wait_event(resync_wait, ...) <-- sync_seq != mddev->sync_seq is
already true; returns immediately
Because sync_seq is sampled before the retry label and never refreshed,
wait_event() does not wait for the newly interrupted sync thread to exit,
leaving MD_RECOVERY_RUNNING set when md_idle_sync_thread() returns (causing
callers such as dm-raid's raid_message() to fail with -EBUSY).
Should the retry at relock skip work_busy(&mddev->sync_work) when
!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery) and sync_seq has already
advanced?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202041327.616-1-thanhnguyentuan2007@gmail.com?part=1
prev parent reply other threads:[~2026-12-02 4:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 8:41 [PATCH] md: flush running sync_work in stop_sync_thread() Thanh Nguyen
2026-12-01 8:58 ` sashiko-bot
2026-12-02 4:13 ` [PATCH v2] " Thanh Nguyen
2026-12-02 4:33 ` 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-244847@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=thanhnguyentuan2007@gmail.com \
--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