[PATCH 6.12.y 14/17] x86/fpu: Bail early from guest XFD update if XFD isn't supported

From: Paolo Bonzini

Date: Fri Dec 04 2026 - 13:04:23 EST


From: Sean Christopherson <seanjc@xxxxxxxxxx>

[ Upstream commit 389bafa29e91827ee95127c40893e64295e4499f ]

As is, KVM allows userspace to set guest XFD to 0 even if XFD isn't
supported; KVM unarguably shouldn't try to update guest XFD when the
kernel doesn't support XFD/XSAVE, but fixing that flaw could potentially
impact KVM's uABI. Thus, ignore KVM-requested guest XFD updates if the
kernel doesn't support XFD.

The current code is subtly fine and does not corrupt guest_fpu->fpstate
by interpreting it as an xstate structure; xsave.header.xfeatures is
modified if and only if xfd != 0, which KVM does reject. Still, it's
more defensive to return early and WARN if XFD is not set to 0.

Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Jim Mattson <jmattson@xxxxxxxxxx>
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Link: https://patch.msgid.link/20261119001506.64568-2-seanjc@xxxxxxxxxx
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/x86/kernel/fpu/core.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 7526b16887dc..b8828bde39e9 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -296,6 +296,11 @@ void fpu_update_guest_xfd(struct fpu_guest *guest_fpu, u64 xfd)
{
struct fpstate *fpstate = guest_fpu->fpstate;

+ if (!cpu_feature_enabled(X86_FEATURE_XFD)) {
+ WARN_ON_ONCE(xfd);
+ return;
+ }
+
fpregs_lock();

/*
--
2.56.1