Skip to content

Commit 2e3cf82

Browse files
committed
KVM: arm64: nv: Ensure correct VL is loaded before saving SVE state
It is possible that the guest hypervisor has selected a smaller VL than the maximum for its nested guest. As such, ZCR_EL2 may be configured for a different VL when exiting a nested guest. Set ZCR_EL2 (via the EL1 alias) to the maximum VL for the VM before saving SVE state as the SVE save area is dimensioned by the max VL. Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 9092aca commit 2e3cf82

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/arm64/kvm/fpsimd.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,14 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
195195
* Note that this means that at guest exit ZCR_EL1 is
196196
* not necessarily the same as on guest entry.
197197
*
198-
* Restoring the VL isn't needed in VHE mode since
199-
* ZCR_EL2 (accessed via ZCR_EL1) would fulfill the same
200-
* role when doing the save from EL2.
198+
* ZCR_EL2 holds the guest hypervisor's VL when running
199+
* a nested guest, which could be smaller than the
200+
* max for the vCPU. Similar to above, we first need to
201+
* switch to a VL consistent with the layout of the
202+
* vCPU's SVE state. KVM support for NV implies VHE, so
203+
* using the ZCR_EL1 alias is safe.
201204
*/
202-
if (!has_vhe())
205+
if (!has_vhe() || (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)))
203206
sve_cond_update_zcr_vq(vcpu_sve_max_vq(vcpu) - 1,
204207
SYS_ZCR_EL1);
205208
}

0 commit comments

Comments
 (0)