KVM: arm64: Fix early exit ptrauth handling
authorMarc Zyngier <maz@kernel.org>
Wed, 13 Oct 2021 12:03:36 +0000 (13:03 +0100)
committerMarc Zyngier <maz@kernel.org>
Mon, 18 Oct 2021 15:57:08 +0000 (16:57 +0100)
The previous rework of the early exit code to provide an EC-based
decoding tree missed the fact that we have two trap paths for
ptrauth: the instructions (EC_PAC) and the sysregs (EC_SYS64).

Rework the handlers to call the ptrauth handling code on both
paths.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Link: https://lore.kernel.org/r/20211013120346.2926621-2-maz@kernel.org
arch/arm64/kvm/hyp/include/hyp/switch.h

index 481399b..4126926 100644 (file)
@@ -282,14 +282,6 @@ static inline bool handle_tx2_tvm(struct kvm_vcpu *vcpu)
 
 static inline bool esr_is_ptrauth_trap(u32 esr)
 {
-       u32 ec = ESR_ELx_EC(esr);
-
-       if (ec == ESR_ELx_EC_PAC)
-               return true;
-
-       if (ec != ESR_ELx_EC_SYS64)
-               return false;
-
        switch (esr_sys64_to_sysreg(esr)) {
        case SYS_APIAKEYLO_EL1:
        case SYS_APIAKEYHI_EL1:
@@ -323,8 +315,7 @@ static bool kvm_hyp_handle_ptrauth(struct kvm_vcpu *vcpu, u64 *exit_code)
        struct kvm_cpu_context *ctxt;
        u64 val;
 
-       if (!vcpu_has_ptrauth(vcpu) ||
-           !esr_is_ptrauth_trap(kvm_vcpu_get_esr(vcpu)))
+       if (!vcpu_has_ptrauth(vcpu))
                return false;
 
        ctxt = this_cpu_ptr(&kvm_hyp_ctxt);
@@ -353,6 +344,9 @@ static bool kvm_hyp_handle_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code)
            __vgic_v3_perform_cpuif_access(vcpu) == 1)
                return true;
 
+       if (esr_is_ptrauth_trap(kvm_vcpu_get_esr(vcpu)))
+               return kvm_hyp_handle_ptrauth(vcpu, exit_code);
+
        return false;
 }