@@ -807,6 +807,9 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
#define kvm_vcpu_has_pmu(vcpu) \
(test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
+#define kvm_vcpu_has_spe(vcpu) \
+ (test_bit(KVM_ARM_VCPU_SPE, (vcpu)->arch.features))
+
int kvm_trng_call(struct kvm_vcpu *vcpu);
#ifdef CONFIG_KVM
extern phys_addr_t hyp_mem_base;
@@ -27,6 +27,7 @@
#include <asm/kvm_asm.h>
#include <asm/kvm_emulate.h>
#include <asm/kvm_mmu.h>
+#include <asm/kvm_spe.h>
#include <asm/virt.h>
/* Maximum phys_shift supported for any VM on this host */
@@ -189,6 +190,21 @@ static bool vcpu_allowed_register_width(struct kvm_vcpu *vcpu)
return true;
}
+static int kvm_vcpu_enable_spe(struct kvm_vcpu *vcpu)
+{
+ if (!kvm_supports_spe())
+ return -EINVAL;
+
+ /*
+ * The Profiling Buffer is disabled if the owning Exception level is
+ * aarch32.
+ */
+ if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT))
+ return -EINVAL;
+
+ return 0;
+}
+
/**
* kvm_reset_vcpu - sets core registers and sys_regs to reset value
* @vcpu: The VCPU pointer
@@ -245,6 +261,13 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
goto out;
}
+ if (kvm_vcpu_has_spe(vcpu)) {
+ if (kvm_vcpu_enable_spe(vcpu)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
switch (vcpu->arch.target) {
default:
if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) {
Check that KVM SPE emulation is supported before allowing userspace to set the KVM_ARM_VCPU_SPE feature. According to ARM DDI 0487G.a, page D9-2946 the Profiling Buffer is disabled if the owning Exception level is 32 bit, reject the SPE feature if the VCPU's execution state at EL1 is aarch32. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> --- arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/reset.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+)