mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86: Clear LAM and FRED feature bits
@ 2025-07-22  7:44 Maciej Wieczor-Retman
  2025-07-22  9:08 ` Xin Li
  0 siblings, 1 reply; 9+ messages in thread
From: Maciej Wieczor-Retman @ 2025-07-22  7:44 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin
  Cc: linux-kernel

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.

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>
---
 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);
+
 	detect_nopl();
 }
 
-- 
2.49.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-07-22 19:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-22  7:44 [PATCH] x86: Clear LAM and FRED feature bits Maciej Wieczor-Retman
2025-07-22  9:08 ` Xin Li
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

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®