From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751612AbdIEIDx (ORCPT ); Tue, 5 Sep 2017 04:03:53 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:48355 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750814AbdIEIDZ (ORCPT ); Tue, 5 Sep 2017 04:03:25 -0400 Message-Id: <20170905075351.686444505@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 05 Sep 2017 09:52:19 +0200 From: Peter Zijlstra To: mingo@kernel.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Byungchul Park , Sebastian Andrzej Siewior , Mike Galbraith Subject: [PATCH 1/2] smp/hotplug,lockdep: Annotate st->done References: <20170905075218.526515965@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peter_zijlstra-hotplug_lockdep_splat_tip.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the new lockdep cross-release feature, cpu hotplug reports the following deadlock: 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) However, CPU-up and CPU-down are globally serialized, so the above scenario cannot in fact happen. Annotate this by splitting the st->done dependency chain for up and down. Cc: Thomas Gleixner Cc: Byungchul Park Cc: Sebastian Andrzej Siewior Reported-by: Mike Galbraith Tested-by: Mike Galbraith Signed-off-by: Peter Zijlstra (Intel) --- kernel/cpu.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index acf5308fad51..0f44ddf64f24 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -533,6 +533,28 @@ void __init cpuhp_threads_init(void) kthread_unpark(this_cpu_read(cpuhp_state.thread)); } +/* + * _cpu_down() and _cpu_up() have different lock ordering wrt st->done, but + * because these two functions are globally serialized and st->done is private + * to them, we can simply re-init st->done for each of them to separate the + * lock chains. + * + * Must be macro to ensure we have two different call sites. + */ +#ifdef CONFIG_LOCKDEP +#define lockdep_reinit_st_done() \ +do { \ + int __cpu; \ + for_each_possible_cpu(__cpu) { \ + struct cpuhp_cpu_state *st = \ + per_cpu_ptr(&cpuhp_state, __cpu); \ + init_completion(&st->done); \ + } \ +} while(0) +#else +#define lockdep_reinit_st_done() +#endif + #ifdef CONFIG_HOTPLUG_CPU /** * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU @@ -676,12 +698,6 @@ void cpuhp_report_idle_dead(void) cpuhp_complete_idle_dead, st, 0); } -#else -#define takedown_cpu NULL -#endif - -#ifdef CONFIG_HOTPLUG_CPU - /* Requires cpu_add_remove_lock to be held */ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) @@ -697,6 +713,8 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen, cpus_write_lock(); + lockdep_reinit_st_done(); + cpuhp_tasks_frozen = tasks_frozen; prev_state = st->state; @@ -759,6 +777,9 @@ int cpu_down(unsigned int cpu) return do_cpu_down(cpu, CPUHP_OFFLINE); } EXPORT_SYMBOL(cpu_down); + +#else +#define takedown_cpu NULL #endif /*CONFIG_HOTPLUG_CPU*/ /** @@ -806,6 +827,8 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) cpus_write_lock(); + lockdep_reinit_st_done(); + if (!cpu_present(cpu)) { ret = -EINVAL; goto out;