Skip to content

Commit 45178ac

Browse files
author
Peter Zijlstra
committed
cpu/hotplug, stop_machine: Fix stop_machine vs hotplug order
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: BP AP bringup_cpu() __cpu_up(cpu, idle) --> start_secondary() ... cpu_startup_entry() bringup_wait_for_ap() wait_for_ap_thread() <-- cpuhp_online_idle() while (1) do_idle() ... available to run kthreads ... stop_machine_unpark() 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" <paulmck@kernel.org> Debugged-by: Tejun Heo <tj@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: "Paul E. McKenney" <paulmck@kernel.org>
1 parent cde6519 commit 45178ac

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎kernel/cpu.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,7 @@ static int bringup_wait_for_ap(unsigned int cpu)
525525
if (WARN_ON_ONCE((!cpu_online(cpu))))
526526
return -ECANCELED;
527527

528-
/* Unpark the stopper thread and the hotplug thread of the target cpu */
529-
stop_machine_unpark(cpu);
528+
/* Unpark the hotplug thread of the target cpu */
530529
kthread_unpark(st->thread);
531530

532531
/*
@@ -1089,8 +1088,8 @@ void notify_cpu_starting(unsigned int cpu)
10891088

10901089
/*
10911090
* Called from the idle task. Wake up the controlling task which brings the
1092-
* stopper and the hotplug thread of the upcoming CPU up and then delegates
1093-
* the rest of the online bringup to the hotplug thread.
1091+
* hotplug thread of the upcoming CPU up and then delegates the rest of the
1092+
* online bringup to the hotplug thread.
10941093
*/
10951094
void cpuhp_online_idle(enum cpuhp_state state)
10961095
{
@@ -1100,6 +1099,12 @@ void cpuhp_online_idle(enum cpuhp_state state)
11001099
if (state != CPUHP_AP_ONLINE_IDLE)
11011100
return;
11021101

1102+
/*
1103+
* Unpart the stopper thread before we start the idle loop (and start
1104+
* scheduling); this ensures the stopper task is always available.
1105+
*/
1106+
stop_machine_unpark(smp_processor_id());
1107+
11031108
st->state = CPUHP_AP_ONLINE_IDLE;
11041109
complete_ap_thread(st, true);
11051110
}

0 commit comments

Comments
 (0)