mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] md: fix hang in stop_sync_thread by setting THREAD_WAKEUP in md_wakeup_thread_directly
@ 2026-01-10 22:12 Jiasheng Jiang
  2026-01-11 16:12 ` Yu Kuai
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2026-01-10 22:12 UTC (permalink / raw)
  To: Song Liu, Yu Kuai; +Cc: linux-raid, linux-kernel, Jiasheng Jiang

Analysis of md.c shows that the md_thread() loop relies on the
THREAD_WAKEUP bit being set to progress beyond wait_event(). However,
md_wakeup_thread_directly() currently only calls wake_up_process()
without setting this bit.

As a result, a thread woken by md_wakeup_thread_directly() will find the
wait condition remains False and immediately return to sleep without
executing its run() handler. In the case of stop_sync_thread(), this
causes the sync thread to ignore the interruption request, leading to
a permanent hang.

Fix this by ensuring the THREAD_WAKEUP bit is set before waking the
process in md_wakeup_thread_directly().

Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/md/md.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 6d73f6e196a9..8709e9fd7f39 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -8512,8 +8512,10 @@ static void md_wakeup_thread_directly(struct md_thread __rcu **thread)
 
 	rcu_read_lock();
 	t = rcu_dereference(*thread);
-	if (t)
+	if (t) {
+		set_bit(THREAD_WAKEUP, &t->flags);
 		wake_up_process(t->tsk);
+	}
 	rcu_read_unlock();
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] md: fix hang in stop_sync_thread by setting THREAD_WAKEUP in md_wakeup_thread_directly
  2026-01-10 22:12 [PATCH] md: fix hang in stop_sync_thread by setting THREAD_WAKEUP in md_wakeup_thread_directly Jiasheng Jiang
@ 2026-01-11 16:12 ` Yu Kuai
  0 siblings, 0 replies; 2+ messages in thread
From: Yu Kuai @ 2026-01-11 16:12 UTC (permalink / raw)
  To: Jiasheng Jiang, Song Liu, yukuai; +Cc: linux-raid, linux-kernel

Hi,

在 2026/1/11 6:12, Jiasheng Jiang 写道:
> Analysis of md.c shows that the md_thread() loop relies on the
> THREAD_WAKEUP bit being set to progress beyond wait_event(). However,
> md_wakeup_thread_directly() currently only calls wake_up_process()
> without setting this bit.
>
> As a result, a thread woken by md_wakeup_thread_directly() will find the
> wait condition remains False and immediately return to sleep without
> executing its run() handler. In the case of stop_sync_thread(), this
> causes the sync thread to ignore the interruption request, leading to
> a permanent hang.

This doesn't look correct, md_wakeup_thread_directly() is not used in the
case to start a new md_do_sync() as you described. It's used in the case
that md_do_sync() is already running and stuck somewhere and could be
interrupted by setting MD_RECOVERY_INTR.

>
> Fix this by ensuring the THREAD_WAKEUP bit is set before waking the
> process in md_wakeup_thread_directly().
>
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
>   drivers/md/md.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 6d73f6e196a9..8709e9fd7f39 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -8512,8 +8512,10 @@ static void md_wakeup_thread_directly(struct md_thread __rcu **thread)
>   
>   	rcu_read_lock();
>   	t = rcu_dereference(*thread);
> -	if (t)
> +	if (t) {
> +		set_bit(THREAD_WAKEUP, &t->flags);
>   		wake_up_process(t->tsk);
> +	}
>   	rcu_read_unlock();
>   }
>   

-- 
Thansk,
Kuai

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-11 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-10 22:12 [PATCH] md: fix hang in stop_sync_thread by setting THREAD_WAKEUP in md_wakeup_thread_directly Jiasheng Jiang
2026-01-11 16:12 ` Yu Kuai

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®