Re: [PATCH 0/7] KVM: x86: APX reg prep work
From: Sean Christopherson
Date: Thu Apr 02 2026 - 19:08:11 EST
On Wed, Mar 25, 2026, Chang S. Bae wrote:
> On 3/12/2026 10:47 AM, Sean Christopherson wrote:
> > On Thu, Mar 12, 2026, Chang S. Bae wrote:
> > >
> > > However, that is sort of what-if scenarios at best. The host kernel still
> > > manages EGPR context switching through XSAVE. Saving EGPRs into regs[] would
> > > introduce an oddity to synchronize between two buffers: regs[] and
> > > gfpu->fpstate, which looks like unnecessary complexity.
>
> No, this looks ugly.
Sorry, you lost me. What looks ugly?
> If guest EGPR state is saved in vcpu->arch.regs[], the APX area there isn't
> necessary:
>
> When the KVM API exposes state in XSAVE format, the frontend can handle this
> separately. Alongside uABI <-> guest fpstate copy functions, new copy
> functions may deal with the state between uABI <-> VCPU cache.
>
> Further, one could think of exclusion as such:
>
> diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
> index 76153dfb58c9..5404f9399eea 100644
> --- a/arch/x86/kernel/fpu/xstate.c
> +++ b/arch/x86/kernel/fpu/xstate.c
> @@ -794,9 +794,10 @@ static u64 __init guest_default_mask(void)
> {
> /*
> * Exclude dynamic features, which require userspace opt-in even
> - * for KVM guests.
> + * for KVM guests, and APX as extended general-purpose register
> + * states are saved in the KVM cache separately.
> */
> - return ~(u64)XFEATURE_MASK_USER_DYNAMIC;
> + return ~((u64)XFEATURE_MASK_USER_DYNAMIC | XFEATURE_MASK_APX);
> }
>
> But this default bitmask feeds into the permission bits:
>
> fpu->guest_perm.__state_perm = guest_default_cfg.features;
> fpu->guest_perm.__state_size = guest_default_cfg.size;
>
> This policy looks clear and sensible: permission is granted only if space is
> reserved to save the state. If there is a strong desire to save memory, I
> think it should go through a more thorough review to revisit this policy.
And I'm lost again.