Commit baa28a53 authored by Oliver Upton's avatar Oliver Upton

KVM: arm64: Hoist PAuth checks into KVM_ARM_VCPU_INIT ioctl

Test for feature support in the ioctl handler rather than
kvm_reset_vcpu(). Continue to uphold our all-or-nothing policy with
address and generic pointer authentication.

Link: https://lore.kernel.org/r/20230920195036.1169791-5-oliver.upton@linux.devSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
parent be9c0c01
...@@ -1203,6 +1203,11 @@ static unsigned long system_supported_vcpu_features(void) ...@@ -1203,6 +1203,11 @@ static unsigned long system_supported_vcpu_features(void)
if (!system_supports_sve()) if (!system_supports_sve())
clear_bit(KVM_ARM_VCPU_SVE, &features); clear_bit(KVM_ARM_VCPU_SVE, &features);
if (!system_has_full_ptr_auth()) {
clear_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, &features);
clear_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, &features);
}
return features; return features;
} }
...@@ -1223,6 +1228,14 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu, ...@@ -1223,6 +1228,14 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
if (features & ~system_supported_vcpu_features()) if (features & ~system_supported_vcpu_features())
return -EINVAL; return -EINVAL;
/*
* For now make sure that both address/generic pointer authentication
* features are requested by the userspace together.
*/
if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, &features) !=
test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, &features))
return -EINVAL;
if (!test_bit(KVM_ARM_VCPU_EL1_32BIT, &features)) if (!test_bit(KVM_ARM_VCPU_EL1_32BIT, &features))
return 0; return 0;
......
...@@ -165,20 +165,9 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu) ...@@ -165,20 +165,9 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)
memset(vcpu->arch.sve_state, 0, vcpu_sve_state_size(vcpu)); memset(vcpu->arch.sve_state, 0, vcpu_sve_state_size(vcpu));
} }
static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu) static void kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)
{ {
/*
* For now make sure that both address/generic pointer authentication
* features are requested by the userspace together and the system
* supports these capabilities.
*/
if (!test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
!test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features) ||
!system_has_full_ptr_auth())
return -EINVAL;
vcpu_set_flag(vcpu, GUEST_HAS_PTRAUTH); vcpu_set_flag(vcpu, GUEST_HAS_PTRAUTH);
return 0;
} }
/** /**
...@@ -233,12 +222,8 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) ...@@ -233,12 +222,8 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
} }
if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) || if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features)) { test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features))
if (kvm_vcpu_enable_ptrauth(vcpu)) { kvm_vcpu_enable_ptrauth(vcpu);
ret = -EINVAL;
goto out;
}
}
if (vcpu_el1_is_32bit(vcpu)) if (vcpu_el1_is_32bit(vcpu))
pstate = VCPU_RESET_PSTATE_SVC; pstate = VCPU_RESET_PSTATE_SVC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment