mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Borislav Petkov <bp@alien8.de>
Cc: Sean Christopherson <seanjc@google.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Jim Mattson <jmattson@google.com>,
	Stefan Teodorescu <fane@google.com>,
	Chris Mason <mason@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>,
	David Woodhouse <dwmw2@infradead.org>,
	stable@vger.kernel.org
Subject: Re: [*** OFF-LIST *** PATCH v2 1/3] x86/fpu: Bail early from guest XFD update if XFD isn't supported
Date: Mon, 30 Nov 2026 19:02:42 +0100	[thread overview]
Message-ID: <20261130180242.201450-1-pbonzini@redhat.com> (raw)
In-Reply-To: <20261120193052.GCawCf7LBmUxT2plv6@fat_crate.local>

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


           reply	other threads:[~2026-11-30 18:02 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20261120193052.GCawCf7LBmUxT2plv6@fat_crate.local>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130180242.201450-1-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=fane@google.com \
    --cc=jmattson@google.com \
    --cc=josef@toxicpanda.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=mingo@redhat.com \
    --cc=seanjc@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®