ANDROID: KVM: arm64: Initialize ptr auth in protected mode

Ensure that pointer authentication is initialized when the vcpu
is initialized as well, and not only when the vcpu is reset.

Bug: 249192647
Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: Ida39a3ee5e6b4b0d3255bfef95601890afd80709
This commit is contained in:
Fuad Tabba
2022-09-28 11:24:05 +01:00
parent 5405862223
commit 8b49e4bee6

View File

@@ -414,6 +414,15 @@ static int set_host_vcpus(struct shadow_vcpu_state *shadow_vcpus, int nr_vcpus,
return 0;
}
static int init_ptrauth(struct kvm_vcpu *shadow_vcpu)
{
int ret = 0;
if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, shadow_vcpu->arch.features) ||
test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, shadow_vcpu->arch.features))
ret = kvm_vcpu_enable_ptrauth(shadow_vcpu);
return ret;
}
static int init_shadow_structs(struct kvm *kvm, struct kvm_shadow_vm *vm,
struct kvm_vcpu **vcpu_array, int nr_vcpus)
{
@@ -438,6 +447,10 @@ static int init_shadow_structs(struct kvm *kvm, struct kvm_shadow_vm *vm,
if (ret)
return ret;
ret = init_ptrauth(shadow_vcpu);
if (ret)
return ret;
if (test_bit(KVM_ARM_VCPU_SVE, shadow_vcpu->arch.features)) {
size_t sve_state_size;
void *sve_state;
@@ -851,14 +864,7 @@ void pkvm_reset_vcpu(struct kvm_vcpu *vcpu)
WARN_ON(!reset_state->reset);
if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features)) {
/*
* This call should not fail since we've already checked for
* feature support on initialization.
*/
WARN_ON(kvm_vcpu_enable_ptrauth(vcpu));
}
init_ptrauth(vcpu);
/* Reset core registers */
memset(vcpu_gp_regs(vcpu), 0, sizeof(*vcpu_gp_regs(vcpu)));