ARM Spectre variant 2 fixes
Subsystems (2)
Russell King - ARM Linux
maintainercover ARM Spectre variant 2 fixes
This series addresses the Spectre variant 2 issues on ARM Cortex and Broadcom Brahma B15 CPUs. Due to the complexity of the bug, it is not possible to verify that this series fixes any of the bugs, since it has not been able to reproduce these exact scenarios using test programs.
I believe that this covers the entire extent of the Spectre variant 2 issues, with the exception of Cortex A53 and Cortex A72 processors as these require a substantially more complex solution (except where the workaround is implemented in PSCI firmware.)
Spectre variant 1 is not covered by this series.
The patch series is based partly on Marc Zyngier's work from February - two of the KVM patches are from Marc's work.
The main differences are:
- Inclusion of more processors as per current ARM Ltd security update documentation.
- Extension of "bugs" infrastructure to detect Cortex A8 and Cortex A15 CPUs missing out on the IBE bit being set on (re-)entry to the kernel through all paths.
- Handle all suspect userspace-touching-kernelspace aborts irrespective of mapping type.
The first patch will trivially conflict with the Broadcom Brahma updates already in arm-soc - it has been necessary to independently add the ID definitions for the B15 CPU.
Having worked through this series, I'm of the opinion that the define_processor_functions macro in proc-v7 are probably more hassle than they're worth - here, we don't need the global equivalent symbols, because we never refer to them from the kernel code for any V7 processor (MULTI_CPU is always defined.)
This series is currently in my "spectre" branch (along with some Spectre variant 1 patches.)
Please carefully review.
arch/arm/include/asm/bugs.h | 6 +- arch/arm/include/asm/cp15.h | 3 + arch/arm/include/asm/cputype.h | 5 ++ arch/arm/include/asm/kvm_asm.h | 2 - arch/arm/include/asm/kvm_host.h | 14 +++- arch/arm/include/asm/kvm_mmu.h | 23 +++++- arch/arm/include/asm/proc-fns.h | 4 + arch/arm/include/asm/system_misc.h | 8 ++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/bugs.c | 18 +++++ arch/arm/kernel/smp.c | 4 + arch/arm/kernel/suspend.c | 2 + arch/arm/kvm/hyp/hyp-entry.S | 108 ++++++++++++++++++++++++- arch/arm/mm/Kconfig | 23 ++++++ arch/arm/mm/Makefile | 2 +- arch/arm/mm/fault.c | 3 + arch/arm/mm/proc-macros.S | 3 +- arch/arm/mm/proc-v7-2level.S | 6 -- arch/arm/mm/proc-v7-bugs.c | 130 ++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 158 +++++++++++++++++++++++++++++-------- 20 files changed, 471 insertions(+), 52 deletions(-)
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
PATCH 1/14 ARM: add CPU part numbers for Cortex A73, A75 and Brahma B15
Add CPU part numbers for the above mentioned CPUs
--- arch/arm/include/asm/cputype.h | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/include/asm/cputype.h +5 -0
@@ -77,8 +77,13 @@#define ARM_CPU_PART_CORTEX_A12 0x4100c0d0#define ARM_CPU_PART_CORTEX_A17 0x4100c0e0#define ARM_CPU_PART_CORTEX_A15 0x4100c0f0 +#define ARM_CPU_PART_CORTEX_A73 0x4100d090 +#define ARM_CPU_PART_CORTEX_A75 0x4100d0a0#define ARM_CPU_PART_MASK 0xff00fff0 +/* Broadcom cores */ +#define ARM_CPU_PART_BRAHMA_B15 0x420000f0 +/* DEC implemented cores */ #define ARM_CPU_PART_SA1100 0x4400a110
Signature · 1 line
2.7.4
Re: [PATCH 01/14] ARM: add CPU part numbers for Cortex A73, A75 and Brahma B15
Quoted 12 lines · Russell King
Add CPU part numbers for the above mentioned CPUs
Signed-off-by Russell King <[email protected]>--- arch/arm/include/asm/cputype.h | 5 +++++ 1 file changed, 5 insertions(+)arch/arm/include/asm/cputype.h +0
-0
arch/arm/include/asm/cputype.h line 85
Quoted 9 lines
arch/arm/include/asm/cputype.h +4
-0@@ -77,8 +77,13 @@#define ARM_CPU_PART_CORTEX_A12 0x4100c0d0#define ARM_CPU_PART_CORTEX_A17 0x4100c0e0#define ARM_CPU_PART_CORTEX_A15 0x4100c0f0 +#define ARM_CPU_PART_CORTEX_A73 0x4100d090 +#define ARM_CPU_PART_CORTEX_A75 0x4100d0a0#define ARM_CPU_PART_MASK 0xff00fff0 +/* Broadcom cores */ +#define ARM_CPU_PART_BRAHMA_B15 0x420000f0
For B15:
Quoted 5 lines
arch/arm/include/asm/cputype.h +1
-0+/* DEC implemented cores */ #define ARM_CPU_PART_SA1100 0x4400a110
Signature · 1 line
Florian
PATCH 2/14 ARM: bugs: prepare processor bug infrastructure
In reply to Russell King - ARM LinuxPrepare the processor bug infrastructure so that it can be expanded to check for per-processor bugs.
--- arch/arm/include/asm/bugs.h | 4 ++-- arch/arm/kernel/Makefile | 1 + arch/arm/kernel/bugs.c | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 arch/arm/kernel/bugs.c
arch/arm/include/asm/bugs.h +2 -2
@@ -10,10 +10,10 @@#ifndef __ASM_BUGS_H#define __ASM_BUGS_H -#ifdef CONFIG_MMU extern void check_writebuffer_bugs (void ); -#define check_bugs () check_writebuffer_bugs() +#ifdef CONFIG_MMU +extern void check_bugs (void );#else #define check_bugs () do { } while (0)#endif
arch/arm/kernel/Makefile +1 -0
@@ -31,6 +31,7 @@ else obj-y += entry-armv.o endif +obj-$(CONFIG_MMU) += bugs.o obj-$(CONFIG_CPU_IDLE) += cpuidle.o obj-$(CONFIG_ISA_DMA_API) += dma.o obj-$(CONFIG_FIQ) += fiq.o fiqasm.o
arch/arm/kernel/bugs.c new file +9 -0
@@ -0,0 +1,9 @@ +// SPDX-Identifier: GPL-2.0 +#include <linux/init.h> +#include <asm/bugs.h> +#include <asm/proc-fns.h> + +void __init check_bugs (void ) +{ +check_writebuffer_bugs (); +}
Signature · 1 line
2.7.4
Re: [PATCH 02/14] ARM: bugs: prepare processor bug infrastructure
Quoted 4 lines · Russell King
Prepare the processor bug infrastructure so that it can be expanded to check for per-processor bugs.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 3/14 ARM: bugs: hook processor bug checking into SMP and suspend paths
In reply to Russell King - ARM LinuxCheck for CPU bugs when secondary processors are being brought online, and also when CPUs are resuming from a low power mode. This gives an opportunity to check that processor specific bug workarounds are correctly enabled for all paths that a CPU re-enters the kernel.
--- arch/arm/include/asm/bugs.h | 2 ++ arch/arm/kernel/bugs.c | 5 +++++ arch/arm/kernel/smp.c | 4 ++++ arch/arm/kernel/suspend.c | 2 ++ 4 files changed, 13 insertions(+)
arch/arm/include/asm/bugs.h +2 -0
@@ -14,8 +14,10 @@ extern void check_writebuffer_bugs(void);#ifdef CONFIG_MMU extern void check_bugs (void ); +extern void check_other_bugs (void );#else #define check_bugs () do { } while (0) +#define check_other_bugs () do { } while (0)#endif #endif
arch/arm/kernel/bugs.c +5 -0
@@ -3,7 +3,12 @@#include <asm/bugs.h> #include <asm/proc-fns.h> +void check_other_bugs (void ) +{ +} +void __init check_bugs (void ) {check_writebuffer_bugs (); +check_other_bugs (); }
arch/arm/kernel/smp.c +4 -0
@@ -31,6 +31,7 @@#include <linux/irq_work.h> #include <linux/atomic.h> +#include <asm/bugs.h> #include <asm/smp.h> #include <asm/cacheflush.h> #include <asm/cpu.h>
@@ -405,6 +406,9 @@ asmlinkage void secondary_start_kernel(void)* before we continue - which happens after __cpu_up returns. */ set_cpu_online (cpu, true); + +check_other_bugs (); +complete (&cpu_running);local_irq_enable ();
arch/arm/kernel/suspend.c +2 -0
@@ -3,6 +3,7 @@#include <linux/slab.h> #include <linux/mm_types.h> +#include <asm/bugs.h> #include <asm/cacheflush.h> #include <asm/idmap.h> #include <asm/pgalloc.h>
@@ -36,6 +37,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))cpu_switch_mm (mm->pgd, mm);local_flush_bp_all ();local_flush_tlb_all (); +check_other_bugs (); }return ret;
Signature · 1 line
2.7.4
Re: [PATCH 03/14] ARM: bugs: hook processor bug checking into SMP and suspend paths
Quoted 6 lines · Russell King
Check for CPU bugs when secondary processors are being brought online, and also when CPUs are resuming from a low power mode. This gives an opportunity to check that processor specific bug workarounds are correctly enabled for all paths that a CPU re-enters the kernel.
Signed-off-by Russell King <[email protected]>
Quoted 52 lines
--- arch/arm/include/asm/bugs.h | 2 ++ arch/arm/kernel/bugs.c | 5 +++++ arch/arm/kernel/smp.c | 4 ++++ arch/arm/kernel/suspend.c | 2 ++ 4 files changed, 13 insertions(+)arch/arm/include/asm/bugs.h +2
-0@@ -14,8 +14,10 @@ extern void check_writebuffer_bugs(void);#ifdef CONFIG_MMU extern void check_bugs (void ); +extern void check_other_bugs (void );#else #define check_bugs () do { } while (0) +#define check_other_bugs () do { } while (0)#endif #endif arch/arm/kernel/bugs.c +5
-0@@ -3,7 +3,12 @@#include <asm/bugs.h> #include <asm/proc-fns.h> +void check_other_bugs (void ) +{ +} +void __init check_bugs (void ) {check_writebuffer_bugs (); +check_other_bugs (); }arch/arm/kernel/smp.c +1
-0@@ -31,6 +31,7 @@#include <linux/irq_work.h> #include <linux/atomic.h> +#include <asm/bugs.h> #include <asm/smp.h> #include <asm/cacheflush.h> #include <asm/cpu.h>
arch/arm/kernel/smp.c asmlinkage void secondary_start_kernel(void) · line 410
Quoted 5 lines
arch/arm/kernel/smp.c +2
-0@@ -405,6 +406,9 @@ asmlinkage void secondary_start_kernel(void)* before we continue - which happens after __cpu_up returns. */ set_cpu_online (cpu, true); + +check_other_bugs ();
Given what is currently implemented, I don't think the location of check_other_bugs() matters too much, but we might have to move this after the local_irq_enable() at some point if we need to check for e.g:
a bogus local timer or whatever?
Signature · 1 line
Florian
Russell King - ARM Linux
maintainerRe: [PATCH 03/14] ARM: bugs: hook processor bug checking into SMP and suspend paths
Quoted 8 lines · Florian Fainelli
Quoted 7 lines · Russell King
arch/arm/kernel/smp.c +0
-0@@ -31,6 +31,7 @@#include <linux/irq_work.h>
Quoted 16 lines
arch/arm/kernel/smp.c asmlinkage void secondary_start_kernel(void) · line 410
Quoted 11 lines
arch/arm/kernel/smp.c +3
-0#include <linux/atomic.h> +#include <asm/bugs.h> #include <asm/smp.h> #include <asm/cacheflush.h> #include <asm/cpu.h> @@ -405,6 +406,9 @@ asmlinkage void secondary_start_kernel(void)* before we continue - which happens after __cpu_up returns. */ set_cpu_online (cpu, true); + +check_other_bugs ();Given what is currently implemented, I don't think the location of
check_other_bugs()matters too much, but we might have to move this after thelocal_irq_enable()at some point if we need to check for e.g:
a bogus local timer or whatever?
We could move it later if we need to.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
PATCH 4/14 ARM: bugs: add support for per-processor bug checking
In reply to Russell King - ARM LinuxAdd support for per-processor bug checking - each processor function descriptor gains a function pointer for this check, which must not be an __init function. If non-NULL, this will be called whenever a CPU enters the kernel via which ever path (boot CPU, secondary CPU startup, CPU resuming, etc.)
This allows processor specific bug checks to validate that workaround bits are properly enabled by firmware via all entry paths to the kernel.
--- arch/arm/include/asm/proc-fns.h | 4 ++++ arch/arm/kernel/bugs.c | 4 ++++ arch/arm/mm/proc-macros.S | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-)
arch/arm/include/asm/proc-fns.h +4 -0
@@ -37,6 +37,10 @@ extern struct processor {*/ void (*_proc_init)(void );/* +* Check for processor bugs +*/ +void (*check_bugs)(void ); +/* * Disable any processor specifics */ void (*_proc_fin)(void );
arch/arm/kernel/bugs.c +4 -0
@@ -5,6 +5,10 @@void check_other_bugs (void ) { +#ifdef MULTI_CPU +if (processor.check_bugs) + processor.check_bugs (); +#endif }void __init check_bugs (void )
arch/arm/mm/proc-macros.S +2 -1
@@ -273,13 +273,14 @@ mcr p15, 0, ip, c7, c10, 4 @ data write barrier .endm -.macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0 +.macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0, bugs=0 .type \name\()_processor_functions, #object .align 2 ENTRY(\name\()_processor_functions) .word \dabort .word \pabort .word cpu_\name\()_proc_init + .word \bugs .word cpu_\name\()_proc_fin .word cpu_\name\()_reset .word cpu_\name\()_do_idle
Signature · 1 line
2.7.4
Re: [PATCH 04/14] ARM: bugs: add support for per-processor bug checking
Quoted 10 lines · Russell King
Add support for per-processor bug checking - each processor function descriptor gains a function pointer for this check, which must not be an
__initfunction. If non-NULL, this will be called whenever a CPU enters the kernel via which ever path (boot CPU, secondary CPU startup, CPU resuming, etc.)This allows processor specific bug checks to validate that workaround bits are properly enabled by firmware via all entry paths to the kernel.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 5/14 ARM: spectre: add Kconfig symbol for CPUs vulnerable to Spectre
In reply to Russell King - ARM LinuxAdd a Kconfig symbol for CPUs which are vulnerable to the Spectre attacks.
--- arch/arm/mm/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/mm/Kconfig +4 -0
@@ -415,6 +415,7 @@ config CPU_V7 select CPU_CP15_MPU if !MMU select CPU_HAS_ASID if MMU select CPU_PABRT_V7 + select CPU_SPECTRE select CPU_THUMB_CAPABLE select CPU_TLB_V7 if MMU
@@ -826,6 +827,9 @@ config CPU_BPREDICT_DISABLE help Say Y here to disable branch prediction. If unsure, say N. +config CPU_SPECTRE + bool + config TLS_REG_EMUL bool select NEED_KUSER_HELPERS
Signature · 1 line
2.7.4
Re: [PATCH 05/14] ARM: spectre: add Kconfig symbol for CPUs vulnerable to Spectre
Quoted 4 lines · Russell King
Add a
Kconfigsymbol for CPUs which are vulnerable to the Spectre attacks.Signed-off-by Russell King <[email protected]>
--
Florian
PATCH 6/14 ARM: spectre-v2: harden branch predictor on context switches
In reply to Russell King - ARM LinuxHarden the branch predictor against Spectre v2 attacks on context switches for ARMv7 and later CPUs. We do this by:
Cortex A9, A12, A17, A73, A75, R7, R8: invalidating the BTB. Cortex A15, Brahma B15: invalidating the instruction cache.
Cortex A57 and Cortex A72 are not addressed in this patch.
--- arch/arm/mm/Kconfig | 19 +++++++ arch/arm/mm/proc-v7-2level.S | 6 -- arch/arm/mm/proc-v7.S | 129 ++++++++++++++++++++++++++++++++----------- 3 files changed, 117 insertions(+), 37 deletions(-)
arch/arm/mm/Kconfig +19 -0
@@ -830,6 +830,25 @@ config CPU_BPREDICT_DISABLE config CPU_SPECTRE bool +config HARDEN_BRANCH_PREDICTOR + bool "Harden the branch predictor against aliasing attacks" if EXPERT + depends on CPU_SPECTRE + default y + help + Speculation attacks against some high-performance processors rely + on being able to manipulate the branch predictor for a victim + context by executing aliasing branches in the attacker context. + Such attacks can be partially mitigated against by clearing + internal branch predictor state and limiting the prediction + logic in some situations. + + This config option will take CPU-specific actions to harden + the branch predictor against aliasing attacks and may rely on + specific instruction sequences or control bits being set by + the system firmware. + + If unsure, say Y. + config TLS_REG_EMUL bool select NEED_KUSER_HELPERS
arch/arm/mm/proc-v7-2level.S +0 -6
@@ -41,11 +41,6 @@ * even on Cortex-A8 revisions not affected by 430973. * If IBE is not set, the flush BTAC/BTB won't do anything. */ -ENTRY(cpu_ca8_switch_mm) -#ifdef CONFIG_MMU - mov r2, #0 - mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB -#endif ENTRY(cpu_v7_switch_mm) #ifdef CONFIG_MMU mmid r1, r1 @ get mm->context.id
@@ -66,7 +61,6 @@ ENTRY(cpu_v7_switch_mm) #endif bx lr ENDPROC(cpu_v7_switch_mm) -ENDPROC(cpu_ca8_switch_mm) /* * cpu_v7_set_pte_ext(ptep, pte)
arch/arm/mm/proc-v7.S +98 -31
189 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 06/14] ARM: spectre-v2: harden branch predictor on context switches
Quoted 9 lines · Russell King
__v7_cr7mp_proc_info:arch/arm/mm/proc-v7.S +1
-1.long 0x410fc170 .long 0xff0ffff0 - __v7_proc __v7_cr7mp_proc_info, __v7_cr7mp_setup + __v7_proc __v7_cr7mp_proc_info, __v7_cr7mp_setup, proc_fns = HARDENED_BPIALL_PROCESSOR_FUNCTIONS .size __v7_cr7mp_proc_info, . - __v7_cr7mp_proc_info /*
arch/arm/mm/proc-v7.S ENDPROC(__v7_setup) · line 704
Quoted 6 lines
arch/arm/mm/proc-v7.S +1
-1@@ -649,7 +700,7 @@ ENDPROC(__v7_setup) __v7_cr8mp_proc_info: .long 0x410fc180 .long 0xff0ffff0 - __v7_proc __v7_cr8mp_proc_info, __v7_cr8mp_setup + __v7_proc __v7_cr8mp_proc_info, __v7_cr8mp_setup, proc_fns = HARDENED_BPIALL_PROCESSOR_FUNCTIONS .size __v7_cr8mp_proc_info, . - __v7_cr8mp_proc_info
For R-class cores, the mitigation doesn't make much sense since we do not enforce user/kernel isolation anyway. I believe the same also applies to A-class cores built with !MMU, so you might want to guard CPU_SPECTRE with MMU in PATCH 05/14.
Cheers
Vladimir
PATCH 7/14 ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
In reply to Russell King - ARM LinuxWhen 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.
--- arch/arm/mm/Makefile | 2 +- arch/arm/mm/proc-v7-bugs.c | 29 +++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 4 ++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mm/proc-v7-bugs.c
arch/arm/mm/Makefile +1 -1
@@ -97,7 +97,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
arch/arm/mm/proc-v7-bugs.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h> +#include <linux/smp.h> + +static __maybe_unused void cpu_v7_check_auxcr_set (u32 mask,const char *msg) +{ +u32 aux_cr; + + asm("mrc p15, 0, %0, c1, c0, 1" :"=r" (aux_cr)); + +if ((aux_cr & mask) != mask) +pr_err ("CPU%u: %s" ,smp_processor_id (), msg); +} + +static void check_spectre_auxcr (u32 bit) +{ +if (IS_ENABLED (CONFIG_HARDEN_BRANCH_PREDICTOR )) +cpu_v7_check_auxcr_set (bit,"Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable\n" ); +} + +void cpu_v7_ca8_ibe (void ) +{ +check_spectre_auxcr (BIT (6 )); +} + +void cpu_v7_ca15_ibe (void ) +{ +check_spectre_auxcr (BIT (0 )); +}
arch/arm/mm/proc-v7.S +2 -2
@@ -570,7 +570,7 @@ ENDPROC(__v7_setup) 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
@@ -603,7 +603,7 @@ ENDPROC(__v7_setup) 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
Signature · 1 line
2.7.4
Re: [PATCH 07/14] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
Quoted 8 lines · Russell King
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 <[email protected]>
I would be keen on updating arch/arm/kernel/head.S to to attempt setting ACTRL[0]=1 on A15/B15, if the kernel executes at the appropriate privilege level, this will succeed, if not, this should result in an ignored write. What do you think?
Signature · 1 line
Florian
Re: [PATCH 07/14] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
In reply to Russell KingQuoted 8 lines · Russell King
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 <[email protected]>
Signature · 1 line
Florian
Re: [PATCH 07/14] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
In reply to Russell KingHi Russell,
Quoted 8 lines · Russell King
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 <[email protected]>
Thanks for your patch!
Quoted 5 lines
arch/arm/mm/proc-v7-bugs.c new file +2
-0@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h>
arch/arm/mm/proc-v7-bugs.c line 12
Quoted 10 lines
arch/arm/mm/proc-v7-bugs.c new file +10
-0+#include <linux/smp.h> + +static __maybe_unused void cpu_v7_check_auxcr_set (u32 mask,const char *msg) +{ +u32 aux_cr; + + asm("mrc p15, 0, %0, c1, c0, 1" :"=r" (aux_cr)); + +if ((aux_cr & mask) != mask) +pr_err ("CPU%u: %s" ,smp_processor_id (), msg);
pr_alert(), to match the patch description.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Russell King - ARM Linux
maintainerRe: [PATCH 07/14] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit
Quoted 24 lines · Geert Uytterhoeven
Hi Russell,
Quoted 8 lines · Russell King
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 <[email protected]>Thanks for your patch!
Quoted 9 lines
arch/arm/mm/proc-v7-bugs.c new file +6
-0@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h> +#include <linux/smp.h> + +static __maybe_unused void cpu_v7_check_auxcr_set (u32 mask,const char *msg) +{
Quoted 8 lines
arch/arm/mm/proc-v7-bugs.c line 12
Quoted 6 lines
arch/arm/mm/proc-v7-bugs.c new file +6
-0+u32 aux_cr; + + asm("mrc p15, 0, %0, c1, c0, 1" :"=r" (aux_cr)); + +if ((aux_cr & mask) != mask) +pr_err ("CPU%u: %s" ,smp_processor_id (), msg);
pr_alert(), to match the patch description.
It was alert, but I've lowered it because I don't think it warrants alert status. Maybe critical would be better? Shrug, this stuff is rather subjective.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
PATCH 8/14 ARM: spectre-v2: harden user aborts in kernel space
In reply to Russell King - ARM LinuxIn order to prevent aliasing attacks on the branch predictor, invalidate the BTB or instruction cache on CPUs that are known to be affected when taking an abort on a address that is outside of a user task limit:
Cortex A8, A9, A12, A17, A73, A75: flush BTB.
Cortex A15, Brahma B15: invalidate icache.
--- arch/arm/include/asm/cp15.h | 3 +++ arch/arm/include/asm/system_misc.h | 8 ++++++ arch/arm/mm/fault.c | 3 +++ arch/arm/mm/proc-v7-bugs.c | 51 ++++++++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 8 +++--- 5 files changed, 70 insertions(+), 3 deletions(-)
arch/arm/include/asm/cp15.h +3 -0
@@ -65,6 +65,9 @@#define __write_sysreg (v, r, w, c, t) asm volatile(w " " c : : "r" ((t)(v)))#define write_sysreg (v, ...) __write_sysreg(v, __VA_ARGS__) +#define BPIALL __ACCESS_CP15(c7, 0, c5, 6) +#define ICIALLU __ACCESS_CP15(c7, 0, c5, 0) +extern unsigned long cr_alignment;/* defined in entry-armv.S */ static inline unsigned long get_cr (void )
arch/arm/include/asm/system_misc.h +8 -0
@@ -15,6 +15,14 @@ void soft_restart(unsigned long);extern void (*arm_pm_restart)(enum reboot_mode reboot_mode,const char *cmd);extern void (*arm_pm_idle)(void ); +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +extern void (*harden_branch_predictor)(void ); +#define harden_branch_predictor () \ + do { if (harden_branch_predictor) harden_branch_predictor(); } while (0) +#else +#define harden_branch_predictor () do { } while (0) +#endif +#define UDBG_UNDEFINED (1 << 0)#define UDBG_SYSCALL (1 << 1)#define UDBG_BADABORT (1 << 2)
arch/arm/mm/fault.c +3 -0
@@ -163,6 +163,9 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr, {struct siginfo si; +if (addr >TASK_SIZE ) +harden_branch_predictor (); +#ifdef CONFIG_DEBUG_USER if (((user_debug &UDBG_SEGV ) && (sig ==SIGSEGV )) || ((user_debug &UDBG_BUS ) && (sig ==SIGBUS ))) {
arch/arm/mm/proc-v7-bugs.c +51 -0
66 lines not on this page · raw message
arch/arm/mm/proc-v7.S +5 -3
@@ -533,8 +533,10 @@ ENDPROC(__v7_setup) __INITDATA + .weak cpu_v7_bugs_init + @ define struct processor (see <asm/proc-fns.h> and proc-macros.S) - define_processor_functions v7, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions v7, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_bugs_init #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR @ generic v7 bpiall on context switch
@@ -549,7 +551,7 @@ ENDPROC(__v7_setup) globl_equ cpu_v7_bpiall_do_suspend, cpu_v7_do_suspend globl_equ cpu_v7_bpiall_do_resume, cpu_v7_do_resume #endif - define_processor_functions v7_bpiall, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions v7_bpiall, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_bugs_init #define HARDENED_BPIALL_PROCESSOR_FUNCTIONS v7_bpiall_processor_functions #else
@@ -585,7 +587,7 @@ ENDPROC(__v7_setup) globl_equ cpu_ca9mp_switch_mm, cpu_v7_switch_mm #endif globl_equ cpu_ca9mp_set_pte_ext, cpu_v7_set_pte_ext - define_processor_functions ca9mp, dabort=v7_early_abort, pabort=v7_pabort, suspend=1 + define_processor_functions ca9mp, dabort=v7_early_abort, pabort=v7_pabort, suspend=1, bugs=cpu_v7_bugs_init #endif @ Cortex-A15 - needs iciallu switch_mm for hardening
Signature · 1 line
2.7.4
Re: [PATCH 08/14] ARM: spectre-v2: harden user aborts in kernel space
Quoted 9 lines · Russell King
In order to prevent aliasing attacks on the branch predictor, invalidate the BTB or instruction cache on CPUs that are known to be affected when taking an abort on a address that is outside of a user task limit:
Cortex A8, A9, A12, A17, A73, A75: flush BTB.
Cortex A15, Brahma B15: invalidate icache.Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 9/14 ARM: spectre-v2: add PSCI based hardening
In reply to Russell King - ARM LinuxAdd PSCI based hardening for cores that require more complex handling in firmware.
--- arch/arm/mm/proc-v7-bugs.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 21 +++++++++++++++++++ 2 files changed, 71 insertions(+)
arch/arm/mm/proc-v7-bugs.c +50 -0
@@ -1,9 +1,12 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/arm-smccc.h> #include <linux/kernel.h> +#include <linux/psci.h> #include <linux/smp.h> #include <asm/cp15.h> #include <asm/cputype.h> +#include <asm/proc-fns.h> #include <asm/system_misc.h> void cpu_v7_bugs_init (void );
@@ -39,6 +42,9 @@ void cpu_v7_ca15_ibe(void)#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR void (*harden_branch_predictor)(void ); +extern void cpu_v7_smc_switch_mm (phys_addr_t pgd_phys,struct mm_struct *mm); +extern void cpu_v7_hvc_switch_mm (phys_addr_t pgd_phys,struct mm_struct *mm); +static void harden_branch_predictor_bpiall (void ) {write_sysreg (0 ,BPIALL );
@@ -49,6 +55,18 @@ static void harden_branch_predictor_iciallu(void)write_sysreg (0 ,ICIALLU ); } +#ifdef CONFIG_ARM_PSCI +static void call_smc_arch_workaround_1 (void ) +{ +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_1 ,NULL ); +} + +static void call_hvc_arch_workaround_1 (void ) +{ +arm_smccc_1_1_hvc (ARM_SMCCC_ARCH_WORKAROUND_1 ,NULL ); +} +#endif +void cpu_v7_bugs_init (void ) {const char *spectre_v2_method =NULL ;
@@ -73,6 +91,38 @@ void cpu_v7_bugs_init(void) spectre_v2_method ="ICIALLU" ;break ; } + +#ifdef CONFIG_ARM_PSCI +if (psci_ops.smccc_version !=SMCCC_VERSION_1_0 ) { +struct arm_smccc_res res; + +switch (psci_ops.conduit) { +case PSCI_CONDUIT_HVC : +arm_smccc_1_1_hvc (ARM_SMCCC_ARCH_FEATURES_FUNC_ID , +ARM_SMCCC_ARCH_WORKAROUND_1 , &res); +if ((int )res.a0 <0 ) +break ; + harden_branch_predictor = call_hvc_arch_workaround_1; + processor.switch_mm = cpu_v7_hvc_switch_mm; + spectre_v2_method ="hypervisor PSCI" ; +break ; + +case PSCI_CONDUIT_SMC : +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FUNC_ID , +ARM_SMCCC_ARCH_WORKAROUND_1 , &res); +if ((int )res.a0 <0 ) +break ; + harden_branch_predictor = call_smc_arch_workaround_1; + processor.switch_mm = cpu_v7_smc_switch_mm; + spectre_v2_method ="firmware PSCI" ; +break ; + +default : +break ; + } + } +#endif +if (spectre_v2_method)pr_info ("CPU: Spectre v2: using %s workaround\n" , spectre_v2_method);
arch/arm/mm/proc-v7.S +21 -0
@@ -9,6 +9,7 @@ * * This is the "shell" of the ARMv7 processor support. */ +#include <linux/arm-smccc.h> #include <linux/init.h> #include <linux/linkage.h> #include <asm/assembler.h>
@@ -93,6 +94,26 @@ ENTRY(cpu_v7_dcache_clean_area) ret lr ENDPROC(cpu_v7_dcache_clean_area) +#ifdef CONFIG_ARM_PSCI + .arch_extension sec +ENTRY(cpu_v7_smc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + smc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) + .arch_extension virt +ENTRY(cpu_v7_hvc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + hvc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) +#endif ENTRY(cpu_v7_iciallu_switch_mm) mov r3, #0 mcr p15, 0, r3, c7, c5, 0 @ ICIALLU
Signature · 1 line
2.7.4
Re: [PATCH 09/14] ARM: spectre-v2: add PSCI based hardening
[updating Christoffer's email address]
Quoted 63 lines · Russell King
Add PSCI based hardening for cores that require more complex handling in firmware.
Signed-off-by Russell King <[email protected]>--- arch/arm/mm/proc-v7-bugs.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 21 +++++++++++++++++++ 2 files changed, 71 insertions(+)arch/arm/mm/proc-v7-bugs.c +22
-0@@ -1,9 +1,12 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/arm-smccc.h> #include <linux/kernel.h> +#include <linux/psci.h> #include <linux/smp.h> #include <asm/cp15.h> #include <asm/cputype.h> +#include <asm/proc-fns.h> #include <asm/system_misc.h> void cpu_v7_bugs_init (void );@@ -39,6 +42,9 @@ void cpu_v7_ca15_ibe(void)#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR void (*harden_branch_predictor)(void ); +extern void cpu_v7_smc_switch_mm (phys_addr_t pgd_phys,struct mm_struct *mm); +extern void cpu_v7_hvc_switch_mm (phys_addr_t pgd_phys,struct mm_struct *mm); +static void harden_branch_predictor_bpiall (void ) {write_sysreg (0 ,BPIALL );@@ -49,6 +55,18 @@ static void harden_branch_predictor_iciallu(void)write_sysreg (0 ,ICIALLU ); } +#ifdef CONFIG_ARM_PSCI +static void call_smc_arch_workaround_1 (void ) +{ +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_1 ,NULL ); +} + +static void call_hvc_arch_workaround_1 (void ) +{ +arm_smccc_1_1_hvc (ARM_SMCCC_ARCH_WORKAROUND_1 ,NULL ); +} +#endif +void cpu_v7_bugs_init (void ) {const char *spectre_v2_method =NULL ;@@ -73,6 +91,38 @@ void cpu_v7_bugs_init(void) spectre_v2_method ="ICIALLU" ;break ; } + +#ifdef CONFIG_ARM_PSCI +if (psci_ops.smccc_version !=SMCCC_VERSION_1_0 ) { +struct arm_smccc_res res;
arch/arm/mm/proc-v7-bugs.c void cpu_v7_bugs_init(void) · line 107
Quoted 10 lines
arch/arm/mm/proc-v7-bugs.c +10
-0+ +switch (psci_ops.conduit) { +case PSCI_CONDUIT_HVC : +arm_smccc_1_1_hvc (ARM_SMCCC_ARCH_FEATURES_FUNC_ID , +ARM_SMCCC_ARCH_WORKAROUND_1 , &res); +if ((int )res.a0 <0 ) +break ; + harden_branch_predictor = call_hvc_arch_workaround_1; + processor.switch_mm = cpu_v7_hvc_switch_mm; + spectre_v2_method ="hypervisor PSCI" ;
nit: strictly speaking, this is not provided by PSCI, but by ARCH_WORKAROUND_1. We just use the same conduit as PSCI to discover it.
Quoted 51 lines
arch/arm/mm/proc-v7-bugs.c +18
-0+break ; + +case PSCI_CONDUIT_SMC : +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FUNC_ID , +ARM_SMCCC_ARCH_WORKAROUND_1 , &res); +if ((int )res.a0 <0 ) +break ; + harden_branch_predictor = call_smc_arch_workaround_1; + processor.switch_mm = cpu_v7_smc_switch_mm; + spectre_v2_method ="firmware PSCI" ; +break ; + +default : + break; + } + } +#endif +if (spectre_v2_method)pr_info ("CPU: Spectre v2: using %s workaround\n" , spectre_v2_method);arch/arm/mm/proc-v7.S +14
-0@@ -9,6 +9,7 @@ * * This is the "shell" of the ARMv7 processor support. */ +#include <linux/arm-smccc.h> #include <linux/init.h> #include <linux/linkage.h> #include <asm/assembler.h>@@ -93,6 +94,26 @@ ENTRY(cpu_v7_dcache_clean_area) ret lr ENDPROC(cpu_v7_dcache_clean_area) +#ifdef CONFIG_ARM_PSCI + .arch_extension sec +ENTRY(cpu_v7_smc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + smc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) + .arch_extension virt +ENTRY(cpu_v7_hvc_switch_mm) + stmfd sp!, {r0 - r3}
arch/arm/mm/proc-v7.S ENTRY(cpu_v7_dcache_clean_area) · line 119
Quoted 10 lines
arch/arm/mm/proc-v7.S +7
-0+ movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + hvc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) +#endif ENTRY(cpu_v7_iciallu_switch_mm) mov r3, #0 mcr p15, 0, r3, c7, c5, 0 @ ICIALLU
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH 10/14 ARM: KVM: invalidate BTB on guest exit for Cortex-A12/A17
In reply to Russell King - ARM LinuxFrom: Marc Zyngier <[email protected]>
In order to avoid aliasing attacks against the branch predictor, let's invalidate the BTB on guest exit. This is made complicated by the fact that we cannot take a branch before invalidating the BTB.
We only apply this to A12 and A17, which are the only two ARM cores on which this useful.
--- arch/arm/include/asm/kvm_asm.h | 2 -- arch/arm/include/asm/kvm_mmu.h | 17 +++++++++- arch/arm/kvm/hyp/hyp-entry.S | 71 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 5 deletions(-)
arch/arm/include/asm/kvm_asm.h +0 -2
@@ -61,8 +61,6 @@ struct kvm_vcpu;extern char __kvm_hyp_init[];extern char __kvm_hyp_init_end[]; -extern char __kvm_hyp_vector[]; -extern void __kvm_flush_vm_context (void );extern void __kvm_tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa);extern void __kvm_tlb_flush_vmid (struct kvm *kvm);
arch/arm/include/asm/kvm_mmu.h +16 -1
@@ -297,7 +297,22 @@ static inline unsigned int kvm_get_vmid_bits(void)static inline void *kvm_get_hyp_vector (void ) { -return kvm_ksym_ref (__kvm_hyp_vector); +switch (read_cpuid_part ()) { +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +case ARM_CPU_PART_CORTEX_A12 : +case ARM_CPU_PART_CORTEX_A17 : + { +extern char __kvm_hyp_vector_bp_inv[]; +return kvm_ksym_ref (__kvm_hyp_vector_bp_inv); + } + +#endif +default : + { +extern char __kvm_hyp_vector[]; +return kvm_ksym_ref (__kvm_hyp_vector); + } + } }static inline int kvm_map_vectors (void )
arch/arm/kvm/hyp/hyp-entry.S +69 -2
89 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 11/14 ARM: KVM: invalidate icache on guest exit for Cortex-A15
In reply to Russell King - ARM LinuxFrom: Marc Zyngier <[email protected]>
In order to avoid aliasing attacks against the branch predictor on Cortex-A15, let's invalidate the BTB on guest exit, which can only be done by invalidating the icache (with ACTLR[0] being set).
We use the same hack as for A12/A17 to perform the vector decoding.
--- arch/arm/include/asm/kvm_mmu.h | 5 +++++ arch/arm/kvm/hyp/hyp-entry.S | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+)
arch/arm/include/asm/kvm_mmu.h +5 -0
@@ -306,6 +306,11 @@ static inline void *kvm_get_hyp_vector(void) return kvm_ksym_ref(__kvm_hyp_vector_bp_inv); } +case ARM_CPU_PART_CORTEX_A15 : + { +extern char __kvm_hyp_vector_ic_inv[]; +return kvm_ksym_ref (__kvm_hyp_vector_ic_inv); + }#endif default : {
arch/arm/kvm/hyp/hyp-entry.S +24 -0
@@ -73,6 +73,28 @@ #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR .align 5 +__kvm_hyp_vector_ic_inv: + .global __kvm_hyp_vector_ic_inv + + /* + * We encode the exception entry in the bottom 3 bits of + * SP, and we have to guarantee to be 8 bytes aligned. + */ + W(add) sp, sp, #1 /* Reset 7 */ + W(add) sp, sp, #1 /* Undef 6 */ + W(add) sp, sp, #1 /* Syscall 5 */ + W(add) sp, sp, #1 /* Prefetch abort 4 */ + W(add) sp, sp, #1 /* Data abort 3 */ + W(add) sp, sp, #1 /* HVC 2 */ + W(add) sp, sp, #1 /* IRQ 1 */ + W(nop) /* FIQ 0 */ + + mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */ + isb + + b decode_vectors + + .align 5 __kvm_hyp_vector_bp_inv: .global __kvm_hyp_vector_bp_inv
@@ -92,6 +114,8 @@ mcr p15, 0, r0, c7, c5, 6 /* BPIALL */ isb +decode_vectors: + #ifdef CONFIG_THUMB2_KERNEL /* * Yet another silly hack: Use VPIDR as a temp register.
Signature · 1 line
2.7.4
PATCH 12/14 ARM: spectre-v2: KVM: invalidate icache on guest exit for Brahma B15
In reply to Russell King - ARM LinuxInclude Brahma B15 in the Spectre v2 KVM workarounds.
--- arch/arm/include/asm/kvm_mmu.h | 1 + 1 file changed, 1 insertion(+)
arch/arm/include/asm/kvm_mmu.h +1 -0
@@ -306,6 +306,7 @@ static inline void *kvm_get_hyp_vector(void)return kvm_ksym_ref (__kvm_hyp_vector_bp_inv); } +case ARM_CPU_PART_BRAHMA_B15 :case ARM_CPU_PART_CORTEX_A15 : {extern char __kvm_hyp_vector_ic_inv[];
Signature · 1 line
2.7.4
Re: [PATCH 12/14] ARM: spectre-v2: KVM: invalidate icache on guest exit for Brahma B15
Quoted 3 lines · Russell King
Include Brahma B15 in the Spectre v2 KVM workarounds.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 13/14 ARM: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling
In reply to Russell King - ARM LinuxWe want SMCCC_ARCH_WORKAROUND_1 to be fast. As fast as possible. So let's intercept it as early as we can by testing for the function call number as soon as we've identified a HVC call coming from the guest.
--- arch/arm/kvm/hyp/hyp-entry.S | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
arch/arm/kvm/hyp/hyp-entry.S +12 -1
@@ -16,6 +16,7 @@ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <linux/arm-smccc.h> #include <linux/linkage.h> #include <asm/kvm_arm.h> #include <asm/kvm_asm.h>
@@ -202,7 +203,7 @@ ENDPROC(__hyp_do_panic) lsr r2, r2, #16 and r2, r2, #0xff cmp r2, #0 - bne guest_trap @ Guest called HVC + bne guest_hvc_trap @ Guest called HVC /* * Getting here means host called HVC, we shift parameters and branch
@@ -253,6 +254,16 @@ THUMB( orr lr, #1) pop {r2, lr} eret +guest_hvc_trap: + movw ip, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt ip, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + ldr r0, [sp] @ Guest's r0 + teq r0, ip + bne guest_trap + pop {r0, r1, r2} + mov r0, #0 + eret + guest_trap: load_vcpu r0 @ Load VCPU pointer to r0
Signature · 1 line
2.7.4
PATCH 14/14 ARM: KVM: report support for SMCCC_ARCH_WORKAROUND_1
In reply to Russell King - ARM LinuxReport support for SMCCC_ARCH_WORKAROUND_1 to KVM guests for affected CPUs.
--- arch/arm/include/asm/kvm_host.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_host.h +12 -2
@@ -21,6 +21,7 @@#include <linux/types.h> #include <linux/kvm_types.h> +#include <asm/cputype.h> #include <asm/kvm.h> #include <asm/kvm_asm.h> #include <asm/kvm_mmio.h>
@@ -311,8 +312,17 @@ static inline void kvm_arm_vhe_guest_exit(void) {}static inline bool kvm_arm_harden_branch_predictor (void ) { -/* No way to detect it yet, pretend it is not there. */ -return false; +switch (read_cpuid_part ()) { +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +case ARM_CPU_PART_BRAHMA_B15 : +case ARM_CPU_PART_CORTEX_A12 : +case ARM_CPU_PART_CORTEX_A15 : +case ARM_CPU_PART_CORTEX_A17 : +return true; +#endif +default : +return false; + } }#endif /* __ARM_KVM_HOST_H__ */
Signature · 1 line
2.7.4