[PATCH 19/28] KVM: arm64: Make HCR_EL2 a non-VNCR register
Marc Zyngier
maz at kernel.org
Thu Jul 9 05:04:58 PDT 2026
On Wed, 08 Jul 2026 12:18:32 +0100,
Joey Gouly <joey.gouly at arm.com> wrote:
>
> On Thu, Jul 02, 2026 at 05:02:39PM +0100, Marc Zyngier wrote:
> > FEAT_NV3 makes a fundamental change to the architecture, by moving
> > guest-initiated HCR_EL2 accesses to the NVHCR_EL2 register. As the
> > names suggests, this is HCR_EL2 for a NV guest.
> >
> > But where do NVHCR_EL2 accesses from a guest go? The are redirected
> > to the VNCR page, right where HCR_EL2 is stored in the NV2 case.
> > Does it hurt? Good. There's more coming.
> >
> > The challenge here is to make KVM work seamlessly, without rewriting
> > everything. Which implies that things such as __vcpu_sys_reg(HCR_EL2)
> > must work, no matter the underlying NV implementation.
> >
> > A simple way to deal with it is to move HCR_EL2's canonical storage
> > outside of VNCR for the vast majority of the KVM code, and only have
> > a copy at entry/exit times. Given that we don't really support NV3
> > yet, this is pretty simple.
> >
> > In the process, advertise NVHCR_EL2 as the register that now holds
> > offset 0x78 in the VNCR page.
> >
> > Signed-off-by: Marc Zyngier <maz at kernel.org>
>
> Reviewed-by: Joey Gouly <joey.gouly at arm.com>
>
> > ---
> > arch/arm64/include/asm/kvm_host.h | 3 ++-
> > arch/arm64/include/asm/vncr_mapping.h | 2 +-
> > arch/arm64/kvm/hyp/vhe/switch.c | 9 +++++++++
> > 3 files changed, 12 insertions(+), 2 deletions(-)
> >
[...]
> > @@ -559,6 +563,11 @@ static void fixup_nv_guest_exit(struct kvm_vcpu *vcpu)
> >
> > *vcpu_cpsr(vcpu) &= ~(PSR_MODE_MASK | PSR_MODE32_BIT);
> > *vcpu_cpsr(vcpu) |= mode;
> > +
> > + /* Publish the latest HCR_EL2 to the emulation */
> > + hcr = __vcpu_sys_reg(vcpu, NVHCR_EL2);
>
> My alarm bells went off reading this, because the context (in-memory) seemed
> wrong, but I see that patch 23 further modifies this for NV3!
Yeah, this patch is strictly about moving HCR_EL2 out of VNCR before
any NV3 shenanigans. The guest state is still in the same VNCR
location when we're running NV2, only duplicated for the benefit of
the rest of the KVM emulation.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
More information about the linux-arm-kernel
mailing list