Skip to content

Commit 9092aca

Browse files
committed
KVM: arm64: nv: Use guest hypervisor's max VL when running nested guest
The max VL for nested guests is additionally constrained by the max VL selected by the guest hypervisor. Use that instead of KVM's max VL when running a nested guest. Note that the guest hypervisor's ZCR_EL2 is sanitised against the VM's max VL at the time of access, so there's no additional handling required at the time of use. Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent b7e5c94 commit 9092aca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,23 @@ static bool kvm_hyp_handle_mops(struct kvm_vcpu *vcpu, u64 *exit_code)
314314

315315
static inline void __hyp_sve_restore_guest(struct kvm_vcpu *vcpu)
316316
{
317+
/*
318+
* The vCPU's saved SVE state layout always matches the max VL of the
319+
* vCPU. Start off with the max VL so we can load the SVE state.
320+
*/
317321
sve_cond_update_zcr_vq(vcpu_sve_max_vq(vcpu) - 1, SYS_ZCR_EL2);
318322
__sve_restore_state(vcpu_sve_pffr(vcpu),
319323
&vcpu->arch.ctxt.fp_regs.fpsr,
320324
true);
321325

326+
/*
327+
* The effective VL for a VM could differ from the max VL when running a
328+
* nested guest, as the guest hypervisor could select a smaller VL. Slap
329+
* that into hardware before wrapping up.
330+
*/
331+
if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu))
332+
sve_cond_update_zcr_vq(__vcpu_sys_reg(vcpu, ZCR_EL2), SYS_ZCR_EL2);
333+
322334
write_sysreg_el1(__vcpu_sys_reg(vcpu, vcpu_sve_zcr_elx(vcpu)), SYS_ZCR);
323335
}
324336

0 commit comments

Comments
 (0)