Skip to content

Commit 6279017

Browse files
willdeaconMarc Zyngier
authored andcommitted
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
1 parent 07cf8aa commit 6279017

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

arch/arm64/include/asm/mmu.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#define USER_ASID_FLAG (UL(1) << USER_ASID_BIT)
1313
#define TTBR_ASID_MASK (UL(0xffff) << 48)
1414

15-
#define BP_HARDEN_EL2_SLOTS 4
16-
#define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K)
17-
1815
#ifndef __ASSEMBLY__
1916

2017
#include <linux/refcount.h>
@@ -41,32 +38,6 @@ static inline bool arm64_kernel_unmapped_at_el0(void)
4138
return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
4239
}
4340

44-
typedef void (*bp_hardening_cb_t)(void);
45-
46-
struct bp_hardening_data {
47-
int hyp_vectors_slot;
48-
bp_hardening_cb_t fn;
49-
};
50-
51-
DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
52-
53-
static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void)
54-
{
55-
return this_cpu_ptr(&bp_hardening_data);
56-
}
57-
58-
static inline void arm64_apply_bp_hardening(void)
59-
{
60-
struct bp_hardening_data *d;
61-
62-
if (!cpus_have_const_cap(ARM64_SPECTRE_V2))
63-
return;
64-
65-
d = arm64_get_bp_hardening_data();
66-
if (d->fn)
67-
d->fn();
68-
}
69-
7041
extern void arm64_memblock_init(void);
7142
extern void paging_init(void);
7243
extern void bootmem_init(void);

arch/arm64/include/asm/spectre.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
#ifndef __ASM_SPECTRE_H
1010
#define __ASM_SPECTRE_H
1111

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+
1219
#include <asm/cpufeature.h>
20+
#include <asm/virt.h>
1321

1422
/* Watch out, ordering is important here. */
1523
enum mitigation_state {
@@ -20,6 +28,27 @@ enum mitigation_state {
2028

2129
struct task_struct;
2230

31+
typedef void (*bp_hardening_cb_t)(void);
32+
33+
struct bp_hardening_data {
34+
int hyp_vectors_slot;
35+
bp_hardening_cb_t fn;
36+
};
37+
38+
DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
39+
40+
static inline void arm64_apply_bp_hardening(void)
41+
{
42+
struct bp_hardening_data *d;
43+
44+
if (!cpus_have_const_cap(ARM64_SPECTRE_V2))
45+
return;
46+
47+
d = this_cpu_ptr(&bp_hardening_data);
48+
if (d->fn)
49+
d->fn();
50+
}
51+
2352
enum mitigation_state arm64_get_spectre_v2_state(void);
2453
bool has_spectre_v2(const struct arm64_cpu_capabilities *cap, int scope);
2554
void spectre_v2_enable_mitigation(const struct arm64_cpu_capabilities *__unused);
@@ -29,4 +58,5 @@ bool has_spectre_v4(const struct arm64_cpu_capabilities *cap, int scope);
2958
void spectre_v4_enable_mitigation(const struct arm64_cpu_capabilities *__unused);
3059
void spectre_v4_enable_task_mitigation(struct task_struct *tsk);
3160

61+
#endif /* __ASSEMBLY__ */
3262
#endif /* __ASM_SPECTRE_H */

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ static void cpu_hyp_reset(void)
14051405
*/
14061406
static void cpu_set_hyp_vector(void)
14071407
{
1408-
struct bp_hardening_data *data = arm64_get_bp_hardening_data();
1408+
struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data);
14091409
void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector));
14101410
int slot = -1;
14111411

arch/arm64/kvm/hyp/hyp-entry.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <asm/kvm_arm.h>
1414
#include <asm/kvm_asm.h>
1515
#include <asm/mmu.h>
16+
#include <asm/spectre.h>
1617

1718
.macro save_caller_saved_regs_vect
1819
/* x0 and x1 were saved in the vector entry */

0 commit comments

Comments
 (0)