Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Fuad Tabba <fuad.tabba@linux.dev>
To: kvm@vger.kernel.org
Cc: kvmarm@lists.linux.dev, Will Deacon <will@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Andre Przywara <andre.przywara@arm.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	Marc Zyngier <maz@kernel.org>, Fuad Tabba <tabba@google.com>
Subject: [PATCH] arm64: Query per-VM capabilities when selecting vCPU features
Date: Tue, 14 Jul 2026 12:03:29 +0100	[thread overview]
Message-ID: <20260714110329.12113-1-fuad.tabba@linux.dev> (raw)

kvm_cpu__select_features() and kvm_cpu__configure_features() probe vCPU
feature availability with kvm__supports_extension(), which issues
KVM_CHECK_EXTENSION on the global /dev/kvm fd. That reports the host's
raw capabilities, unaware of any per-VM restrictions.

Protected VMs support a subset of the host's features. The kernel
reflects this on the VM fd (commit a3163dca4817 ("KVM: arm64: Use KVM
extension checks for allowed protected VM capabilities")), while the
global fd still advertises capabilities such as SVE that the VM cannot
use. kvmtool then requests SVE in KVM_ARM_VCPU_INIT, which the kernel
rejects.

Query these capabilities on the VM fd via kvm__supports_vm_extension().
More generally, vCPU feature availability is a per-VM property and is
better checked against the VM fd than the global one.

Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 arm64/kvm-cpu.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arm64/kvm-cpu.c b/arm64/kvm-cpu.c
index ae5a6eb..3aa7684 100644
--- a/arm64/kvm-cpu.c
+++ b/arm64/kvm-cpu.c
@@ -53,34 +53,34 @@ int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 static void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init)
 {
 	if (kvm->cfg.arch.aarch32_guest) {
-		if (!kvm__supports_extension(kvm, KVM_CAP_ARM_EL1_32BIT))
+		if (!kvm__supports_vm_extension(kvm, KVM_CAP_ARM_EL1_32BIT))
 			die("32bit guests are not supported\n");
 		init->features[0] |= 1UL << KVM_ARM_VCPU_EL1_32BIT;
 	}
 
 	if (kvm->cfg.arch.has_pmuv3) {
-		if (!kvm__supports_extension(kvm, KVM_CAP_ARM_PMU_V3))
+		if (!kvm__supports_vm_extension(kvm, KVM_CAP_ARM_PMU_V3))
 			die("PMUv3 is not supported");
 		init->features[0] |= 1UL << KVM_ARM_VCPU_PMU_V3;
 	}
 
 	/* Enable pointer authentication if available */
-	if (kvm__supports_extension(kvm, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
-	    kvm__supports_extension(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC)) {
+	if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+	    kvm__supports_vm_extension(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC)) {
 		init->features[0] |= 1UL << KVM_ARM_VCPU_PTRAUTH_ADDRESS;
 		init->features[0] |= 1UL << KVM_ARM_VCPU_PTRAUTH_GENERIC;
 	}
 
 	/* Enable SVE if available */
-	if (kvm__supports_extension(kvm, KVM_CAP_ARM_SVE))
+	if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE))
 		init->features[0] |= 1UL << KVM_ARM_VCPU_SVE;
 
 	if (kvm->cfg.arch.nested_virt) {
-		if (!kvm__supports_extension(kvm, KVM_CAP_ARM_EL2))
+		if (!kvm__supports_vm_extension(kvm, KVM_CAP_ARM_EL2))
 			die("EL2 (nested virt) is not supported");
 		init->features[0] |= 1UL << KVM_ARM_VCPU_HAS_EL2;
 		if (kvm->cfg.arch.e2h0) {
-			if (!kvm__supports_extension(kvm, KVM_CAP_ARM_EL2_E2H0))
+			if (!kvm__supports_vm_extension(kvm, KVM_CAP_ARM_EL2_E2H0))
 				die("FEAT_E2H0 is not supported");
 			init->features[0] |= 1UL << KVM_ARM_VCPU_HAS_EL2_E2H0;
 		}
@@ -123,7 +123,7 @@ static int vcpu_configure_sve(struct kvm_cpu *vcpu)
 
 static int kvm_cpu__configure_features(struct kvm_cpu *vcpu)
 {
-	if (kvm__supports_extension(vcpu->kvm, KVM_CAP_ARM_SVE))
+	if (kvm__supports_vm_extension(vcpu->kvm, KVM_CAP_ARM_SVE))
 		return vcpu_configure_sve(vcpu);
 
 	return 0;
-- 
2.39.5


             reply	other threads:[~2026-07-14 11:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 11:03 Fuad Tabba [this message]
2026-07-14 11:15 ` [PATCH] arm64: Query per-VM capabilities when selecting vCPU features Suzuki K Poulose

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=20260714110329.12113-1-fuad.tabba@linux.dev \
    --to=fuad.tabba@linux.dev \
    --cc=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    /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