Re: [PATCH v3 23/40] KVM: x86: Move kvm_{load,put}_guest_fpu() to fpu.h

From: Sean Christopherson

Date: Fri Jun 05 2026 - 15:15:45 EST


On Thu, Jun 04, 2026, Kai Huang wrote:
> On Fri, 2026-05-29 at 15:22 -0700, Sean Christopherson wrote:
> > +/* Swap (qemu) user FPU context for the guest FPU context. */
> > +static inline void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
> > +{
> > + if (KVM_BUG_ON(vcpu->arch.guest_fpu.fpstate->in_use, vcpu->kvm))
> > + return;
> > +
> > + /* Exclude PKRU, it's restored separately immediately after VM-Exit. */
> > + fpu_swap_kvm_fpstate(&vcpu->arch.guest_fpu, true);
> > + trace_kvm_fpu(1);
> > +}
> > +
> > +/* When vcpu_run ends, restore user space FPU context. */
> > +static inline void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
> > +{
> > + if (KVM_BUG_ON(!vcpu->arch.guest_fpu.fpstate->in_use, vcpu->kvm))
> > + return;
> > +
> > + fpu_swap_kvm_fpstate(&vcpu->arch.guest_fpu, false);
> > + ++vcpu->stat.fpu_reload;
> > + trace_kvm_fpu(0);
> > +}
> > +
>
> Nit: to me it's a little bit weird to put the two functions before the typedefs
> and macro defines below, though.

Yeah, I don't disagree. But I think I'd prefer to keep it this way, so that the
typedefs are more obviously bundled with the ugly XMM/AVX register helpers.

>
> > typedef u32 __attribute__((vector_size(16))) sse128_t;
> > #define __sse128_u union { sse128_t vec; u64 as_u64[2]; u32 as_u32[4]; }
> > #define sse128_lo(x) ({ __sse128_u t; t.vec = x; t.as_u64[0]; })