[PATCH] KVM: arm64: Preserve all guest ZCR_EL2.LEN values
Mark Brown
broonie at kernel.org
Sat May 23 07:38:28 PDT 2026
On Sat, May 23, 2026 at 09:47:38AM +0100, Marc Zyngier wrote:
> Mark Brown <broonie at kernel.org> wrote:
> > The reasoning for the current behaviour is not specifically articulated, my
> > best guess is that it is intended to ensure that the guest can not see an
> > effective VL greater than the maximum that has been configured. This can
> > instead be achieved by configuring ZCR_EL2 when loading guest state:
> > - When running at EL0 or EL1 configure ZCR_EL2.LEN to the minimum of the
> > guest ZCR_EL2.LEN and vcpu_sve_max_vq(vcpu)-1.
> This is not EL0 or EL1. This is when in a nested context (i.e. running
> a L2 guest), as EL0 exists for L1 as well.
Sorry, this was intended to be specifically for a L2 guest but didn't
actually say that. I originally had more verbosity in the commit log
that I cleaned up too much, making things unclear. I will clarify.
> > Currently all other bits in ZCR_EL2 are either RES0 or RAZ/WI, values
> > written are sanitised based on this.
> Only for the direct writes to ZCR_EL2, as they are trapping. I don't
> see any sanitisation for writes using the ZCR_EL1 accessor, which is
> the common case. This needs fixing at the same time.
OK, I'll convert ZCR_EL2 to a sanitised register. As I mentioned I was
a bit confused about why the existing code is the way it is and so
followed it in only managing the direct writes. I figured it was
considered OK to rely on the hardware for the RES0 and WI behaviour for
untrapped access.
> > - if (is_nested_ctxt(vcpu)) - zcr_el2
> > = __vcpu_sys_reg(vcpu, ZCR_EL2); - else -
> > zcr_el2 = vcpu_sve_max_vq(vcpu) - 1; + if
> > (is_nested_ctxt(vcpu) && !is_hyp_ctxt(vcpu)) +
> > zcr_el2 = min(zcr_el2, __vcpu_sys_reg(vcpu, ZCR_EL2));
> Why the change in the condition guarding this? Given the definition of
> is_nested_ctxt(), this seems unnecessary.
You're right, this change is not needed. I had misremembered what
is_nested_ctxt() was checking.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20260523/ef39bbbb/attachment.sig>
More information about the linux-arm-kernel
mailing list