]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: selftests: Enable EL2 by default
authorOliver Upton <oliver.upton@linux.dev>
Wed, 17 Sep 2025 21:20:42 +0000 (14:20 -0700)
committerMarc Zyngier <maz@kernel.org>
Wed, 24 Sep 2025 18:23:32 +0000 (19:23 +0100)
Take advantage of VHE to implicitly promote KVM selftests to run at EL2
with only slight modification. Update the smccc_filter test to account
for this now that the EL2-ness of a VM is visible to tests.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/arm64/smccc_filter.c
tools/testing/selftests/kvm/include/arm64/processor.h
tools/testing/selftests/kvm/lib/arm64/processor.c

index a8e22d866ea7a0762dcfca7652d297cef350e402..1763b9d45400b3e8fedc44b12ce976155ddd07fc 100644 (file)
@@ -22,8 +22,20 @@ enum smccc_conduit {
        SMC_INSN,
 };
 
+static bool test_runs_at_el2(void)
+{
+       struct kvm_vm *vm = vm_create(1);
+       struct kvm_vcpu_init init;
+
+       kvm_get_default_vcpu_target(vm, &init);
+       kvm_vm_free(vm);
+
+       return init.features[0] & BIT(KVM_ARM_VCPU_HAS_EL2);
+}
+
 #define for_each_conduit(conduit)                                      \
-       for (conduit = HVC_INSN; conduit <= SMC_INSN; conduit++)
+       for (conduit = test_runs_at_el2() ? SMC_INSN : HVC_INSN;        \
+            conduit <= SMC_INSN; conduit++)
 
 static void guest_main(uint32_t func_id, enum smccc_conduit conduit)
 {
index f037c1bb8e6328b4b087705f3707dd61d9fcc331..b6b86e2cd59ce2d46cba08916166a7a8ec1cfa08 100644 (file)
@@ -303,6 +303,7 @@ void wfi(void);
 void test_wants_mte(void);
 void test_disable_default_vgic(void);
 
+bool vm_supports_el2(struct kvm_vm *vm);
 static bool vcpu_has_el2(struct kvm_vcpu *vcpu)
 {
        return vcpu->init.features[0] & BIT(KVM_ARM_VCPU_HAS_EL2);
index 4339de2fc482f3a853c2b2414047245c9e1da37a..74324915b41e3cbcfb1b3594b8359306590ae0e3 100644 (file)
@@ -267,11 +267,23 @@ void virt_arch_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent)
        }
 }
 
+bool vm_supports_el2(struct kvm_vm *vm)
+{
+       const char *value = getenv("NV");
+
+       if (value && *value == '0')
+               return false;
+
+       return vm_check_cap(vm, KVM_CAP_ARM_EL2) && vm->arch.has_gic;
+}
+
 void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init)
 {
        struct kvm_vcpu_init preferred = {};
 
        vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &preferred);
+       if (vm_supports_el2(vm))
+               preferred.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2);
 
        *init = preferred;
 }