Skip to content

Commit 2de21fb

Browse files
ouptonMarc Zyngier
authored andcommitted
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>
1 parent 05c93cb commit 2de21fb

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

tools/testing/selftests/kvm/arm64/smccc_filter.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ enum smccc_conduit {
2222
SMC_INSN,
2323
};
2424

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+
2536
#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++)
2739

2840
static void guest_main(uint32_t func_id, enum smccc_conduit conduit)
2941
{

tools/testing/selftests/kvm/include/arm64/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ void wfi(void);
303303
void test_wants_mte(void);
304304
void test_disable_default_vgic(void);
305305

306+
bool vm_supports_el2(struct kvm_vm *vm);
306307
static bool vcpu_has_el2(struct kvm_vcpu *vcpu)
307308
{
308309
return vcpu->init.features[0] & BIT(KVM_ARM_VCPU_HAS_EL2);

tools/testing/selftests/kvm/lib/arm64/processor.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,23 @@ void virt_arch_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent)
267267
}
268268
}
269269

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+
270280
void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init)
271281
{
272282
struct kvm_vcpu_init preferred = {};
273283

274284
vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &preferred);
285+
if (vm_supports_el2(vm))
286+
preferred.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2);
275287

276288
*init = preferred;
277289
}

0 commit comments

Comments
 (0)