On Tue, Feb 04, 2025 at 06:00:24PM +0000, Marc Zyngier wrote: > On Tue, 04 Feb 2025 15:21:00 +0000, > Mark Rutland <mark.rutland@xxxxxxx> wrote: > > +static inline void fpsimd_lazy_switch_to_guest(struct kvm_vcpu *vcpu) > > +{ > > + u64 zcr_el1, zcr_el2; > > + > > + if (!guest_owns_fp_regs()) > > + return; > > + > > + if (vcpu_has_sve(vcpu)) { > > + /* A guest hypervisor may restrict the effective max VL. */ > > + if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) > > + zcr_el2 = __vcpu_sys_reg(vcpu, ZCR_EL2); > > + else > > + zcr_el2 = vcpu_sve_max_vq(vcpu) - 1; > > + > > + sve_cond_update_zcr_vq(zcr_el2, SYS_ZCR_EL2); > > Not a big deal, but I though I'd mention it here: Using ZCR_EL2 (or > any other register using the _EL2 suffix) is a source of expensive > traps with NV. We're much better off using the _EL1 accessor if we are > running VHE, as this will involve no trap at all. > > nVHE will of course trap, but using nVHE with SVE under NV is not > something I'm prepared to give a damn about. Ah, sorry. I had forgotten that wrinkle. Given the compiler warnings reported by Mark Brown [1] and the kernel test robot [2], I'll go spin a v2 with that cleaned up. I'll use write_sysreg_el2() here, i.e. if (vcpu_has_sve(vcpu)) { /* A guest hypervisor may restrict the effective max VL. */ if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) zcr_el2 = __vcpu_sys_reg(vcpu, ZCR_EL2); else zcr_el2 = vcpu_sve_max_vq(vcpu) - 1; write_sysreg_el2(scr_el2, SYS_ZCR); } That'll use the preferred alias automatically, and it matches the style used to write to ZCR_EL{1,12} immediately after. Likewise for the other instances. Mark. [1] https://lore.kernel.org/linux-arm-kernel/b76803b7-c1b3-426b-a375-0c01b98142c9@xxxxxxxxxxxxx/ [2] https://lore.kernel.org/oe-kbuild-all/202502061341.FvsCMKEH-lkp@xxxxxxxxx/