Skip to content

Commit 5bdf343

Browse files
author
James Morse
committed
KVM: arm64: Allow indirect vectors to be used without SPECTRE_V3A
CPUs vulnerable to Spectre-BHB either need to make an SMC-CC firmware call from the vectors, or run a sequence of branches. This gets added to the hyp vectors. If there is no support for arch-workaround-1 in firmware, the indirect vector will be used. kvm_init_vector_slots() only initialises the two indirect slots if the platform is vulnerable to Spectre-v3a. pKVM's hyp_map_vectors() only initialises __hyp_bp_vect_base if the platform is vulnerable to Spectre-v3a. As there are about to more users of the indirect vectors, ensure their entries in hyp_spectre_vector_selector[] are always initialised, and __hyp_bp_vect_base defaults to the regular VA mapping. The Spectre-v3a check is moved to a helper kvm_system_needs_idmapped_vectors(), and merged with the code that creates the hyp mappings. Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 1b33d48 commit 5bdf343

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ static inline void kvm_init_host_cpu_context(struct kvm_cpu_context *cpu_ctxt)
714714
ctxt_sys_reg(cpu_ctxt, MPIDR_EL1) = read_cpuid_mpidr();
715715
}
716716

717+
static inline bool kvm_system_needs_idmapped_vectors(void)
718+
{
719+
return cpus_have_const_cap(ARM64_SPECTRE_V3A);
720+
}
721+
717722
void kvm_arm_vcpu_ptrauth_trap(struct kvm_vcpu *vcpu);
718723

719724
static inline void kvm_arch_hardware_unsetup(void) {}

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,7 @@ static int kvm_init_vector_slots(void)
14911491
base = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs));
14921492
kvm_init_vector_slot(base, HYP_VECTOR_SPECTRE_DIRECT);
14931493

1494-
if (!cpus_have_const_cap(ARM64_SPECTRE_V3A))
1495-
return 0;
1496-
1497-
if (!has_vhe()) {
1494+
if (kvm_system_needs_idmapped_vectors() && !has_vhe()) {
14981495
err = create_hyp_exec_mappings(__pa_symbol(__bp_harden_hyp_vecs),
14991496
__BP_HARDEN_HYP_VECS_SZ, &base);
15001497
if (err)

arch/arm64/kvm/hyp/nvhe/mm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ int hyp_map_vectors(void)
148148
phys_addr_t phys;
149149
void *bp_base;
150150

151-
if (!cpus_have_const_cap(ARM64_SPECTRE_V3A))
151+
if (!kvm_system_needs_idmapped_vectors()) {
152+
__hyp_bp_vect_base = __bp_harden_hyp_vecs;
152153
return 0;
154+
}
153155

154156
phys = __hyp_pa(__bp_harden_hyp_vecs);
155157
bp_base = (void *)__pkvm_create_private_mapping(phys,

0 commit comments

Comments
 (0)