From: Thomas Gleixner <tglx@linutronix.de>
To: Mitchell Levy via B4 Relay
<devnull+levymitchell0.gmail.com@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Cc: stable@vger.kernel.org, Borislav Petkov <bp@suse.de>,
linux-kernel@vger.kernel.org,
Mitchell Levy <levymitchell0@gmail.com>
Subject: Re: [PATCH] x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported
Date: Fri, 09 Aug 2024 14:02:44 +0200 [thread overview]
Message-ID: <87plqhucnv.ffs@tglx> (raw)
In-Reply-To: <87sevet447.ffs@tglx>
On Fri, Aug 09 2024 at 11:52, Thomas Gleixner wrote:
>> static inline u64 xfeatures_mask_independent(void)
>> {
>> - if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR))
>> + if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR) ||
>> + (fpu_kernel_cfg.max_features & XFEATURE_MASK_LBR) != XFEATURE_MASK_LBR)
>
> This is wrong because fpu_kernel_cfg.max_features never contains
> XFEATURE_MASK_LBR. It only contains the bits which are managed by the
> FPU subsystem.
You want something like the uncompiled below.
The LBR bit should be probably cleared when the CPU feature is not there
at some point in the boot process to avoid the whole is enabled and
masking business, but that's an orthogonal issue.
Thanks,
tglx
---
arch/x86/include/asm/fpu/types.h | 7 +++++++
arch/x86/kernel/fpu/xstate.c | 2 ++
arch/x86/kernel/fpu/xstate.h | 4 ++--
3 files changed, 11 insertions(+), 2 deletions(-)
--- a/arch/x86/include/asm/fpu/types.h
+++ b/arch/x86/include/asm/fpu/types.h
@@ -591,6 +591,13 @@ struct fpu_state_config {
* even without XSAVE support, i.e. legacy features FP + SSE
*/
u64 legacy_features;
+ /*
+ * @independent_features:
+ *
+ * Features which are supported by XSAVES but not managed
+ * by the FPU core, e.g. LBR
+ */
+ u64 independent_features;
};
/* FPU state configuration information */
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -788,6 +788,8 @@ void __init fpu__init_system_xstate(unsi
goto out_disable;
}
+ fpu_kernel_cfg.independent_features = fpu_kernel_cfg.max_features &
+ XFEATURE_MASK_INDEPENDENT;
/*
* Clear XSAVE features that are disabled in the normal CPUID.
*/
--- a/arch/x86/kernel/fpu/xstate.h
+++ b/arch/x86/kernel/fpu/xstate.h
@@ -62,9 +62,9 @@ static inline u64 xfeatures_mask_supervi
static inline u64 xfeatures_mask_independent(void)
{
if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR))
- return XFEATURE_MASK_INDEPENDENT & ~XFEATURE_MASK_LBR;
+ return fpu_kernel_cfg.independent_features & ~XFEATURE_MASK_LBR;
- return XFEATURE_MASK_INDEPENDENT;
+ return fpu_kernel_cfg.independent_features;
}
/* XSAVE/XRSTOR wrapper functions */
prev parent reply other threads:[~2024-08-09 12:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-08 23:30 [PATCH] x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported Mitchell Levy via B4 Relay
2024-08-09 0:40 ` Mitchell Levy
2024-08-09 9:52 ` Thomas Gleixner
2024-08-09 12:02 ` Thomas Gleixner [this message]
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=87plqhucnv.ffs@tglx \
--to=tglx@linutronix.de \
--cc=bp@alien8.de \
--cc=bp@suse.de \
--cc=dave.hansen@linux.intel.com \
--cc=devnull+levymitchell0.gmail.com@kernel.org \
--cc=hpa@zytor.com \
--cc=levymitchell0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=stable@vger.kernel.org \
--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