Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: selftests: Enable EL2 by default

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>

authored by

Oliver Upton and committed by
Marc Zyngier
2de21fb6 05c93cbe

+26 -1
+13 -1
tools/testing/selftests/kvm/arm64/smccc_filter.c
··· 22 22 SMC_INSN, 23 23 }; 24 24 25 + static bool test_runs_at_el2(void) 26 + { 27 + struct kvm_vm *vm = vm_create(1); 28 + struct kvm_vcpu_init init; 29 + 30 + kvm_get_default_vcpu_target(vm, &init); 31 + kvm_vm_free(vm); 32 + 33 + return init.features[0] & BIT(KVM_ARM_VCPU_HAS_EL2); 34 + } 35 + 25 36 #define for_each_conduit(conduit) \ 26 - for (conduit = HVC_INSN; conduit <= SMC_INSN; conduit++) 37 + for (conduit = test_runs_at_el2() ? SMC_INSN : HVC_INSN; \ 38 + conduit <= SMC_INSN; conduit++) 27 39 28 40 static void guest_main(uint32_t func_id, enum smccc_conduit conduit) 29 41 {
+1
tools/testing/selftests/kvm/include/arm64/processor.h
··· 303 303 void test_wants_mte(void); 304 304 void test_disable_default_vgic(void); 305 305 306 + bool vm_supports_el2(struct kvm_vm *vm); 306 307 static bool vcpu_has_el2(struct kvm_vcpu *vcpu) 307 308 { 308 309 return vcpu->init.features[0] & BIT(KVM_ARM_VCPU_HAS_EL2);
+12
tools/testing/selftests/kvm/lib/arm64/processor.c
··· 267 267 } 268 268 } 269 269 270 + bool vm_supports_el2(struct kvm_vm *vm) 271 + { 272 + const char *value = getenv("NV"); 273 + 274 + if (value && *value == '0') 275 + return false; 276 + 277 + return vm_check_cap(vm, KVM_CAP_ARM_EL2) && vm->arch.has_gic; 278 + } 279 + 270 280 void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init) 271 281 { 272 282 struct kvm_vcpu_init preferred = {}; 273 283 274 284 vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &preferred); 285 + if (vm_supports_el2(vm)) 286 + preferred.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2); 275 287 276 288 *init = preferred; 277 289 }