* Re: [*** OFF-LIST *** PATCH v2 1/3] x86/fpu: Bail early from guest XFD update if XFD isn't supported
[not found] ` <20261120193052.GCawCf7LBmUxT2plv6@fat_crate.local>
@ 2026-11-30 18:02 ` Paolo Bonzini
0 siblings, 0 replies; only message in thread
From: Paolo Bonzini @ 2026-11-30 18:02 UTC (permalink / raw)
To: linux-kernel, kvm, Borislav Petkov
Cc: Sean Christopherson, Thomas Gleixner, Ingo Molnar, Dave Hansen,
Jim Mattson, Stefan Teodorescu, Chris Mason, Josef Bacik,
David Woodhouse, stable
On Fri, 20 Nov 2026 11:30:52 -0800, Borislav Petkov wrote:
> On Wed, Nov 18, 2026 at 04:15:04PM -0800, Sean Christopherson wrote:
>> Ignore KVM-requested guest XFD updates if the kernel doesn't support XFD,
>
>> to allow an upcoming fix to modify xsave.header.xfeatures even when the
>> incoming XFD value is '0'.
>
> Drop that. I agree with Dave and the sentiment to "not even go there" and
> not support non-sensical configurations.
Agreed, the real justification for bailing out early should be "allow
XFD == 0 as that is anyway the initial value of fpstate->xfd, but detect
XFD != 0 and WARN as that's a clear bug in KVM".
Then subsequent patches are free to do whatever they want.
> I appreciate your musings, Sean, but to me that commit message ended after the
> first sentence. All is perfectly clear.
:)
Here is my take on both the patch and the commit message:
----------------------- 8< -----------------
From c720a41b6df014f95ef7246777db6f066d6396e3 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <seanjc@google.com>
Date: Wed, 18 Nov 2026 16:15:04 -0800
Subject: [PATCH 1/1] x86/fpu: Bail early from guest XFD update if XFD isn't supported
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@vger.kernel.org
Reported-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://patch.msgid.link/20261119001506.64568-2-seanjc@google.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 18:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20261119001506.64568-1-seanjc@google.com>
[not found] ` <20261119001506.64568-2-seanjc@google.com>
[not found] ` <20261120193052.GCawCf7LBmUxT2plv6@fat_crate.local>
2026-11-30 18:02 ` [*** OFF-LIST *** PATCH v2 1/3] x86/fpu: Bail early from guest XFD update if XFD isn't supported Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®