Skip to content

Commit 5d81f7d

Browse files
Marc Zyngierctmarinas
authored andcommitted
arm64: KVM: Add ARCH_WORKAROUND_2 discovery through ARCH_FEATURES_FUNC_ID
Now that all our infrastructure is in place, let's expose the availability of ARCH_WORKAROUND_2 to guests. We take this opportunity to tidy up a couple of SMCCC constants. Acked-by: Christoffer Dall <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent b4f18c0 commit 5d81f7d

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

arch/arm/include/asm/kvm_host.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ static inline bool kvm_arm_harden_branch_predictor(void)
315315
return false;
316316
}
317317

318+
#define KVM_SSBD_UNKNOWN -1
319+
#define KVM_SSBD_FORCE_DISABLE 0
320+
#define KVM_SSBD_KERNEL 1
321+
#define KVM_SSBD_FORCE_ENABLE 2
322+
#define KVM_SSBD_MITIGATED 3
323+
324+
static inline int kvm_arm_have_ssbd(void)
325+
{
326+
/* No way to detect it yet, pretend it is not there. */
327+
return KVM_SSBD_UNKNOWN;
328+
}
329+
318330
static inline void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) {}
319331
static inline void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) {}
320332

arch/arm64/include/asm/kvm_host.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,29 @@ static inline bool kvm_arm_harden_branch_predictor(void)
455455
return cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR);
456456
}
457457

458+
#define KVM_SSBD_UNKNOWN -1
459+
#define KVM_SSBD_FORCE_DISABLE 0
460+
#define KVM_SSBD_KERNEL 1
461+
#define KVM_SSBD_FORCE_ENABLE 2
462+
#define KVM_SSBD_MITIGATED 3
463+
464+
static inline int kvm_arm_have_ssbd(void)
465+
{
466+
switch (arm64_get_ssbd_state()) {
467+
case ARM64_SSBD_FORCE_DISABLE:
468+
return KVM_SSBD_FORCE_DISABLE;
469+
case ARM64_SSBD_KERNEL:
470+
return KVM_SSBD_KERNEL;
471+
case ARM64_SSBD_FORCE_ENABLE:
472+
return KVM_SSBD_FORCE_ENABLE;
473+
case ARM64_SSBD_MITIGATED:
474+
return KVM_SSBD_MITIGATED;
475+
case ARM64_SSBD_UNKNOWN:
476+
default:
477+
return KVM_SSBD_UNKNOWN;
478+
}
479+
}
480+
458481
void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu);
459482
void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu);
460483

arch/arm64/kvm/reset.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
122122
/* Reset PMU */
123123
kvm_pmu_vcpu_reset(vcpu);
124124

125+
/* Default workaround setup is enabled (if supported) */
126+
if (kvm_arm_have_ssbd() == KVM_SSBD_KERNEL)
127+
vcpu->arch.workaround_flags |= VCPU_WORKAROUND_2_FLAG;
128+
125129
/* Reset timer */
126130
return kvm_timer_vcpu_reset(vcpu);
127131
}

virt/kvm/arm/psci.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static int kvm_psci_call(struct kvm_vcpu *vcpu)
405405
int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
406406
{
407407
u32 func_id = smccc_get_function(vcpu);
408-
u32 val = PSCI_RET_NOT_SUPPORTED;
408+
u32 val = SMCCC_RET_NOT_SUPPORTED;
409409
u32 feature;
410410

411411
switch (func_id) {
@@ -417,7 +417,21 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
417417
switch(feature) {
418418
case ARM_SMCCC_ARCH_WORKAROUND_1:
419419
if (kvm_arm_harden_branch_predictor())
420-
val = 0;
420+
val = SMCCC_RET_SUCCESS;
421+
break;
422+
case ARM_SMCCC_ARCH_WORKAROUND_2:
423+
switch (kvm_arm_have_ssbd()) {
424+
case KVM_SSBD_FORCE_DISABLE:
425+
case KVM_SSBD_UNKNOWN:
426+
break;
427+
case KVM_SSBD_KERNEL:
428+
val = SMCCC_RET_SUCCESS;
429+
break;
430+
case KVM_SSBD_FORCE_ENABLE:
431+
case KVM_SSBD_MITIGATED:
432+
val = SMCCC_RET_NOT_REQUIRED;
433+
break;
434+
}
421435
break;
422436
}
423437
break;

0 commit comments

Comments
 (0)