From: Xin Li <xin@zytor.com>
To: Wieczor-Retman Maciej <maciej.wieczor-retman@intel.com>
Cc: Gleixner Thomas <tglx@linutronix.de>,
Molnar Ingo <mingo@redhat.com>, Petkov Borislav <bp@alien8.de>,
Hansen Dave <dave.hansen@linux.intel.com>,
x86@kernel.org, "Anvin H. Peter" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86: Clear LAM and FRED feature bits
Date: Tue, 22 Jul 2025 02:08:28 -0700 [thread overview]
Message-ID: <32382f60-79fb-4cfa-87b4-581f92c980da@zytor.com> (raw)
In-Reply-To: <20250722074439.4069992-1-maciej.wieczor-retman@intel.com>
> On Jul 22, 2025, at 12:54 AM, Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> wrote:
>
> If LAM (CONFIG_ADDRESS_MASKING) or FRED (CONFIG_X86_FRED) are disabled
> during compile time, they still are enumerated in macros such as
> cpu_has() or this_cpu_has() that use the x86_capability bitmask. The
> features are also visible in /proc/cpuinfo even though they are not
> enabled - which is contrary to what the documentation states about the
> file.
I'm curious how this bug is introduced with my patch set that adds the
AWK script which automatically generates the CPU feature mask header.
>
> The documentation for x86/cpuinfo.rst also states how to handle features
> disabled at compile time:
>
> The kernel disabled support for it at compile-time
> --------------------------------------------------
>
> For example, if Linear Address Masking (LAM) is not enabled when
> building (i.e., CONFIG_ADDRESS_MASKING is not selected) the flag
> "lam" will not show up. Even though the feature will still be
> detected via CPUID, the kernel disables it by clearing via
> setup_clear_cpu_cap(X86_FEATURE_LAM).
>
> Clear feature bits if they are present in the DISABLED_MASK.
>
> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
And we need a Fixes tag and CC stable.
> ---
> arch/x86/kernel/cpu/common.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index 77afca95cced..1c5af795cedc 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -1782,6 +1782,16 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
> if (!pgtable_l5_enabled())
> setup_clear_cpu_cap(X86_FEATURE_LA57);
>
> + /*
> + * If a feature is disabled during compile time clear its feature
> + * bit to prevent it from showing up in the x86_capability bitmask.
> + */
> + if (!cpu_feature_enabled(X86_FEATURE_LAM))
> + setup_clear_cpu_cap(X86_FEATURE_LAM);
> +
> + if (!cpu_feature_enabled(X86_FEATURE_FRED))
> + setup_clear_cpu_cap(X86_FEATURE_FRED);
> +
The following code will work as a generic fix:
c->x86_capability[i] &= ~DISABLED_MASK(i);
And DISABLED_MASK(x) needs to be defined like DISABLED_MASK_BIT_SET(x).
Thanks!
Xin
next prev parent reply other threads:[~2025-07-22 9:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-22 7:44 Maciej Wieczor-Retman
2025-07-22 9:08 ` Xin Li [this message]
2025-07-22 14:11 ` Dave Hansen
2025-07-22 15:43 ` Maciej Wieczor-Retman
2025-07-22 15:31 ` Maciej Wieczor-Retman
2025-07-22 16:46 ` H. Peter Anvin
2025-07-22 17:22 ` Xin Li
2025-07-22 18:19 ` Maciej Wieczor-Retman
2025-07-22 19:26 ` H. Peter Anvin
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=32382f60-79fb-4cfa-87b4-581f92c980da@zytor.com \
--to=xin@zytor.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--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®