Re: [PATCH v3 23/40] KVM: x86: Move kvm_{load,put}_guest_fpu() to fpu.h
From: Yosry Ahmed
Date: Fri May 29 2026 - 20:53:06 EST
On Fri, May 29, 2026 at 03:22:06PM -0700, Sean Christopherson wrote:
> Move the kvm_{load,put}_guest_fpu() helpers to fpu.h in anticipation of
> moving the bulk of KVM's register specific code out of x86.c.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Reviewed-by: Yosry Ahmed <yosry@xxxxxxxxxx>
> ---
> arch/x86/kvm/fpu.h | 26 ++++++++++++++++++++++++++
> arch/x86/kvm/x86.c | 24 ------------------------
> 2 files changed, 26 insertions(+), 24 deletions(-)
>
> diff --git a/arch/x86/kvm/fpu.h b/arch/x86/kvm/fpu.h
> index f898781b6a06..6b7b628f530d 100644
> --- a/arch/x86/kvm/fpu.h
> +++ b/arch/x86/kvm/fpu.h
> @@ -3,8 +3,34 @@
> #ifndef __KVM_FPU_H_
> #define __KVM_FPU_H_
>
> +#include <linux/kvm_host.h>
> +
> +#include <trace/events/kvm.h>
> +
> #include <asm/fpu/api.h>
>
> +/* Swap (qemu) user FPU context for the guest FPU context. */
I didn't know KVM was allowed to break the fourth wall like this?
> +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);
> +}