As part of adding the nested virtualisation support commit 0cfc85b8f5cf3
("KVM: arm64: nv: Load guest FP state for ZCR_EL2 trap") added code
which handles access to ZCR_EL2 from a guest as a SVE access trap.
While the reasoning for this was not specifically articulated in the
commit log it was part of the lazy switching mechanism that we used to
have for ZCR_ELx.  Since commit 59419f10045bc ("KVM: arm64: Eagerly
switch ZCR_EL{1,2}") this mechanism has been removed.  We now switch
ZCR_EL2 in the hypervisor when transitioning between guest and host,
meaning that we no longer need the special casing.

Remove the redundant special casing, this simplifies the code and will
make the implementation of SME support (which architecturally follows a
similar pattern to SVE) easier.  Accesses to ZCR_EL2 from a nested EL2
will use the standard system register access handling path which works
with the in memory copy, and if the FP state is not yet loaded any
floating point operations will cause an access trap which we handle by
loading the state.

Signed-off-by: Mark Brown <[email protected]>
---
 arch/arm64/kvm/hyp/include/hyp/switch.h |  4 ----
 arch/arm64/kvm/hyp/vhe/switch.c         | 27 ---------------------------
 2 files changed, 31 deletions(-)

diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h 
b/arch/arm64/kvm/hyp/include/hyp/switch.h
index 18131e395e24..b4680baffc6e 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -601,10 +601,6 @@ static inline bool kvm_hyp_handle_fpsimd(struct kvm_vcpu 
*vcpu, u64 *exit_code)
                if (guest_hyp_fpsimd_traps_enabled(vcpu))
                        return false;
                break;
-       case ESR_ELx_EC_SYS64:
-               if (WARN_ON_ONCE(!is_hyp_ctxt(vcpu)))
-                       return false;
-               fallthrough;
        case ESR_ELx_EC_SVE:
                if (!sve_guest)
                        return false;
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index bbe9cebd3d9d..625fe81a20b1 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -458,30 +458,6 @@ static bool kvm_hyp_handle_cpacr_el1(struct kvm_vcpu 
*vcpu, u64 *exit_code)
        return true;
 }
 
-static bool kvm_hyp_handle_zcr_el2(struct kvm_vcpu *vcpu, u64 *exit_code)
-{
-       u32 sysreg = esr_sys64_to_sysreg(kvm_vcpu_get_esr(vcpu));
-
-       if (!vcpu_has_nv(vcpu))
-               return false;
-
-       if (sysreg != SYS_ZCR_EL2)
-               return false;
-
-       if (guest_owns_fp_regs())
-               return false;
-
-       /*
-        * ZCR_EL2 traps are handled in the slow path, with the expectation
-        * that the guest's FP context has already been loaded onto the CPU.
-        *
-        * Load the guest's FP context and unconditionally forward to the
-        * slow path for handling (i.e. return false).
-        */
-       kvm_hyp_handle_fpsimd(vcpu, exit_code);
-       return false;
-}
-
 static bool kvm_hyp_handle_sysreg_vhe(struct kvm_vcpu *vcpu, u64 *exit_code)
 {
        if (kvm_hyp_handle_tlbi_el2(vcpu, exit_code))
@@ -493,9 +469,6 @@ static bool kvm_hyp_handle_sysreg_vhe(struct kvm_vcpu 
*vcpu, u64 *exit_code)
        if (kvm_hyp_handle_cpacr_el1(vcpu, exit_code))
                return true;
 
-       if (kvm_hyp_handle_zcr_el2(vcpu, exit_code))
-               return true;
-
        return kvm_hyp_handle_sysreg(vcpu, exit_code);
 }
 

-- 
2.47.3


Reply via email to