From: Andrew Morton <akpm@linux-foundation.org>
To: Chen Yu <yu.c.chen@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Andreas Gruenbacher <agruenba@redhat.com>,
Tejun Heo <tj@kernel.org>, Shuah Khan <skhan@linuxfoundation.org>,
"Mickael Salaun" <mic@digikod.net>,
linux-kernel@vger.kernel.org, Chen Yu <yu.chen.surf@gmail.com>,
kernel test robot <oliver.sang@intel.com>
Subject: Re: [PATCH] kthread: fix task state in kthread worker if being frozen
Date: Mon, 19 Aug 2024 18:58:07 -0700 [thread overview]
Message-ID: <20240819185807.ff5004ade2661c46740fc459@linux-foundation.org> (raw)
In-Reply-To: <20240819141551.111610-1-yu.c.chen@intel.com>
On Mon, 19 Aug 2024 22:15:51 +0800 Chen Yu <yu.c.chen@intel.com> wrote:
> It was reported that during cpu hotplug test, the following
> error was triggered:
>
> do not call blocking ops when !TASK_RUNNING; state=1 set at kthread_worker_fn (kernel/kthread.c:?)
> WARNING: CPU: 1 PID: 674 at kernel/sched/core.c:8469 __might_sleep
>
> handle_bug
> exc_invalid_op
> asm_exc_invalid_op
> __might_sleep
> __might_sleep
> kthread_worker_fn
> kthread_worker_fn
> kthread
> __cfi_kthread_worker_fn
> ret_from_fork
> __cfi_kthread
> ret_from_fork_asm
>
> Peter pointed out that there is a race condition when the kworker is being
> frozen and falls into try_to_freeze() with TASK_INTERRUPTIBLE, which
> triggeres the warning.
OK. A full description of this race would be better than simply
asserting that it exists, please.
> Fix this by explicitly set the TASK_RUNNING before entering try_to_freeze().
OK.
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -848,6 +848,12 @@ int kthread_worker_fn(void *worker_ptr)
> } else if (!freezing(current))
> schedule();
>
> + /*
> + * Explicitly set the running state in case we are being
> + * frozen and skip the schedule() above. try_to_freeze()
> + * expects the current task to be in the running state.
> + */
> + __set_current_state(TASK_RUNNING);
> try_to_freeze();
> cond_resched();
> goto repeat;
Comment is helpful, but why express in a comment that which can be
expressed in code?
--- a/kernel/kthread.c~kthread-fix-task-state-in-kthread-worker-if-being-frozen
+++ a/kernel/kthread.c
@@ -847,6 +847,12 @@ repeat:
trace_sched_kthread_work_execute_end(work, func);
} else if (!freezing(current))
schedule();
+ } else {
+ /*
+ * Handle the case where X happens
+ */
+ __set_current_state(TASK_RUNNING);
+ }
try_to_freeze();
cond_resched();
_
next prev parent reply other threads:[~2024-08-20 1:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-19 14:15 Chen Yu
2024-08-20 1:58 ` Andrew Morton [this message]
2024-08-20 3:52 ` Chen Yu
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=20240819185807.ff5004ade2661c46740fc459@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=agruenba@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mic@digikod.net \
--cc=oliver.sang@intel.com \
--cc=peterz@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=tj@kernel.org \
--cc=yu.c.chen@intel.com \
--cc=yu.chen.surf@gmail.com \
/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®