Re: [PATCH v8 02/20] KVM: VMX: Save guest EGPRs in VCPU cache
From: Jim Mattson
Date: Thu Nov 05 2026 - 18:53:02 EST
On Wed, Sep 30, 2026 at 2:35 PM Chang S. Bae <chang.seok.bae@xxxxxxxxx> wrote:
>
> Save and restore the guest EGPRs on VM exit/entry if the system supports
> Advanced Performance Extensions (APX).
>
> There are two possible ways of handling EGPR accesses: reading them from
> the processor lazily, or switching them in the vmentry/vmexit path and
> accessing them via vcpu->arch.regs. Prepare for the latter; it does not
> pollute kvm_reg_read/write() with conditionals to treat GPRs vs. EGPRs
> differently, and it allows for future usage of APX registers in the
> kernel.
>
> KVM intercepts all XCR0 writes, therefore XCR0 cannot change during the
> execution of VMLAUNCH/VMRESUME. Thus, for a guest that does not set
> XCR0[APX], the EGPR state does not have to be loaded/saved.
>
> The register saving path is placed after SPEC_CTRL is restored, so as
> to avoid any mis-speculation into EGPR accesses when APX is disabled.
>
> While saving may be skipped on VM-Fail, it is not worth the added
> complication for a slow path.
>
> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Tested-by: Zhao Liu <zhao1.liu@xxxxxxxxx>
> Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
> Link: https://lore.kernel.org/adPRA4ZhnvbaXSn0@xxxxxxxxxx
Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>