All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Long <dave.long@linaro.org>
To: stable@vger.kernel.org,
	Russell King - ARM Linux <linux@armlinux.org.uk>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Tony Lindgren <tony@atomide.com>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Mark Rutland <mark.rutland@arm.com>
Cc: Greg KH <gregkh@linuxfoundation.org>, Mark Brown <broonie@kernel.org>
Subject: [PATCH 4.9 V2 07/24] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
Date: Wed,  7 Nov 2018 11:43:45 -0500	[thread overview]
Message-ID: <20181107164402.9380-8-dave.long@linaro.org> (raw)
In-Reply-To: <20181107164402.9380-1-dave.long@linaro.org>

From: Russell King <rmk+kernel@armlinux.org.uk>

Commit e388b80288aade31135aca23d32eee93dd106795 upstream.

When the branch predictor hardening is enabled, firmware must have set
the IBE bit in the auxiliary control register.  If this bit has not
been set, the Spectre workarounds will not be functional.

Add validation that this bit is set, and print a warning at alert level
if this is not the case.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Boot-tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: David A. Long <dave.long@linaro.org>
---
 arch/arm/mm/Makefile       |  2 +-
 arch/arm/mm/proc-v7-bugs.c | 36 ++++++++++++++++++++++++++++++++++++
 arch/arm/mm/proc-v7.S      |  4 ++--
 3 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mm/proc-v7-bugs.c

diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile
index e8698241ece9..92d47c8cbbc3 100644
--- a/arch/arm/mm/Makefile
+++ b/arch/arm/mm/Makefile
@@ -94,7 +94,7 @@ obj-$(CONFIG_CPU_MOHAWK)	+= proc-mohawk.o
 obj-$(CONFIG_CPU_FEROCEON)	+= proc-feroceon.o
 obj-$(CONFIG_CPU_V6)		+= proc-v6.o
 obj-$(CONFIG_CPU_V6K)		+= proc-v6.o
-obj-$(CONFIG_CPU_V7)		+= proc-v7.o
+obj-$(CONFIG_CPU_V7)		+= proc-v7.o proc-v7-bugs.o
 obj-$(CONFIG_CPU_V7M)		+= proc-v7m.o
 
 AFLAGS_proc-v6.o	:=-Wa,-march=armv6
diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c
new file mode 100644
index 000000000000..e46557db6446
--- /dev/null
+++ b/arch/arm/mm/proc-v7-bugs.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
+#include <linux/smp.h>
+
+static __maybe_unused void cpu_v7_check_auxcr_set(bool *warned,
+						  u32 mask, const char *msg)
+{
+	u32 aux_cr;
+
+	asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (aux_cr));
+
+	if ((aux_cr & mask) != mask) {
+		if (!*warned)
+			pr_err("CPU%u: %s", smp_processor_id(), msg);
+		*warned = true;
+	}
+}
+
+static DEFINE_PER_CPU(bool, spectre_warned);
+
+static void check_spectre_auxcr(bool *warned, u32 bit)
+{
+	if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR) &&
+		cpu_v7_check_auxcr_set(warned, bit,
+				       "Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable\n");
+}
+
+void cpu_v7_ca8_ibe(void)
+{
+	check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(6));
+}
+
+void cpu_v7_ca15_ibe(void)
+{
+	check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(0));
+}
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index bf632d76d392..4e4f794f17ce 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -564,7 +564,7 @@ __v7_setup_stack:
 	globl_equ	cpu_ca8_do_suspend,	cpu_v7_do_suspend
 	globl_equ	cpu_ca8_do_resume,	cpu_v7_do_resume
 #endif
-	define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
+	define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_ca8_ibe
 
 	@ Cortex-A9 - needs more registers preserved across suspend/resume
 	@ and bpiall switch_mm for hardening
@@ -597,7 +597,7 @@ __v7_setup_stack:
 	globl_equ	cpu_ca15_suspend_size,	cpu_v7_suspend_size
 	globl_equ	cpu_ca15_do_suspend,	cpu_v7_do_suspend
 	globl_equ	cpu_ca15_do_resume,	cpu_v7_do_resume
-	define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
+	define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_ca15_ibe
 #ifdef CONFIG_CPU_PJ4B
 	define_processor_functions pj4b, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
 #endif
-- 
2.17.1

  parent reply	other threads:[~2018-11-08  2:15 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 16:43 [PATCH 4.9 V2 00/24] V4.9 backport of 32-bit arm spectre patches David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 01/24] ARM: add more CPU part numbers for Cortex and Brahma B15 CPUs David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 02/24] ARM: bugs: prepare processor bug infrastructure David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 03/24] ARM: bugs: hook processor bug checking into SMP and suspend paths David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 04/24] ARM: bugs: add support for per-processor bug checking David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 05/24] ARM: spectre: add Kconfig symbol for CPUs vulnerable to Spectre David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 06/24] ARM: spectre-v2: harden branch predictor on context switches David Long
2018-11-07 16:43 ` David Long [this message]
2018-11-07 16:43 ` [PATCH 4.9 V2 08/24] ARM: spectre-v2: harden user aborts in kernel space David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 09/24] ARM: spectre-v2: add firmware based hardening David Long
2018-11-12 16:54   ` Russell King - ARM Linux
2018-11-13 14:23     ` Marc Zyngier
2018-11-13 15:16       ` David Long
2018-11-13 17:36         ` Marc Zyngier
2018-11-13 17:54           ` Russell King - ARM Linux
2018-11-13 16:43       ` Tony Lindgren
2018-11-13 18:08       ` Florian Fainelli
2018-11-20 10:59         ` Russell King - ARM Linux
2018-11-20 11:15           ` Greg KH
2018-11-20 15:30             ` David Long
2018-11-20 16:42               ` Marc Zyngier
2018-11-20 16:24           ` David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 10/24] ARM: spectre-v2: warn about incorrect context switching functions David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 11/24] ARM: KVM: invalidate BTB on guest exit for Cortex-A12/A17 David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 12/24] ARM: KVM: invalidate icache on guest exit for Cortex-A15 David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 13/24] ARM: spectre-v2: KVM: invalidate icache on guest exit for Brahma B15 David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 14/24] ARM: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 15/24] ARM: KVM: report support for SMCCC_ARCH_WORKAROUND_1 David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 16/24] ARM: spectre-v1: add speculation barrier (csdb) macros David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 17/24] ARM: spectre-v1: add array_index_mask_nospec() implementation David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 18/24] ARM: spectre-v1: fix syscall entry David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 19/24] ARM: signal: copy registers using __copy_from_user() David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 20/24] ARM: vfp: use __copy_from_user() when restoring VFP state David Long
2018-11-07 16:43 ` [PATCH 4.9 V2 21/24] ARM: oabi-compat: copy semops using __copy_from_user() David Long
2018-11-07 16:44 ` [PATCH 4.9 V2 22/24] ARM: use __inttype() in get_user() David Long
2018-11-07 16:44 ` [PATCH 4.9 V2 23/24] ARM: spectre-v1: use get_user() for __get_user() David Long
2018-11-07 16:44 ` [PATCH 4.9 V2 24/24] ARM: spectre-v1: mitigate user accesses David Long
2018-11-12 15:27 ` [PATCH 4.9 V2 00/24] V4.9 backport of 32-bit arm spectre patches Russell King - ARM Linux
2018-11-21 18:27 ` Greg KH
2018-11-21 19:13   ` David Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181107164402.9380-8-dave.long@linaro.org \
    --to=dave.long@linaro.org \
    --cc=broonie@kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux@armlinux.org.uk \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.