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 <tabba@google.com>
Bug: 267291591
This commit is contained in:
Fuad Tabba
2023-04-06 12:46:33 +01:00
parent cbe59d40a2
commit 3e3a126ea3
3 changed files with 8 additions and 4 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);