On Sat, 01 Jun 2024 00:13:50 +0100, Oliver Upton <oliver.upton@xxxxxxxxx> wrote: > > Round out the ZCR_EL2 gymnastics by loading SVE state in the fast path > when the guest hypervisor tries to access SVE state. > > Signed-off-by: Oliver Upton <oliver.upton@xxxxxxxxx> > --- > arch/arm64/kvm/hyp/include/hyp/switch.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 428ee15dd6ae..5872eaafc7f0 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -345,6 +345,10 @@ static 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; > @@ -520,6 +524,22 @@ static bool handle_ampere1_tcr(struct kvm_vcpu *vcpu) > return true; > } > > +static bool kvm_hyp_handle_zcr(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; > + > + return kvm_hyp_handle_fpsimd(vcpu, exit_code); For my own understanding of the flow: let's say the L1 guest accesses ZCR_EL2 while the host own the FP regs: - ZCR_EL2 traps - we restore the guest's state, enable SVE - ZCR_EL2 traps again - emulate the access on the slow path In contrast, the same thing using ZCR_EL1 in L1 results in: - ZCR_EL1 traps - we restore the guest's state, enable SVE and we're done. Is that correct? If so, a comment would help... ;-) > +} > + > static bool kvm_hyp_handle_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code) > { > if (cpus_have_final_cap(ARM64_WORKAROUND_CAVIUM_TX2_219_TVM) && > @@ -537,6 +557,9 @@ static bool kvm_hyp_handle_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code) > if (kvm_hyp_handle_cntpct(vcpu)) > return true; > > + if (kvm_hyp_handle_zcr(vcpu, exit_code)) > + return true; > + > return false; > } > Thanks, M. -- Without deviation from the norm, progress is not possible.