Skip to content

Commit ef15090

Browse files
committed
KVM: arm64: Add generic check for system-supported vCPU features
To date KVM has relied on kvm_reset_vcpu() failing when the vCPU feature flags are unsupported by the system. This is a bit messy since kvm_reset_vcpu() is called at runtime outside of the KVM_ARM_VCPU_INIT ioctl when it is expected to succeed. Further complicating the matter is that kvm_reset_vcpu() must tolerate be idemptotent to the config_lock, as it isn't consistently called with the lock held. Prepare to move feature compatibility checks out of kvm_reset_vcpu() with a 'generic' check that compares the user-provided flags with a computed maximum feature set for the system. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent ce9ecca commit ef15090

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

arch/arm64/kvm/arm.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,16 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
11901190
return -EINVAL;
11911191
}
11921192

1193+
static unsigned long system_supported_vcpu_features(void)
1194+
{
1195+
unsigned long features = KVM_VCPU_VALID_FEATURES;
1196+
1197+
if (!cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
1198+
clear_bit(KVM_ARM_VCPU_EL1_32BIT, &features);
1199+
1200+
return features;
1201+
}
1202+
11931203
static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
11941204
const struct kvm_vcpu_init *init)
11951205
{
@@ -1204,12 +1214,12 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
12041214
return -ENOENT;
12051215
}
12061216

1217+
if (features & ~system_supported_vcpu_features())
1218+
return -EINVAL;
1219+
12071220
if (!test_bit(KVM_ARM_VCPU_EL1_32BIT, &features))
12081221
return 0;
12091222

1210-
if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1))
1211-
return -EINVAL;
1212-
12131223
/* MTE is incompatible with AArch32 */
12141224
if (kvm_has_mte(vcpu->kvm))
12151225
return -EINVAL;

0 commit comments

Comments
 (0)