[PATCH 1/1] x86/fpu: Bail early from guest XFD update if XFD isn't supported

From: Sean Christopherson

Date: Wed Nov 18 2026 - 19:15:04 EST


KVM generally allows userspace to set MSRs to their inactive values even
if they aren't supported by the guest, as that simplifies userspace code
noticeably, and XFD is no exception. Arguably, it should then not try
to update XFD in struct fpu_guest* if the kernel doesn't support XFD or
even XSAVE. However, fixing that flaw could potentially impact KVM's
uABI; thus, simply 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, returning early
is clearer, provides fewer opportunities for bugs, and provides a place
for WARNing in the indefensible case of xfd != 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>
---
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 80a7f41cf3ad..2739264b9cf3 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -334,6 +334,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