md: fix stop_sync_thread() hang on new sync in idle path
Subsystems (2)
PATCH v2 1/1 md: fix stop_sync_thread() hang on new sync in idle path
From: Li Youhong <[email protected]>
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.
---
v2:
- Fix the Fixes: tag to reference the upstream commit f52f5c71f3d4 instead of the stable backport a17d1bca5aba.
- v1: https://lore.kernel.org/all/[email protected]/
drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/md.c +1 -0
@@ -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
Signature · 1 line
2.25.1
Quoted 22 lines · Li Youhong
From: Li Youhong<[email protected]>
stop_sync_thread()waits for eitherMD_RECOVERY_RUNNINGto be cleared, or (whenMD_RECOVERY_FROZENis clear) formddev->sync_seqto change. Thesync_seqcounter is only incremented when a sync thread is reaped inmd_reap_sync_thread(), not on themd_start_sync()not_runningpath.If the previous sync attempt took the
not_runningpath,sync_seqdoes not advance. Ifmddev->threadthen queues and runs a new sync in the window betweenflush_work()andwait_event(), that new sync may start a real sync thread, leavingMD_RECOVERY_RUNNINGset whilesync_seqis still unchanged.md_idle_sync_thread()then waits until that new sync thread is reaped andsync_seqfinally changes, even though it only needs to wait for the current sync attempt to finish.Fix this by incrementing
sync_seqon thenot_runningpath as well, so that the wait condition correctly observes the current sync attempt has completed.Fixes f52f5c71f3d4 ("md: fix stopping sync thread")Signed-off-by Li Youhong<[email protected]>
Quoted 8 lines
---
v2:
- Fix the Fixes: tag to reference the upstream commitf52f5c71f3d4instead of the stable backporta17d1bca5aba.
- v1:https://lore.kernel.org/all/[email protected]/drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)
Applied
Signature · 2 lines
Thanks, Kuai