* [PATCH] md: fix stop_sync_thread() hang on new sync in idle path
@ 2026-11-12 9:26 Li Youhong
2026-11-12 9:35 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Li Youhong @ 2026-11-12 9:26 UTC (permalink / raw)
To: song, yukuai
Cc: magiclinan, xiao, linux-raid, linux-kernel, Li Youhong, stable
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: a17d1bca5aba ("md: fix stopping sync thread")
Cc: stable@vger.kernel.org
Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] md: fix stop_sync_thread() hang on new sync in idle path
2026-11-12 9:26 [PATCH] md: fix stop_sync_thread() hang on new sync in idle path Li Youhong
@ 2026-11-12 9:35 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-12 9:35 UTC (permalink / raw)
To: Li Youhong; +Cc: linux-raid, yukuai
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] md: Fixes trailer references stable backport SHA instead of
mainline SHA
--
commit 5befe56f6aae61b7aa7d4c1baac50a35a4c54849
Author: Li Youhong <liyouhong@kylinos.cn>
> md: fix stop_sync_thread() hang on new sync in idle path
>
> 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: a17d1bca5aba ("md: fix stopping sync thread")
> Cc: stable@vger.kernel.org
> Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
[Severity: Low]
a17d1bca5aba ("md: fix stopping sync thread") is a stable-tree backport
rather than the mainline commit in the branch history. Should the Fixes:
tag reference the upstream commit instead:
Fixes: f52f5c71f3d4 ("md: fix stopping sync thread")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112092634.1700963-1-dayou5941@163.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-12 9:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 9:26 [PATCH] md: fix stop_sync_thread() hang on new sync in idle path Li Youhong
2026-11-12 9:35 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox