Re: [PATCH v6 10/90] x86/cpu: Rescan CPUID table after disabling PSN

From: Borislav Petkov

Date: Mon May 11 2026 - 16:03:07 EST


On Fri, Mar 27, 2026 at 03:15:24AM +0100, Ahmed S. Darwish wrote:
> 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.
> Rescan only the changed CPUID leaves, not to override any of the kernel's
> previously force-set or unset cached CPUID bits.
>
> Rename squash_the_stupid_serial_number() to disable_cpu_serial_number() and
> explain the rationale behind disabling the CPU's PSN.

Except that those changes do not belong in this set. So I zapped them, see
below.

Also, why are you doing this min_t thing?

+ rescan_from = min_t(int, l0->max_std_leaf, c->cpuid_level) + 1;
+ cpuid_refresh_range(c, rescan_from, CPUID_BASE_END);
+ c->cpuid_level = l0->max_std_leaf;

Wny not simply:

/* Disabling CPUID(0x3) can change the maximum base CPUID level. */
cpuid_refresh_leaf(c, 0x0);
l0 = cpuid_leaf(c, 0x0);
if (!l0)
return;

/* Rescan from the new maximum base CPUID level. */
cpuid_refresh_range(c, l0->max_std_leaf + 1, CPUID_BASE_END);
c->cpuid_level = l0->max_std_leaf;


commit 6ee288c96f9b701f71140e86d20cd16df778afba
Author: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
Date: Fri Mar 27 03:15:24 2026 +0100

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.
Rescan only the changed CPUID leaves, not to override any of the kernel's
previously force-set or unset cached CPUID bits.

[ bp: Zap unrelated changes. ]

Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Link: https://lore.kernel.org/all/20260327021645.555257-1-darwi@xxxxxxxxxxxxx

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a3df21d26460..01b64d04eb3b 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -339,13 +339,14 @@ bool cpuid_feature(void)

static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
{
+ const struct leaf_0x0_0 *l0;
+ unsigned int rescan_from;
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 +354,15 @@ 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 standard CPUID level. */
+ cpuid_refresh_leaf(c, 0x0);
+ l0 = cpuid_leaf(c, 0x0);
+ if (!l0)
+ return;
+
+ rescan_from = min_t(int, l0->max_std_leaf, c->cpuid_level) + 1;
+ cpuid_refresh_range(c, rescan_from, CPUID_BASE_END);
+ c->cpuid_level = l0->max_std_leaf;
}

static int __init x86_serial_nr_setup(char *s)

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette