On Wed, Mar 27, 2024 at 05:35:02PM +0000, Fuad Tabba wrote: > On restoring guest SVE state, use the guest's current active > vector length. This reduces the amount of restoring for the cases For this to work don't we also need to also save the state with the currently operational guest VL, all the saves and loads are done with VL dependent operations? It has crossed my mind to save and load the guest state with the currently active guest VL since that's probably a little quicker but we don't appear to be doing that. > where the maximum size isn't used. Moreover, it fixes a bug where > the ZCR_EL2 value wasn't being set when restoring the guest > state, potentially corrupting it. > static inline void __hyp_sve_restore_guest(struct kvm_vcpu *vcpu) > { > - sve_cond_update_zcr_vq(vcpu_sve_max_vq(vcpu) - 1, SYS_ZCR_EL2); What was the bug with ZCR_EL2 not being set - I'm not clear how this could be skipped? > + u64 zcr_el1 = __vcpu_sys_reg(vcpu, ZCR_EL1); > + u64 zcr_el2 = min(zcr_el1, vcpu_sve_max_vq(vcpu) - 1ULL); This works currently since all the bits other than LEN are either RES0 or RAZ but will break if anything new is added, explicit extraction of LEN is probably safer though slight overhead.