[tip: x86/cpu] x86/cpu: Rescan CPUID table after disabling PSN

tip-bot2 for Ahmed S. Darwish posted 1 patch 4 weeks, 1 day ago
arch/x86/kernel/cpu/common.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
[tip: x86/cpu] x86/cpu: Rescan CPUID table after disabling PSN
Posted by tip-bot2 for Ahmed S. Darwish 4 weeks, 1 day ago
The following commit has been merged into the x86/cpu branch of tip:

Commit-ID:     32e3732c0325385d389792bbe494434b3efae485
Gitweb:        https://git.kernel.org/tip/32e3732c0325385d389792bbe494434b3efae485
Author:        Ahmed S. Darwish <darwi@linutronix.de>
AuthorDate:    Fri, 27 Mar 2026 03:15:24 +01:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Wed, 13 May 2026 17:29:12 +02:00

x86/cpu: Rescan CPUID table after disabling PSN

On Pentium-III and Transmeta CPUs, disabling the CPUID(0x3) Processor
Serial Number (PSN) can affect the maximum valid CPUID standard leaf.

Rescan the CPUID table in that case in order not to have stale cached
data.

  [ bp: Zap unrelated changes, rescan the full range after disabling
    CPUID(3). ]

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/all/20260327021645.555257-1-darwi@linutronix.de
---
 arch/x86/kernel/cpu/common.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a3df21d..c51cdca 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -339,13 +339,13 @@ bool cpuid_feature(void)
 
 static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
 {
+	const struct leaf_0x0_0 *l0;
 	unsigned long lo, hi;
 
 	if (!cpu_has(c, X86_FEATURE_PN) || !disable_x86_serial_nr)
 		return;
 
 	/* Disable processor serial number: */
-
 	rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
 	lo |= 0x200000;
 	wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
@@ -353,8 +353,16 @@ static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
 	pr_notice("CPU serial number disabled.\n");
 	clear_cpu_cap(c, X86_FEATURE_PN);
 
-	/* Disabling the serial number may affect the cpuid level */
-	c->cpuid_level = cpuid_eax(0);
+	/* Disabling CPUID(0x3) can change the maximum base CPUID level. */
+	cpuid_refresh_leaf(c, 0x0);
+	l0 = cpuid_leaf(c, 0x0);
+	if (!l0)
+		return;
+
+	c->cpuid_level = l0->max_std_leaf;
+
+	/* Rescan from the whole range. */
+	cpuid_refresh_range(c, 0, CPUID_BASE_END);
 }
 
 static int __init x86_serial_nr_setup(char *s)