[PATCH v2 10/11] KVM: arm64: Save/restore SVE state for nVHE
Marc Zyngier
maz at kernel.org
Thu Mar 18 14:32:27 GMT 2021
On Thu, 18 Mar 2021 14:13:58 +0000,
Will Deacon <will at kernel.org> wrote:
>
> On Thu, Mar 18, 2021 at 12:25:31PM +0000, Marc Zyngier wrote:
> > Implement the SVE save/restore for nVHE, following a similar
> > logic to that of the VHE implementation:
> >
> > - the SVE state is switched on trap from EL1 to EL2
> >
> > - no further changes to ZCR_EL2 occur as long as the guest isn't
> > preempted or exit to userspace
> >
> > - ZCR_EL2 is reset to its default value on the first SVE access from
> > the host EL1, and ZCR_EL1 restored to the default guest value in
> > vcpu_put()
> >
> > Signed-off-by: Marc Zyngier <maz at kernel.org>
> > ---
> > arch/arm64/kvm/fpsimd.c | 10 +++++--
> > arch/arm64/kvm/hyp/include/hyp/switch.h | 37 +++++++++----------------
> > arch/arm64/kvm/hyp/nvhe/switch.c | 4 +--
> > 3 files changed, 23 insertions(+), 28 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c
> > index 14ea05c5134a..5621020b28de 100644
> > --- a/arch/arm64/kvm/fpsimd.c
> > +++ b/arch/arm64/kvm/fpsimd.c
> > @@ -121,11 +121,17 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
> > local_irq_save(flags);
> >
> > if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) {
> > - if (guest_has_sve)
> > + if (guest_has_sve) {
> > __vcpu_sys_reg(vcpu, ZCR_EL1) = read_sysreg_el1(SYS_ZCR);
> >
> > + /* Restore the VL that was saved when bound to the CPU */
> > + if (!has_vhe())
> > + sve_cond_update_zcr_vq(vcpu_sve_max_vq(vcpu) - 1,
> > + SYS_ZCR_EL1);
>
> You end up reading ZCR_EL1 twice here, but it's probably not the end of the
> world.
True, but I'd expect read accesses to ZCR_EL1 to be reasonably fast,
something we can't expect from writes.
>
> Anyway:
>
> Acked-by: Will Deacon <will at kernel.org>
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
More information about the linux-arm-kernel
mailing list