From patchwork Thu May 11 13:12:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 99648 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp724422qge; Thu, 11 May 2017 06:13:01 -0700 (PDT) X-Received: by 10.98.150.211 with SMTP id s80mr276621pfk.15.1494508381046; Thu, 11 May 2017 06:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494508381; cv=none; d=google.com; s=arc-20160816; b=IFT1Bjo6WLl85imDjKl2Roiq3IpvIe9r27jEeLXiWuFCe1pbAMfSjrn1kF0mbs9dMK Y763PgmAyzBw0Ye+g6CbMI+B3z1V/mt1vBHT1JccFnZttdeJo3bqptkjRSIsX02aEROG qPyqmEzZZiZiTsE3ewBE23clXe21lz7m3AIJ3lSWuXEOGenKwF3s0K/VxPf8iUGDNM4l e/0Nlg2UWznQcVBPBdiKnfX1QJLT+3Rwc7gYir+6Lf2xK7um+7Qld46oXqrU2xCyTEVT fehfrzudgcrNYT8qdNS5HeYGp+hRowcil/QEpfO6w7pXCSBL6iP+ZUvhEBtSc076L9ZU ZK8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=v6F/Jefac8wSS2PkCIrbpUsXHFQyndcbKIkCso+OcaI=; b=AKQE517bnXmGB6htmhXtjg7spk2JP017vLmQbB4EZDX3NULRfYQU4Bu7Oy8kzGXagy 1DUb73lBGYrQcOTJu8WRGy6ir7zQ7Tk7mSaHqsnFoNWb7KdPHQQPd8g/RxO9DxCjNi+Q SPOATqoHOQqfJWkCh2n73UjUFGWzGSjIbmbJtEcMAr1o7/ufuiQ9uIk7v6q14LQDHGzd CImcMY5VC1cQMNDXT436BhQGwhUH4EcUG9rP3rFP7pjSLRodAc7ZjMPkMAB0oQY4xJ3L lNXomm1BYQZgA9dCqFOA8Xe5Ixna/lSi7MClvvDTsRzBft9346uSBt/mPCXiVNwIAPvP nALQ== 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 b61si132114plb.6.2017.05.11.06.13.00; Thu, 11 May 2017 06:13:01 -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 S1755659AbdEKNMw (ORCPT + 25 others); Thu, 11 May 2017 09:12:52 -0400 Received: from foss.arm.com ([217.140.101.70]:47456 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754975AbdEKNMu (ORCPT ); Thu, 11 May 2017 09:12:50 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F5CC2B; Thu, 11 May 2017 06:12:50 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 832AA3F220; Thu, 11 May 2017 06:12:48 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, bigeasy@linutronix.de, catalin.marinas@arm.com, marc.zyngier@arm.com, mark.rutland@arm.com, peterz@infradead.org, suzuki.poulose@arm.com, tglx@linutronix.de, will.deacon@arm.com Subject: [PATCH] arm64/cpufeature: don't use mutex in bringup path Date: Thu, 11 May 2017 14:12:11 +0100 Message-Id: <1494508331-31644-1-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, cpus_set_cap() calls static_branch_enable_cpuslocked(), which must take the jump_label mutex. We call cpus_set_cap() in the secondary bringup path, from the idle thread where interrupts are disabled. Taking a mutex in this path "is a NONO" regardless of whether it's contended, and something we must avoid. Additionally, the secondary CPU doesn't hold the percpu rwsem (as this is held by the primary CPU), so this triggers a lockdep splat. This patch fixes both issues by moving the static_key poking from cpus_set_cap() into enable_cpu_capabilities(). This means that there is a period between detecting an erratum and cpus_have_const_cap(erratum) being true, but largely this is fine. Features are only enabled later regardless, and most errata workarounds are best-effort. This rework means that we can remove the *_cpuslocked() helpers added in commit d54bb72551b999dd ("arm64/cpufeature: Use static_branch_enable_cpuslocked()"). Fixes: efd9e03facd075f5 ("arm64: Use static keys for CPU features") Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Marc Zyniger Cc: Peter Zijlstra Cc: Sebastian Sewior Cc: Suzuki Poulose Cc: Thomas Gleixner Cc: Will Deacon --- arch/arm64/include/asm/cpufeature.h | 3 +-- arch/arm64/kernel/cpu_errata.c | 9 +-------- arch/arm64/kernel/cpufeature.c | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 13 deletions(-) I'm not sure what to do about ARM64_WORKAROUND_CAVIUM_23154. This patch will defer enabling the workaround until all CPUs are up, and I can't see a good way of having the workaround on by default, then subsequently disabled if no CPUs are affected. Thanks, Mark -- 1.9.1 diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 8a7ff73..5370626 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -145,7 +145,6 @@ static inline void cpus_set_cap(unsigned int num) num, ARM64_NCAPS); } else { __set_bit(num, cpu_hwcaps); - static_branch_enable_cpuslocked(&cpu_hwcap_keys[num]); } } @@ -223,7 +222,7 @@ void update_cpu_capabilities(const struct arm64_cpu_capabilities *caps, void check_local_cpu_capabilities(void); void update_cpu_errata_workarounds(void); -void update_cpu_errata_workarounds_cpuslocked(void); +void update_cpu_errata_workarounds(void); void __init enable_errata_workarounds(void); void verify_local_cpu_errata_workarounds(void); diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 57d60fa..2ed2a76 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -190,16 +190,9 @@ void verify_local_cpu_errata_workarounds(void) } } -void update_cpu_errata_workarounds_cpuslocked(void) -{ - update_cpu_capabilities(arm64_errata, "enabling workaround for"); -} - void update_cpu_errata_workarounds(void) { - get_online_cpus(); - update_cpu_errata_workarounds_cpuslocked(); - put_online_cpus(); + update_cpu_capabilities(arm64_errata, "enabling workaround for"); } void __init enable_errata_workarounds(void) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 803afae..68ed74d 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -986,8 +986,16 @@ void update_cpu_capabilities(const struct arm64_cpu_capabilities *caps, */ void __init enable_cpu_capabilities(const struct arm64_cpu_capabilities *caps) { - for (; caps->matches; caps++) - if (caps->enable && cpus_have_cap(caps->capability)) + for (; caps->matches; caps++) { + unsigned int num = caps->capability; + + if (!cpus_have_cap(num)) + continue; + + /* Ensure cpus_have_const_cap(num) works */ + static_branch_enable(&cpu_hwcap_keys[num]); + + if (caps->enable) { /* * Use stop_machine() as it schedules the work allowing * us to modify PSTATE, instead of on_each_cpu() which @@ -995,6 +1003,8 @@ void __init enable_cpu_capabilities(const struct arm64_cpu_capabilities *caps) * we return. */ stop_machine(caps->enable, NULL, cpu_online_mask); + } + } } /* @@ -1086,7 +1096,7 @@ void check_local_cpu_capabilities(void) * advertised capabilities. */ if (!sys_caps_initialised) - update_cpu_errata_workarounds_cpuslocked(); + update_cpu_errata_workarounds(); else verify_local_cpu_capabilities(); }