From d871a6444c978a769e7b97c71e5b1a1ad843eacc Mon Sep 17 00:00:00 2001 From: Fuad Tabba Date: Thu, 1 May 2025 13:21:50 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Move __deactivate_fpsimd_traps() to switch.h Move __deactivate_fpsimd_traps() to the shared switch header, instead of having separate implementations in the vhe/nvhe switch.c files. Subsequent patches will remove all specific implementations from switch.c and include switch.h in other files. Bug: 411040189 Change-Id: I42c545e939b230366fbd9ad8e41a614193169bce Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/hyp/switch.h | 22 +++++++++++++++++++++- arch/arm64/kvm/hyp/nvhe/switch.c | 12 ------------ arch/arm64/kvm/hyp/vhe/switch.c | 10 ---------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index efcfd44e7012..087a3cef4116 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -193,7 +193,27 @@ static void kvm_hyp_handle_fpsimd_host(struct kvm_vcpu *vcpu) } } -static void __deactivate_fpsimd_traps(struct kvm_vcpu *vcpu); +static void __deactivate_fpsimd_traps(struct kvm_vcpu *vcpu) +{ + if (has_vhe()) { + u64 reg = CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN; + + if (vcpu_has_sve(vcpu)) + reg |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN; + + sysreg_clear_set(cpacr_el1, 0, reg); + + } else { + u64 reg = CPTR_EL2_TFP; + + if (vcpu_has_sve(vcpu) || + (is_protected_kvm_enabled() && system_supports_sve())) { + reg |= CPTR_EL2_TZ; + } + + sysreg_clear_set(cptr_el2, reg, 0); + } +} /* * We trap the first access to the FP/SIMD to save the host context and diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 8240ae1ebeb3..f1890454628d 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -108,18 +108,6 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) write_sysreg(__kvm_hyp_host_vector, vbar_el2); } -static void __deactivate_fpsimd_traps(struct kvm_vcpu *vcpu) -{ - u64 reg = CPTR_EL2_TFP; - - if (vcpu_has_sve(vcpu) || - (is_protected_kvm_enabled() && system_supports_sve())) { - reg |= CPTR_EL2_TZ; - } - - sysreg_clear_set(cptr_el2, reg, 0); -} - /* Save VGICv3 state on non-VHE systems */ static void __hyp_vgic_save_state(struct kvm_vcpu *vcpu) { diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index b9c8cd61ec7a..45ac4a59cc2c 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -102,16 +102,6 @@ void deactivate_traps_vhe_put(struct kvm_vcpu *vcpu) __deactivate_traps_common(vcpu); } -static void __deactivate_fpsimd_traps(struct kvm_vcpu *vcpu) -{ - u64 reg = CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN; - - if (vcpu_has_sve(vcpu)) - reg |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN; - - sysreg_clear_set(cpacr_el1, 0, reg); -} - static const exit_handler_fn hyp_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = NULL, [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32,