[lkml]   [2019]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: Workqueues splat due to ending up on wrong CPU
On Mon, Dec 09, 2019 at 10:59:08AM -0800, Paul E. McKenney wrote:
> And it survived! ;-)
> Peter, could I please have your Signed-off-by? Or take my Tested-by if
> you would prefer to send it up some other way.

How's this?

Subject: cpu/hotplug, stop_machine: Fix stop_machine vs hotplug order
From: Peter Zijlstra <>
Date: Tue Dec 10 09:34:54 CET 2019

Paul reported a very sporadic, rcutorture induced, workqueue failure.
When the planets align, the workqueue rescuer's self-migrate fails and
then triggers a WARN for running a work on the wrong CPU.

Tejun then figured that set_cpus_allowed_ptr()'s stop_one_cpu() call
could be ignored! When stopper->enabled is false, stop_machine will
insta complete the work, without actually doing the work. Worse, it
will not WARN about this (we really should fix this).

It turns out there is a small window where a freshly online'ed CPU is
marked 'online' but doesn't yet have the stopper task running:


__cpu_up(cpu, idle) --> start_secondary()
wait_for_ap_thread() <-- cpuhp_online_idle()
while (1)

... available to run kthreads ...

stopper->enable = true;

Close this by moving the stop_machine_unpark() into
cpuhp_online_idle(), such that the stopper thread is ready before we
start the idle loop and schedule.

Reported-by: "Paul E. McKenney" <>
Debugged-by: Tejun Heo <>
Signed-off-by: Peter Zijlstra (Intel) <>
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -525,8 +525,7 @@ static int bringup_wait_for_ap(unsigned
if (WARN_ON_ONCE((!cpu_online(cpu))))
return -ECANCELED;

- /* Unpark the stopper thread and the hotplug thread of the target cpu */
- stop_machine_unpark(cpu);
+ /* Unpark the hotplug thread of the target cpu */

@@ -1089,8 +1088,8 @@ void notify_cpu_starting(unsigned int cp

* Called from the idle task. Wake up the controlling task which brings the
- * stopper and the hotplug thread of the upcoming CPU up and then delegates
- * the rest of the online bringup to the hotplug thread.
+ * hotplug thread of the upcoming CPU up and then delegates the rest of the
+ * online bringup to the hotplug thread.
void cpuhp_online_idle(enum cpuhp_state state)
@@ -1100,6 +1099,12 @@ void cpuhp_online_idle(enum cpuhp_state
if (state != CPUHP_AP_ONLINE_IDLE)

+ /*
+ * Unpart the stopper thread before we start the idle loop (and start
+ * scheduling); this ensures the stopper task is always available.
+ */
+ stop_machine_unpark(smp_processor_id());
complete_ap_thread(st, true);
 \ /
  Last update: 2019-12-10 10:09    [W:0.141 / U:1.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site