Re: [PATCH v3 06/20] KVM: x86: Support APX state for XSAVE ABI

Paolo Bonzini
2026-04-28T09:31:57Z

On 4/28/26 07:00, Chang S. Bae wrote:
> + /*
> + * APX off in XSTATE_BV will guide fpu_copy_uabi_to_guest_fpstate()
> + * to avoid from unnecessary handling.
> + */
> + xstate->xsave.header.xfeatures &= ~XFEATURE_MASK_APX;

I would place this statement inside in fpu_copy_uabi_to_guest_fpstate,
and more in general make arch/x86/fpu ignore APX when dealing with
guest_fpstate. This can be a separate patch like this:

-------------- 8< -------------
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: x86/fpu: ignore APX when copying from/to guest FPU

KVM will store APX extended GPRs directly in the regs[] field of
struct kvm_vcpu. This is done to make accessors more uniform
between GPRs and EGPRs, and partly because x86 maintainers
expressed the desire to compile Linux with APX enabled sooner
or later; accessing guest EGPRs from KVM's C code would get
in the way.

Therefore, let KVM handle the APX feature on its own when
executing ioctls to get and set the virtual machine's
XSAVE state.

Cc: x86@kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 608983806fd7..c35cff8dbfff 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -420,6 +420,8 @@ void fpu_copy_guest_fpstate_to_uabi(struct fpu_guest *gfpu, void *buf,
struct membuf mb = { .p = buf, .left = size };

if (cpu_feature_enabled(X86_FEATURE_XSAVE)) {
+ /* Up to date APX registers are in struct kvm_vcpu anyway. */
+ xfeatures &= ~XFEATURE_MASK_APX;
__copy_xstate_to_uabi_buf(mb, kstate, xfeatures, pkru,
XSTATE_COPY_XSAVE);
} else {
@@ -464,6 +465,8 @@ int fpu_copy_uabi_to_guest_fpstate(struct fpu_guest *gfpu, const void *buf,
if (!(ustate->xsave.header.xfeatures & XFEATURE_MASK_PKRU))
vpkru = NULL;

+ /* APX registers are copied to and from struct kvm_vcpu, not the FPU. */
+ ustate->xsave.header.xfeatures &= ~XFEATURE_MASK_APX;
return copy_uabi_from_kernel_to_xstate(kstate, ustate, vpkru);
}
EXPORT_SYMBOL_FOR_KVM(fpu_copy_uabi_to_guest_fpstate);

Thanks,

Paolo