From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425855AbdEZIwW (ORCPT ); Fri, 26 May 2017 04:52:22 -0400 Received: from terminus.zytor.com ([65.50.211.136]:33179 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933830AbdEZIwU (ORCPT ); Fri, 26 May 2017 04:52:20 -0400 Date: Fri, 26 May 2017 01:48:59 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: paulmck@linux.vnet.ibm.com, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, rostedt@goodmis.org, hpa@zytor.com, peterz@infradead.org Reply-To: mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, bigeasy@linutronix.de, tglx@linutronix.de In-Reply-To: <20170524081549.709375845@linutronix.de> References: <20170524081549.709375845@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:smp/hotplug] cpuhotplug: Link lock stacks for hotplug callbacks Git-Commit-ID: 49dfe2a6779717d9c18395684ee31bdc98b22e53 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 49dfe2a6779717d9c18395684ee31bdc98b22e53 Gitweb: http://git.kernel.org/tip/49dfe2a6779717d9c18395684ee31bdc98b22e53 Author: Thomas Gleixner AuthorDate: Wed, 24 May 2017 10:15:43 +0200 Committer: Thomas Gleixner CommitDate: Fri, 26 May 2017 10:10:48 +0200 cpuhotplug: Link lock stacks for hotplug callbacks The CPU hotplug callbacks are not covered by lockdep versus the cpu hotplug rwsem. CPU0 CPU1 cpuhp_setup_state(STATE, startup, teardown); cpus_read_lock(); invoke_callback_on_ap(); kick_hotplug_thread(ap); wait_for_completion(); hotplug_thread_fn() lock(m); do_stuff(); unlock(m); Lockdep does not know about this dependency and will not trigger on the following code sequence: lock(m); cpus_read_lock(); Add a lockdep map and connect the initiators lock chain with the hotplug thread lock chain, so potential deadlocks can be detected. Signed-off-by: Thomas Gleixner Tested-by: Paul E. McKenney Acked-by: Ingo Molnar Cc: Peter Zijlstra Cc: Sebastian Siewior Cc: Steven Rostedt Link: http://lkml.kernel.org/r/20170524081549.709375845@linutronix.de --- kernel/cpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/cpu.c b/kernel/cpu.c index 6683621..7435ffc 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -66,6 +66,12 @@ struct cpuhp_cpu_state { static DEFINE_PER_CPU(struct cpuhp_cpu_state, cpuhp_state); +#if defined(CONFIG_LOCKDEP) && defined(CONFIG_SMP) +static struct lock_class_key cpuhp_state_key; +static struct lockdep_map cpuhp_state_lock_map = + STATIC_LOCKDEP_MAP_INIT("cpuhp_state", &cpuhp_state_key); +#endif + /** * cpuhp_step - Hotplug state machine step * @name: Name of the step @@ -403,6 +409,7 @@ static void cpuhp_thread_fun(unsigned int cpu) st->should_run = false; + lock_map_acquire(&cpuhp_state_lock_map); /* Single callback invocation for [un]install ? */ if (st->single) { if (st->cb_state < CPUHP_AP_ONLINE) { @@ -429,6 +436,7 @@ static void cpuhp_thread_fun(unsigned int cpu) else if (st->state > st->target) ret = cpuhp_ap_offline(cpu, st); } + lock_map_release(&cpuhp_state_lock_map); st->result = ret; complete(&st->done); } @@ -443,6 +451,9 @@ cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, bool bringup, if (!cpu_online(cpu)) return 0; + lock_map_acquire(&cpuhp_state_lock_map); + lock_map_release(&cpuhp_state_lock_map); + /* * If we are up and running, use the hotplug thread. For early calls * we invoke the thread function directly. @@ -486,6 +497,8 @@ static int cpuhp_kick_ap_work(unsigned int cpu) enum cpuhp_state state = st->state; trace_cpuhp_enter(cpu, st->target, state, cpuhp_kick_ap_work); + lock_map_acquire(&cpuhp_state_lock_map); + lock_map_release(&cpuhp_state_lock_map); __cpuhp_kick_ap_work(st); wait_for_completion(&st->done); trace_cpuhp_exit(cpu, st->state, state, st->result);