public inbox for linux-raid@vger.kernel.org
 help / color / mirror / Atom feed
From: "Yu Kuai" <yukuai@fnnas.com>
To: "Jiasheng Jiang" <jiashengjiangcool@gmail.com>,
	 "Song Liu" <song@kernel.org>, <yukuai@fnnas.com>
Cc: <linux-raid@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] md: fix hang in stop_sync_thread by setting THREAD_WAKEUP in md_wakeup_thread_directly
Date: Mon, 12 Jan 2026 00:12:48 +0800	[thread overview]
Message-ID: <dc64a750-1785-482a-964b-d1e590876bc2@fnnas.com> (raw)
In-Reply-To: <20260110221244.14304-1-jiashengjiangcool@gmail.com>

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

      reply	other threads:[~2026-01-11 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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=dc64a750-1785-482a-964b-d1e590876bc2@fnnas.com \
    --to=yukuai@fnnas.com \
    --cc=jiashengjiangcool@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    /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