From 3e3a126ea3cffc1ce5c1caa3774f90317405bf70 Mon Sep 17 00:00:00 2001 From: Fuad Tabba Date: Thu, 6 Apr 2023 12:46:33 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Factor out logic for setting SVE vector length at hyp Factor out the logic for setting the SVE vector length at the hypervisor in pKVM to the maximum hardware supported value when saving and restoring host SVE state. This shares common code, and elides an unused variable warning when SVE is not configured. Change-Id: Ibaa58e5bb44e4f85b9548a6abb498f0a769f6a4b Signed-off-by: Fuad Tabba Bug: 267291591 --- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 6 ++++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 3 +-- arch/arm64/kvm/hyp/nvhe/switch.c | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h index c56db3d918ab..9eba06503704 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h @@ -152,6 +152,12 @@ static inline bool pkvm_ipa_range_has_pvmfw(struct pkvm_hyp_vm *vm, return ipa_end > pkvm->pvmfw_load_addr && ipa_start < pvmfw_load_end; } +static inline void pkvm_set_max_sve_vq(void) +{ + sve_cond_update_zcr_vq(sve_vq_from_vl(kvm_host_sve_max_vl) - 1, + SYS_ZCR_EL2); +} + int pkvm_load_pvmfw_pages(struct pkvm_hyp_vm *vm, u64 ipa, phys_addr_t phys, u64 size); void pkvm_poison_pvmfw_pages(void); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 4c5ff40ccdc9..c854d1f674e5 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -688,10 +688,9 @@ static void fpsimd_host_restore(void) if (system_supports_sve()) { struct kvm_host_sve_state *sve_state = get_host_sve_state(vcpu); - u64 vq_len = sve_vq_from_vl(kvm_host_sve_max_vl) - 1; write_sysreg_el1(sve_state->zcr_el1, SYS_ZCR); - sve_cond_update_zcr_vq(vq_len, SYS_ZCR_EL2); + pkvm_set_max_sve_vq(); __sve_restore_state(sve_state->sve_regs + sve_ffr_offset(kvm_host_sve_max_vl), &sve_state->fpsr); diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index c98dcd1b05d6..553fa769ea35 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -199,10 +199,9 @@ static void kvm_hyp_handle_fpsimd_host(struct kvm_vcpu *vcpu) */ if (unlikely(is_protected_kvm_enabled() && system_supports_sve())) { struct kvm_host_sve_state *sve_state = get_host_sve_state(vcpu); - u64 vq_len = sve_vq_from_vl(kvm_host_sve_max_vl) - 1; sve_state->zcr_el1 = read_sysreg_el1(SYS_ZCR); - sve_cond_update_zcr_vq(vq_len, SYS_ZCR_EL2); + pkvm_set_max_sve_vq(); __sve_save_state(sve_state->sve_regs + sve_ffr_offset(kvm_host_sve_max_vl), &sve_state->fpsr);