Skip to content

Commit e388b80

Browse files
author
Russell King
committed
ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
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>
1 parent 06c23f5 commit e388b80

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

arch/arm/mm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ obj-$(CONFIG_CPU_MOHAWK) += proc-mohawk.o
9797
obj-$(CONFIG_CPU_FEROCEON) += proc-feroceon.o
9898
obj-$(CONFIG_CPU_V6) += proc-v6.o
9999
obj-$(CONFIG_CPU_V6K) += proc-v6.o
100-
obj-$(CONFIG_CPU_V7) += proc-v7.o
100+
obj-$(CONFIG_CPU_V7) += proc-v7.o proc-v7-bugs.o
101101
obj-$(CONFIG_CPU_V7M) += proc-v7m.o
102102

103103
AFLAGS_proc-v6.o :=-Wa,-march=armv6

arch/arm/mm/proc-v7-bugs.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/kernel.h>
3+
#include <linux/smp.h>
4+
5+
static __maybe_unused void cpu_v7_check_auxcr_set(bool *warned,
6+
u32 mask, const char *msg)
7+
{
8+
u32 aux_cr;
9+
10+
asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (aux_cr));
11+
12+
if ((aux_cr & mask) != mask) {
13+
if (!*warned)
14+
pr_err("CPU%u: %s", smp_processor_id(), msg);
15+
*warned = true;
16+
}
17+
}
18+
19+
static DEFINE_PER_CPU(bool, spectre_warned);
20+
21+
static void check_spectre_auxcr(bool *warned, u32 bit)
22+
{
23+
if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR) &&
24+
cpu_v7_check_auxcr_set(warned, bit,
25+
"Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable\n");
26+
}
27+
28+
void cpu_v7_ca8_ibe(void)
29+
{
30+
check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(6));
31+
}
32+
33+
void cpu_v7_ca15_ibe(void)
34+
{
35+
check_spectre_auxcr(this_cpu_ptr(&spectre_warned), BIT(0));
36+
}

arch/arm/mm/proc-v7.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ __v7_setup_stack:
569569
globl_equ cpu_ca8_do_suspend, cpu_v7_do_suspend
570570
globl_equ cpu_ca8_do_resume, cpu_v7_do_resume
571571
#endif
572-
define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
572+
define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_ca8_ibe
573573

574574
@ Cortex-A9 - needs more registers preserved across suspend/resume
575575
@ and bpiall switch_mm for hardening
@@ -602,7 +602,7 @@ __v7_setup_stack:
602602
globl_equ cpu_ca15_suspend_size, cpu_v7_suspend_size
603603
globl_equ cpu_ca15_do_suspend, cpu_v7_do_suspend
604604
globl_equ cpu_ca15_do_resume, cpu_v7_do_resume
605-
define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
605+
define_processor_functions ca15, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_ca15_ibe
606606
#ifdef CONFIG_CPU_PJ4B
607607
define_processor_functions pj4b, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
608608
#endif

0 commit comments

Comments
 (0)