Commit 2de21fb6 authored by Oliver Upton's avatar Oliver Upton Committed by Marc Zyngier
Browse files

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: default avatarOliver Upton <oliver.upton@linux.dev>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent 05c93cbe
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -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)
{
+1 −0
Original line number Diff line number Diff line
@@ -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);
+12 −0
Original line number Diff line number Diff line
@@ -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;
}