Received: by 10.192.165.156 with SMTP id m28csp1080131imm; Wed, 11 Apr 2018 12:02:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ROzcgp9FKpW0KdVull81Fn67zWpsQ2Sm3AT/tNPdlZj5Ffw3+FyfjFDWBgx9bOseRWNiX X-Received: by 2002:a17:902:564:: with SMTP id 91-v6mr6472782plf.63.1523473374453; Wed, 11 Apr 2018 12:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523473374; cv=none; d=google.com; s=arc-20160816; b=zVGV91PtacE4mRGACmQkV7gMnjZGxVKSoXvcI8Wl3Mx2veETbp5IApVqMidvVI4Tah vqkSs22QL4jaNDOX5idDGuEItA61npQlx0Rr2UmTGK3tktiawuJrV1zAHoOLMp+Mx4v4 ahl9+Ad2QCm+vt0d23YqW5e8Y3NaS8DGUJ2Q1FrUiCZyeb3B4YnKEFwY/vPWpGbyBmxg pobVA/968GkOECCGiN4K1kYCKJPT2g70Kci7dxfrzMHtaCATDCFQHHNScpxumgplZa3L F/2SXctTVTfP7l8oH+2fb+bw3ZfwRJwXpP+FJpawq0Kqc3v8N/fsUhQB7kqziqGie47P yESg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=i8wyh+L+2xHX1S5Nk+lrklmRh3wodqOYh045iXyHSF4=; b=NsEMHKCUNzUGvdoqqu7FZcJrupkZ8mtdhjNzMu5plPuAEHsNzq4zTjWeur/purXYlB Z+649mzJD/+26wVV1nvBexFxIeeBvID2cAcHd8x1hV9SNy9r9myAICLDR1I0+qZfQ55x dEnOt72q47OsemPd/3vO7rtBm4R+n6d07PNtGH5rE4KmLzFMSJY3Qaqn0ixltQ9Kibxn KI6iSOf5CB6vQMlPbLqXnLlBXM2ZeIvUeL2z0Gxm2z0f9g/l4zEm9vUgFTiSTyk7D4xR A64TPRdSOzMwaI8IvvVC/boa+I5Vt0g8rUbcznyzRHP+0NwVVPE67tDZxpK9v4w+WD6S xkyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si1644213plw.143.2018.04.11.12.02.17; Wed, 11 Apr 2018 12:02:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756446AbeDKS5f (ORCPT + 99 others); Wed, 11 Apr 2018 14:57:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36336 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756431AbeDKS5c (ORCPT ); Wed, 11 Apr 2018 14:57:32 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2F6CEC06; Wed, 11 Apr 2018 18:57:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar , Peter Zijlstra , Sebastian Siewior , Steven Rostedt , Sasha Levin Subject: [PATCH 4.9 113/310] cpuhotplug: Link lock stacks for hotplug callbacks Date: Wed, 11 Apr 2018 20:34:12 +0200 Message-Id: <20180411183627.044868504@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner [ Upstream commit 49dfe2a6779717d9c18395684ee31bdc98b22e53 ] 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 Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/cpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -63,6 +63,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 @@ -563,6 +569,7 @@ static void cpuhp_thread_fun(unsigned in 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) { @@ -594,6 +601,7 @@ static void cpuhp_thread_fun(unsigned in 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); } @@ -608,6 +616,9 @@ cpuhp_invoke_ap_callback(int cpu, enum c 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. @@ -651,6 +662,8 @@ static int cpuhp_kick_ap_work(unsigned i 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);