Re: [PATCH v4 06/21] x86/fpu: Ignore APX when copying from/to guest FPU

From: Chang S. Bae

Date: Thu May 14 2026 - 22:11:34 EST


On 5/14/2026 9:04 AM, Paolo Bonzini wrote:

Separately, it's possible to avoid hardcoding APX by passing a mask
argument to fpu_copy_uabi_to_guest_fpstate and
fpu_copy_guest_fpstate_to_uabi. KVM can then pass
~(u64)XFEATURE_MASK_APX.

Yeah, that’s possible, though it also needs to ensure XSTATE_BV[APX] = 0 in the UABI buffer to avoid:

if (ustate->xsave.header.xfeatures & ~xcr0)
return -EINVAL;

V3 previously handled that on the KVM side. Then, V4 moved it to the x86/fpu core to make the exclusion more explicit.

Another option would be simply leave the UABI XSTATE_BV untouched. But then a few sub-optimal behavior remain:

* On UABI => kernel, APX state gets copied twice: one into VCPU regs[]
and again into guest fpstate. The latter 128B copy isn’t necessary.
* On kernel => UABI, the generic copier zeros the APX area even though
it will later be overwritten from regs[]
* On XRSTOR before VM enter, APX state restore becomes redundant since
the entry code reloads EGPRs from regs[] anyway.

That said, all of this happens on slow paths involving userspace interactions. So unless avoiding these still keeps code clear enough, this falls into mere optimization but with negligible practical benefit.

So perhaps patch7 could instead carry a note like:

/*
* Both functions copy APX state into each storage: VCPU regs[] and
* guest fpstate. This is redundant, but lies on a slow path with IOCTL
* handling already. Avoid additional tweaking of the generic copy
* function and userspace XSTATE_BV, in order to keep the flow
* straightforward.
*/

kvm_copy_uabi_to_vcpu_regs();
fpu_copy_uabi_to_guest_fpstate();

Thanks,
Chang