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 11:52:40 +0200 [thread overview]
Message-ID: <87sevet447.ffs@tglx> (raw)
In-Reply-To: <20240808-xsave-lbr-fix-v1-1-a223806c83e7@gmail.com>
On Thu, Aug 08 2024 at 16:30, Mitchell Levy via wrote:
> From: Mitchell Levy <levymitchell0@gmail.com>
>
> When computing which xfeatures are available, make sure that LBR is only
> present if both LBR is supported in general, as well as by XSAVES.
>
> There are two distinct CPU features related to the use of XSAVES as it
> applies to LBR: whether LBR is itself supported (strictly speaking, I'm
> not sure that this is necessary to check though it's certainly a good
> sanity check), and whether XSAVES supports LBR (see sections 13.2 and
> 13.5.12 of the Intel 64 and IA-32 Architectures Software Developer's
> Manual, Volume 1). Currently, the LBR subsystem correctly checks both
> (see intel_pmu_arch_lbr_init), however the xstate initialization
> subsystem does not.
>
> When calculating what value to place in the IA32_XSS MSR,
> xfeatures_mask_independent only checks whether LBR support is present,
> not whether XSAVES supports LBR. If XSAVES does not support LBR, this
> write causes #GP, leaving the state of IA32_XSS unchanged (i.e., set to
> zero, as its not written with other values, and its default value is
> zero out of RESET per section 13.3 of the arch manual).
>
> Then, the next time XRSTORS is used to restore supervisor state, it will
> fail with #GP (because the RFBM has zero for all supervisor features,
> which does not match the XCOMP_BV field). In particular,
> XFEATURE_MASK_FPSTATE includes supervisor features, so setting up the FPU
> will cause a #GP. This results in a call to fpu_reset_from_exception_fixup,
> which by the same process results in another #GP. Eventually this causes
> the kernel to run out of stack space and #DF.
Cute.
> Fixes: d72c87018d00 ("x86/fpu/xstate: Move remaining xfeature helpers to core")
This is not the culprit/
> Cc: stable@vger.kernel.org
>
> Signed-off-by: Mitchell Levy <levymitchell0@gmail.com>
> ---
> arch/x86/kernel/fpu/xstate.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h
> index 2ee0b9c53dcc..574d2c2ea227 100644
> --- a/arch/x86/kernel/fpu/xstate.h
> +++ b/arch/x86/kernel/fpu/xstate.h
> @@ -61,7 +61,8 @@ static inline u64 xfeatures_mask_supervisor(void)
>
> 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.
Thanks,
tglx
next prev parent reply other threads:[~2024-08-09 9:52 UTC|newest]
Thread overview: 5+ 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
2024-08-08 23:30 ` Mitchell Levy via B4 Relay
2024-08-09 0:40 ` Mitchell Levy
2024-08-09 9:52 ` Thomas Gleixner [this message]
2024-08-09 12:02 ` Thomas Gleixner
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=87sevet447.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.