From 55c963e08b2edc506ff27fad3b6b3d67f8270fc7 Mon Sep 17 00:00:00 2001 From: Fuad Tabba Date: Thu, 16 Mar 2023 09:04:58 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Specialize handling of host fpsimd state on EL2 trap n/vhe In subsequent patches, vhe/pKVM(nvhe) will diverge significantly on saving the host fpsimd/sve state when taking a guest fpsimd trap. Add a specialized helper to handle that. No functional change intended. Signed-off-by: Fuad Tabba Bug: 267291591 Change-Id: Ib6b13cafad8bf568694804e3b55e0a5a4fcd70a4 --- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +++- arch/arm64/kvm/hyp/nvhe/switch.c | 5 +++++ arch/arm64/kvm/hyp/vhe/switch.c | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 34ff603d6436..56e37f87e812 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -152,6 +152,8 @@ static inline void __hyp_sve_restore_guest(struct kvm_vcpu *vcpu) write_sysreg_el1(__vcpu_sys_reg(vcpu, ZCR_EL1), SYS_ZCR); } +static void kvm_hyp_handle_fpsimd_host(struct kvm_vcpu *vcpu); + /* * We trap the first access to the FP/SIMD to save the host context and * restore the guest context lazily. @@ -194,7 +196,7 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code) /* Write out the host state if it's in the registers */ if (vcpu->arch.fp_state == FP_STATE_HOST_OWNED) - __fpsimd_save_state(vcpu->arch.host_fpsimd_state); + kvm_hyp_handle_fpsimd_host(vcpu); /* Restore the guest state */ if (sve_guest) diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 101d2ecc8f0b..0615c57d0f03 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -178,6 +178,11 @@ static bool kvm_handle_pvm_sys64(struct kvm_vcpu *vcpu, u64 *exit_code) kvm_handle_pvm_sysreg(vcpu, exit_code)); } +static void kvm_hyp_handle_fpsimd_host(struct kvm_vcpu *vcpu) +{ + __fpsimd_save_state(vcpu->arch.host_fpsimd_state); +} + static const exit_handler_fn hyp_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = NULL, [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32, diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index 4d6e76f82a78..53a18f0846e1 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -102,6 +102,11 @@ void deactivate_traps_vhe_put(struct kvm_vcpu *vcpu) __deactivate_traps_common(vcpu); } +static void kvm_hyp_handle_fpsimd_host(struct kvm_vcpu *vcpu) +{ + __fpsimd_save_state(vcpu->arch.host_fpsimd_state); +} + static const exit_handler_fn hyp_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = NULL, [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32,