Skip to content

Commit cb92173

Browse files
Peter Zijlstraingomolnar
authored andcommitted
locking/lockdep, cpu/hotplug: Annotate AP thread
Anybody trying to assert the cpu_hotplug_lock is held (lockdep_assert_cpus_held()) from AP callbacks will fail, because the lock is held by the BP. Stick in an explicit annotation in cpuhp_thread_fun() to make this work. Reported-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-tip-commits@vger.kernel.org Fixes: cb53826 ("jump_label/lockdep: Assert we hold the hotplug lock for _cpuslocked() operations") Link: http://lkml.kernel.org/r/20180911095127.GT24082@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 84818af commit cb92173

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎kernel/cpu.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ void lockdep_assert_cpus_held(void)
315315
percpu_rwsem_assert_held(&cpu_hotplug_lock);
316316
}
317317

318+
static void lockdep_acquire_cpus_lock(void)
319+
{
320+
rwsem_acquire(&cpu_hotplug_lock.rw_sem.dep_map, 0, 0, _THIS_IP_);
321+
}
322+
323+
static void lockdep_release_cpus_lock(void)
324+
{
325+
rwsem_release(&cpu_hotplug_lock.rw_sem.dep_map, 1, _THIS_IP_);
326+
}
327+
318328
/*
319329
* Wait for currently running CPU hotplug operations to complete (if any) and
320330
* disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects
@@ -344,6 +354,17 @@ void cpu_hotplug_enable(void)
344354
cpu_maps_update_done();
345355
}
346356
EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
357+
358+
#else
359+
360+
static void lockdep_acquire_cpus_lock(void)
361+
{
362+
}
363+
364+
static void lockdep_release_cpus_lock(void)
365+
{
366+
}
367+
347368
#endif /* CONFIG_HOTPLUG_CPU */
348369

349370
#ifdef CONFIG_HOTPLUG_SMT
@@ -616,6 +637,12 @@ static void cpuhp_thread_fun(unsigned int cpu)
616637
*/
617638
smp_mb();
618639

640+
/*
641+
* The BP holds the hotplug lock, but we're now running on the AP,
642+
* ensure that anybody asserting the lock is held, will actually find
643+
* it so.
644+
*/
645+
lockdep_acquire_cpus_lock();
619646
cpuhp_lock_acquire(bringup);
620647

621648
if (st->single) {
@@ -661,6 +688,7 @@ static void cpuhp_thread_fun(unsigned int cpu)
661688
}
662689

663690
cpuhp_lock_release(bringup);
691+
lockdep_release_cpus_lock();
664692

665693
if (!st->should_run)
666694
complete_ap_thread(st, bringup);

0 commit comments

Comments
 (0)