@@ -815,6 +815,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;
@@ -13,8 +13,15 @@ static __always_inline bool kvm_supports_spe(void)
{
return static_branch_likely(&kvm_spe_available);
}
+
+int kvm_spe_vcpu_enable_spe(struct kvm_vcpu *vcpu);
#else
#define kvm_supports_spe() (false)
+
+static inline int kvm_spe_vcpu_enable_spe(struct kvm_vcpu *vcpu)
+{
+ return 0;
+}
#endif /* CONFIG_KVM_ARM_SPE */
#endif /* __ARM64_KVM_SPE_H__ */
@@ -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 */
@@ -251,6 +252,13 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
goto out;
}
+ if (kvm_vcpu_has_spe(vcpu)) {
+ if (kvm_spe_vcpu_enable_spe(vcpu)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
switch (vcpu->arch.target) {
default:
if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) {
@@ -7,6 +7,7 @@
#include <linux/kvm_host.h>
#include <linux/perf/arm_spe_pmu.h>
+#include <asm/kvm_emulate.h>
#include <asm/kvm_spe.h>
DEFINE_STATIC_KEY_FALSE(kvm_spe_available);
@@ -26,3 +27,18 @@ void kvm_host_spe_init(struct arm_spe_pmu *spe_pmu)
mutex_unlock(&supported_cpus_lock);
}
+
+int kvm_spe_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;
+}
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/include/asm/kvm_spe.h | 7 +++++++ arch/arm64/kvm/reset.c | 8 ++++++++ arch/arm64/kvm/spe.c | 16 ++++++++++++++++ 4 files changed, 34 insertions(+)