Skip to content

Commit 5ebe774

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
smp/hotplug: Differentiate the AP completion between up and down
With lockdep-crossrelease we get deadlock reports that span cpu-up and cpu-down chains. Such deadlocks cannot possibly happen because cpu-up and cpu-down are globally serialized. takedown_cpu() irq_lock_sparse() wait_for_completion(&st->done) cpuhp_thread_fun cpuhp_up_callback cpuhp_invoke_callback irq_affinity_online_cpu irq_local_spare() irq_unlock_sparse() complete(&st->done) Now that we have consistent AP state, we can trivially separate the AP completion between up and down using st->bringup. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 5f4b55e commit 5ebe774

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

kernel/cpu.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
* @bringup: Single callback bringup or teardown selector
4747
* @cb_state: The state for a single callback (install/uninstall)
4848
* @result: Result of the operation
49-
* @done: Signal completion to the issuer of the task
49+
* @done_up: Signal completion to the issuer of the task for cpu-up
50+
* @done_down: Signal completion to the issuer of the task for cpu-down
5051
*/
5152
struct cpuhp_cpu_state {
5253
enum cpuhp_state state;
@@ -61,7 +62,8 @@ struct cpuhp_cpu_state {
6162
struct hlist_node *last;
6263
enum cpuhp_state cb_state;
6364
int result;
64-
struct completion done;
65+
struct completion done_up;
66+
struct completion done_down;
6567
#endif
6668
};
6769

@@ -130,14 +132,6 @@ static bool cpuhp_is_ap_state(enum cpuhp_state state)
130132
return state > CPUHP_BRINGUP_CPU && state != CPUHP_TEARDOWN_CPU;
131133
}
132134

133-
/*
134-
* The former STARTING/DYING states, ran with IRQs disabled and must not fail.
135-
*/
136-
static bool cpuhp_is_atomic_state(enum cpuhp_state state)
137-
{
138-
return CPUHP_AP_IDLE_DEAD <= state && state < CPUHP_AP_ONLINE;
139-
}
140-
141135
static struct cpuhp_step *cpuhp_get_step(enum cpuhp_state state)
142136
{
143137
struct cpuhp_step *sp;
@@ -232,6 +226,26 @@ static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state,
232226
}
233227

234228
#ifdef CONFIG_SMP
229+
static inline void wait_for_ap_thread(struct cpuhp_cpu_state *st, bool bringup)
230+
{
231+
struct completion *done = bringup ? &st->done_up : &st->done_down;
232+
wait_for_completion(done);
233+
}
234+
235+
static inline void complete_ap_thread(struct cpuhp_cpu_state *st, bool bringup)
236+
{
237+
struct completion *done = bringup ? &st->done_up : &st->done_down;
238+
complete(done);
239+
}
240+
241+
/*
242+
* The former STARTING/DYING states, ran with IRQs disabled and must not fail.
243+
*/
244+
static bool cpuhp_is_atomic_state(enum cpuhp_state state)
245+
{
246+
return CPUHP_AP_IDLE_DEAD <= state && state < CPUHP_AP_ONLINE;
247+
}
248+
235249
/* Serializes the updates to cpu_online_mask, cpu_present_mask */
236250
static DEFINE_MUTEX(cpu_add_remove_lock);
237251
bool cpuhp_tasks_frozen;
@@ -368,7 +382,7 @@ static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st)
368382
smp_mb();
369383
st->should_run = true;
370384
wake_up_process(st->thread);
371-
wait_for_completion(&st->done);
385+
wait_for_ap_thread(st, st->bringup);
372386
}
373387

374388
static int cpuhp_kick_ap(struct cpuhp_cpu_state *st, enum cpuhp_state target)
@@ -391,7 +405,7 @@ static int bringup_wait_for_ap(unsigned int cpu)
391405
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
392406

393407
/* Wait for the CPU to reach CPUHP_AP_ONLINE_IDLE */
394-
wait_for_completion(&st->done);
408+
wait_for_ap_thread(st, true);
395409
if (WARN_ON_ONCE((!cpu_online(cpu))))
396410
return -ECANCELED;
397411

@@ -464,7 +478,8 @@ static void cpuhp_create(unsigned int cpu)
464478
{
465479
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
466480

467-
init_completion(&st->done);
481+
init_completion(&st->done_up);
482+
init_completion(&st->done_down);
468483
}
469484

470485
static int cpuhp_should_run(unsigned int cpu)
@@ -557,7 +572,7 @@ static void cpuhp_thread_fun(unsigned int cpu)
557572
cpuhp_lock_release(bringup);
558573

559574
if (!st->should_run)
560-
complete(&st->done);
575+
complete_ap_thread(st, bringup);
561576
}
562577

563578
/* Invoke a single callback on a remote cpu */
@@ -753,7 +768,7 @@ static int takedown_cpu(unsigned int cpu)
753768
*
754769
* Wait for the stop thread to go away.
755770
*/
756-
wait_for_completion(&st->done);
771+
wait_for_ap_thread(st, false);
757772
BUG_ON(st->state != CPUHP_AP_IDLE_DEAD);
758773

759774
/* Interrupts are moved away from the dying cpu, reenable alloc/free */
@@ -772,7 +787,7 @@ static void cpuhp_complete_idle_dead(void *arg)
772787
{
773788
struct cpuhp_cpu_state *st = arg;
774789

775-
complete(&st->done);
790+
complete_ap_thread(st, false);
776791
}
777792

778793
void cpuhp_report_idle_dead(void)
@@ -939,7 +954,7 @@ void cpuhp_online_idle(enum cpuhp_state state)
939954
return;
940955

941956
st->state = CPUHP_AP_ONLINE_IDLE;
942-
complete(&st->done);
957+
complete_ap_thread(st, true);
943958
}
944959

945960
/* Requires cpu_add_remove_lock to be held */

0 commit comments

Comments
 (0)