mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Li Youhong" <dayou5941@163.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	Li Youhong <liyouhong@kylinos.cn>,
	stable@vger.kernel.org
Subject: [PATCH v2] md: fix stop_sync_thread() hang on new sync in idle path
Date: Fri, 13 Nov 2026 09:09:09 +0800	[thread overview]
Message-ID: <20261113010909.30324-1-dayou5941@163.com> (raw)

From: Li Youhong <liyouhong@kylinos.cn>

stop_sync_thread() waits for either MD_RECOVERY_RUNNING to be cleared,
or (when MD_RECOVERY_FROZEN is clear) for mddev->sync_seq to change.
The sync_seq counter is only incremented when a sync thread is reaped
in md_reap_sync_thread(), not on the md_start_sync() not_running path.

If the previous sync attempt took the not_running path, sync_seq does
not advance. If mddev->thread then queues and runs a new sync in the
window between flush_work() and wait_event(), that new sync may start
a real sync thread, leaving MD_RECOVERY_RUNNING set while sync_seq is
still unchanged. md_idle_sync_thread() then waits until that new sync
thread is reaped and sync_seq finally changes, even though it only
needs to wait for the current sync attempt to finish.

Fix this by incrementing sync_seq on the not_running path as well, so
that the wait condition correctly observes the current sync attempt has
completed.

Fixes: f52f5c71f3d4 ("md: fix stopping sync thread")
Cc: stable@vger.kernel.org
Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
---
v2: 
- Fix the Fixes: tag to reference the upstream commit f52f5c71f3d4
  instead of the stable backport a17d1bca5aba.
- v1: https://lore.kernel.org/all/20261112092634.1700963-1-dayou5941@163.com/

 drivers/md/md.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 68a72513e884..1970c945e597 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -10352,6 +10352,7 @@ static void md_start_sync(struct work_struct *ws)
 	clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
 	clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
 	clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
+	atomic_inc(&mddev->sync_seq);
 	mddev_unlock(mddev);
 	/*
 	 * md_start_sync was triggered by MD_RECOVERY_NEEDED, so we should
-- 
2.25.1


             reply	other threads:[~2026-11-13  1:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  1:09 Li Youhong [this message]
2026-11-21  4:00 ` yu kuai

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=20261113010909.30324-1-dayou5941@163.com \
    --to=dayou5941@163.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=liyouhong@kylinos.cn \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=xiao@kernel.org \
    --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

all inboxes | Powered by JetHome®