[PATCH v3 43/44] x86/cpu: Rescan CPUID table after PSN disable

From: Ahmed S. Darwish
Date: Thu Jun 12 2025 - 19:50:08 EST


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

Rescan the CPU's CPUID table in that case, not to have stale cached data.
Use parsed CPUID(0x0) access, instead of direct CPUID query, afterwards.

Rename squash_the_stupid_serial_number() to disable_cpu_serial_number()
and explain the rational for disabling the CPU's PSN.

Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/common.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 023613698b15..81fe33976ceb 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -327,15 +327,17 @@ bool cpuid_feature(void)
return flag_is_changeable_p(X86_EFLAGS_ID);
}

-static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
+/*
+ * For privacy concerns, disable legacy Intel and Transmeta CPUID(0x3)
+ * feature, Processor Serial Number, by default.
+ */
+static void disable_cpu_serial_number(struct cpuinfo_x86 *c)
{
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);
@@ -343,8 +345,12 @@ 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) might have affected the maximum standard
+ * CPUID level. Rescan the CPU's CPUID table afterwards.
+ */
+ cpuid_parser_scan_cpu(c);
+ c->cpuid_level = cpuid_leaf(c, 0x0)->max_std_leaf;
}

static int __init x86_serial_nr_setup(char *s)
@@ -354,7 +360,7 @@ static int __init x86_serial_nr_setup(char *s)
}
__setup("serialnumber", x86_serial_nr_setup);
#else
-static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
+static inline void disable_cpu_serial_number(struct cpuinfo_x86 *c)
{
}
#endif
@@ -1968,7 +1974,7 @@ static void identify_cpu(struct cpuinfo_x86 *c)
bus_lock_init();

/* Disable the PN if appropriate */
- squash_the_stupid_serial_number(c);
+ disable_cpu_serial_number(c);

/* Set up SMEP/SMAP/UMIP */
setup_smep(c);
--
2.49.0