mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	the arch/x86 maintainers <x86@kernel.org>
Subject: [PATCH] x86/xstate: don't globally disable TILE_DATA just on its own
Date: Thu, 4 Jul 2024 13:32:24 +0200	[thread overview]
Message-ID: <32f5ce15-e9e8-4351-a231-c23ebb4b083c@suse.com> (raw)

In XCR0 certain bits need to be simultaneously set / clear. Since
fpu__init_cpu_xstate() wants to pass fpu_user_cfg.max_features to
XSETBV, make sure invalid values cannot end up there in case XFD is not
available. Do the clearing right for fpu_kernel_cfg.max_features (which
fpu_user_cfg.max_features is derived from), to avoid that field holding
an invalid combination of bits either.

Fixes: 2ae996e0c1a3 ("x86/fpu: Calculate the default sizes independently")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
#GP observed in a virtualized environment with AMX enabled, but XFD off
(which is an architecturally legal combination of features, afaict).

--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -49,6 +49,9 @@
 /* Features which are dynamically enabled for a process on request */
 #define XFEATURE_MASK_USER_DYNAMIC	XFEATURE_MASK_XTILE_DATA
 
+/* Features which the above ones are tied to. */
+#define XFEATURE_MASK_USER_DYN_DEPS	XFEATURE_MASK_XTILE_CFG
+
 /* All currently supported supervisor features */
 #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \
 					    XFEATURE_MASK_CET_USER)
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -799,8 +799,15 @@ void __init fpu__init_system_xstate(unsi
 			fpu_kernel_cfg.max_features &= ~BIT_ULL(i);
 	}
 
-	if (!cpu_feature_enabled(X86_FEATURE_XFD))
-		fpu_kernel_cfg.max_features &= ~XFEATURE_MASK_USER_DYNAMIC;
+	if (!cpu_feature_enabled(X86_FEATURE_XFD)) {
+		/*
+		 * Besides disabling all dynamic features, also disable all
+		 * of their dependents, such that the resulting value can be
+		 * handed to XSETBV without causing #GP.
+		 */
+		fpu_kernel_cfg.max_features &= ~(XFEATURE_MASK_USER_DYNAMIC |
+						 XFEATURE_MASK_USER_DYN_DEPS);
+	}
 
 	if (!cpu_feature_enabled(X86_FEATURE_XSAVES))
 		fpu_kernel_cfg.max_features &= XFEATURE_MASK_USER_SUPPORTED;

                 reply	other threads:[~2024-07-04 11:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=32f5ce15-e9e8-4351-a231-c23ebb4b083c@suse.com \
    --to=jbeulich@suse.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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®