KVM: arm64: Prevent unsupported vcpu features for VM types

Prevent unsupported VCPU features for the protected VCPUs. Realms and pVMs
not support 32bit EL1 or NV yet. pKVM doesn't rely on the host vcpu
features for protected VMs and hand picks features while hyp_vcpu is
initialised. Block the features early in the vcpu init if we detect
incompatible features.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://patch.msgid.link/20261007073537.2454351-15-suzuki.poulose@arm.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
This commit is contained in:
Suzuki K Poulose 2026-10-07 08:35:37 +01:00 committed by Marc Zyngier
parent 37d7ea3f81
commit a467f39afc
2 changed files with 15 additions and 3 deletions

View File

@ -42,6 +42,13 @@
#define KVM_VCPU_MAX_FEATURES 10
#define KVM_VCPU_VALID_FEATURES (BIT(KVM_VCPU_MAX_FEATURES) - 1)
/* As dictated by kvm_pkvm_ext_allowed() */
#define KVM_PROTECTED_VCPU_VALID_FEATURES \
(BIT(KVM_ARM_VCPU_POWER_OFF) | \
BIT(KVM_ARM_VCPU_PSCI_0_2) | \
BIT(KVM_ARM_VCPU_PTRAUTH_ADDRESS) | \
BIT(KVM_ARM_VCPU_PTRAUTH_GENERIC))
#define KVM_REQ_SLEEP \
KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
#define KVM_REQ_IRQ_PENDING KVM_ARCH_REQ(1)

View File

@ -1668,9 +1668,14 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
return -EINVAL;
}
static unsigned long system_supported_vcpu_features(void)
static unsigned long system_supported_vcpu_features(struct kvm_vcpu *vcpu)
{
unsigned long features = KVM_VCPU_VALID_FEATURES;
unsigned long features;
if (vcpu->kvm->arch.vm_flavor == VM_PROTECTED_PKVM)
features = KVM_PROTECTED_VCPU_VALID_FEATURES;
else
features = KVM_VCPU_VALID_FEATURES;
if (!cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
clear_bit(KVM_ARM_VCPU_EL1_32BIT, &features);
@ -1708,7 +1713,7 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
return -ENOENT;
}
if (features & ~system_supported_vcpu_features())
if (features & ~system_supported_vcpu_features(vcpu))
return -EINVAL;
/*