public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oliver.upton@linux.dev>
To: kvmarm@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@redhat.com>,
	linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org,
	Oliver Upton <oliver.upton@linux.dev>
Subject: [PATCH 12/13] KVM: arm64: selftests: Enable EL2 by default
Date: Wed, 17 Sep 2025 14:20:42 -0700	[thread overview]
Message-ID: <20250917212044.294760-13-oliver.upton@linux.dev> (raw)
In-Reply-To: <20250917212044.294760-1-oliver.upton@linux.dev>

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>
---
 tools/testing/selftests/kvm/arm64/smccc_filter.c   | 14 +++++++++++++-
 .../selftests/kvm/include/arm64/processor.h        |  1 +
 tools/testing/selftests/kvm/lib/arm64/processor.c  | 12 ++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/arm64/smccc_filter.c b/tools/testing/selftests/kvm/arm64/smccc_filter.c
index a8e22d866ea7..1763b9d45400 100644
--- a/tools/testing/selftests/kvm/arm64/smccc_filter.c
+++ b/tools/testing/selftests/kvm/arm64/smccc_filter.c
@@ -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)
 {
diff --git a/tools/testing/selftests/kvm/include/arm64/processor.h b/tools/testing/selftests/kvm/include/arm64/processor.h
index f037c1bb8e63..b6b86e2cd59c 100644
--- a/tools/testing/selftests/kvm/include/arm64/processor.h
+++ b/tools/testing/selftests/kvm/include/arm64/processor.h
@@ -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);
diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
index 4339de2fc482..74324915b41e 100644
--- a/tools/testing/selftests/kvm/lib/arm64/processor.c
+++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
@@ -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;
 }
-- 
2.47.3


  parent reply	other threads:[~2025-09-17 21:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17 21:20 [PATCH 00/13] KVM: arm64: selftests: Run selftests in VHE EL2 Oliver Upton
2025-09-17 21:20 ` [PATCH 01/13] KVM: arm64: selftests: Provide kvm_arch_vm_post_create() in library code Oliver Upton
2025-09-18  1:25   ` Itaru Kitayama
2025-09-17 21:20 ` [PATCH 02/13] KVM: arm64: selftests: Initialize VGICv3 only once Oliver Upton
2025-09-18 10:44   ` Zenghui Yu
2025-09-17 21:20 ` [PATCH 03/13] KVM: arm64: selftests: Add helper to check for VGICv3 support Oliver Upton
2025-09-18  1:45   ` Itaru Kitayama
2025-09-17 21:20 ` [PATCH 04/13] KVM: arm64: selftests: Add unsanitised helpers for VGICv3 creation Oliver Upton
2025-09-17 21:20 ` [PATCH 05/13] KVM: arm64: selftests: Create a VGICv3 for 'default' VMs Oliver Upton
2025-09-17 21:20 ` [PATCH 06/13] KVM: arm64: selftests: Alias EL1 registers to EL2 counterparts Oliver Upton
2025-09-17 21:20 ` [PATCH 07/13] KVM: arm64: selftests: Provide helper for getting default vCPU target Oliver Upton
2025-09-17 21:56   ` Itaru Kitayama
2025-09-17 22:00     ` Oliver Upton
2025-09-17 21:20 ` [PATCH 08/13] KVM: arm64: selftests: Select SMCCC conduit based on current EL Oliver Upton
2025-09-17 21:20 ` [PATCH 09/13] KVM: arm64: selftests: Use hyp timer IRQs when test runs at EL2 Oliver Upton
2025-09-17 21:20 ` [PATCH 10/13] KVM: arm64: selftests: Use the vCPU attr for setting nr of PMU counters Oliver Upton
2025-09-17 21:20 ` [PATCH 11/13] KVM: arm64: selftests: Initialize HCR_EL2 Oliver Upton
2025-09-17 21:20 ` Oliver Upton [this message]
2025-09-17 21:20 ` [PATCH 13/13] KVM: arm64: selftests: Add basic test for running in VHE EL2 Oliver Upton
2025-09-24 18:37 ` [PATCH 00/13] KVM: arm64: selftests: Run selftests " Marc Zyngier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250917212044.294760-13-oliver.upton@linux.dev \
    --to=oliver.upton@linux.dev \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox