[PATCH v1 6/7] KVM: arm64: Eagerly restore host fpsimd/sve state in pKVM

Fuad Tabba tabba at google.com
Mon May 20 00:37:22 PDT 2024


Hi Oliver,

On Fri, May 17, 2024 at 6:09 PM Oliver Upton <oliver.upton at linux.dev> wrote:
>
> Hi Fuad,
>
> On Fri, May 17, 2024 at 02:18:13PM +0100, Fuad Tabba wrote:
> >  static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu)
> >  {
> > -     __fpsimd_save_state(*host_data_ptr(fpsimd_state));
> > +     /*
> > +      * Non-protected kvm relies on the host restoring its sve state.
> > +      * Protected kvm restores the host's sve state as not to reveal that
> > +      * fpsimd was used by a guest nor leak upper sve bits.
> > +      */
> > +     if (unlikely(is_protected_kvm_enabled() && system_supports_sve())) {
> > +             __hyp_sve_save_host();
> > +
> > +             /* Re-enable SVE traps for guests that do not support it. */
> > +             if (!vcpu_has_sve(vcpu))
> > +                     sysreg_clear_set(cptr_el2, 0, CPTR_EL2_TZ);
>
> This doesn't account for hVHE. I wonder we'd be better off abstracting
> CPTR_EL2 behind a helper wherever it gets used in nVHE and translate
> into the VHE-format behind the scenes:

Right! Too many modes to keep track of :)

Abstracting cptr_el2 would make things clearer and less error-prone.
I'll do that on the respin.

Cheers,
/fuad

>
> static inline void __cptr_clear_set_hvhe(u64 cptr_clr, u64 cptr_set)
> {
>         u64 clr = 0, set = 0;
>
>         if (cptr_clr & CPTR_EL2_TFP)
>                 set |= CPACR_ELx_FPEN;
>         if (cptr_clr & CPTR_EL2_TZ)
>                 set |= CPACR_ELx_ZEN;
>         if (cptr_clr & CPTR_EL2_TSM)
>                 set |= CPACR_ELx_SMEN;
>
>         if (cptr_set & CPTR_EL2_TFP)
>                 clr |= CPACR_ELx_FPEN;
>         if (cptr_set & CPTR_EL2_TZ)
>                 clr |= CPACR_ELx_ZEN;
>         if (cptr_set & CPTR_EL2_TSM)
>                 clr |= CPACR_ELx_SMEN;
>
>         sysreg_clear_set(cpacr_el1, clr, set);
> }
>
> static inline void cptr_clear_set(u64 clr, u64 set)
> {
>         if (has_hvhe())
>                 __cptr_clear_set_hvhe(clr, set);
>         else
>                 sysreg_clear_set(cptr_el2, clr, set);
> }
>
> --
> Thanks,
> Oliver



More information about the linux-arm-kernel mailing list