Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: Move BP hardening helpers into spectre.h

The BP hardening helpers are an integral part of the Spectre-v2
mitigation, so move them into asm/spectre.h and inline the
arm64_get_bp_hardening_data() function at the same time.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20201113113847.21619-6-will@kernel.org

authored by

Will Deacon and committed by
Marc Zyngier
6279017e 07cf8aa9

+32 -30
-29
arch/arm64/include/asm/mmu.h
··· 12 12 #define USER_ASID_FLAG (UL(1) << USER_ASID_BIT) 13 13 #define TTBR_ASID_MASK (UL(0xffff) << 48) 14 14 15 - #define BP_HARDEN_EL2_SLOTS 4 16 - #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K) 17 - 18 15 #ifndef __ASSEMBLY__ 19 16 20 17 #include <linux/refcount.h> ··· 36 39 static inline bool arm64_kernel_unmapped_at_el0(void) 37 40 { 38 41 return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0); 39 - } 40 - 41 - typedef void (*bp_hardening_cb_t)(void); 42 - 43 - struct bp_hardening_data { 44 - int hyp_vectors_slot; 45 - bp_hardening_cb_t fn; 46 - }; 47 - 48 - DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 49 - 50 - static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 51 - { 52 - return this_cpu_ptr(&bp_hardening_data); 53 - } 54 - 55 - static inline void arm64_apply_bp_hardening(void) 56 - { 57 - struct bp_hardening_data *d; 58 - 59 - if (!cpus_have_const_cap(ARM64_SPECTRE_V2)) 60 - return; 61 - 62 - d = arm64_get_bp_hardening_data(); 63 - if (d->fn) 64 - d->fn(); 65 42 } 66 43 67 44 extern void arm64_memblock_init(void);
+30
arch/arm64/include/asm/spectre.h
··· 9 9 #ifndef __ASM_SPECTRE_H 10 10 #define __ASM_SPECTRE_H 11 11 12 + #define BP_HARDEN_EL2_SLOTS 4 13 + #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K) 14 + 15 + #ifndef __ASSEMBLY__ 16 + 17 + #include <linux/percpu.h> 18 + 12 19 #include <asm/cpufeature.h> 20 + #include <asm/virt.h> 13 21 14 22 /* Watch out, ordering is important here. */ 15 23 enum mitigation_state { ··· 28 20 29 21 struct task_struct; 30 22 23 + typedef void (*bp_hardening_cb_t)(void); 24 + 25 + struct bp_hardening_data { 26 + int hyp_vectors_slot; 27 + bp_hardening_cb_t fn; 28 + }; 29 + 30 + DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 31 + 32 + static inline void arm64_apply_bp_hardening(void) 33 + { 34 + struct bp_hardening_data *d; 35 + 36 + if (!cpus_have_const_cap(ARM64_SPECTRE_V2)) 37 + return; 38 + 39 + d = this_cpu_ptr(&bp_hardening_data); 40 + if (d->fn) 41 + d->fn(); 42 + } 43 + 31 44 enum mitigation_state arm64_get_spectre_v2_state(void); 32 45 bool has_spectre_v2(const struct arm64_cpu_capabilities *cap, int scope); 33 46 void spectre_v2_enable_mitigation(const struct arm64_cpu_capabilities *__unused); ··· 58 29 void spectre_v4_enable_mitigation(const struct arm64_cpu_capabilities *__unused); 59 30 void spectre_v4_enable_task_mitigation(struct task_struct *tsk); 60 31 32 + #endif /* __ASSEMBLY__ */ 61 33 #endif /* __ASM_SPECTRE_H */
+1 -1
arch/arm64/kvm/arm.c
··· 1405 1405 */ 1406 1406 static void cpu_set_hyp_vector(void) 1407 1407 { 1408 - struct bp_hardening_data *data = arm64_get_bp_hardening_data(); 1408 + struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data); 1409 1409 void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector)); 1410 1410 int slot = -1; 1411 1411
+1
arch/arm64/kvm/hyp/hyp-entry.S
··· 13 13 #include <asm/kvm_arm.h> 14 14 #include <asm/kvm_asm.h> 15 15 #include <asm/mmu.h> 16 + #include <asm/spectre.h> 16 17 17 18 .macro save_caller_saved_regs_vect 18 19 /* x0 and x1 were saved in the vector entry */