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

Borislav Petkov <[email protected]> Wed, 13 May 2026 17:27:42 +0200
Newsgroups dev.linux.lists.x86-cpuid,org.kernel.vger.linux-kernel
Message-ID <20260513152742.GDagSYbheCBWwNeVj-@fat_crate.local>
On Tue, May 12, 2026 at 04:34:12PM +0200, Borislav Petkov wrote:
> On Tue, May 12, 2026 at 09:12:25AM +0200, Ahmed S. Darwish wrote:
> > So the min_t()'s intent is just to be defensive against hardware surprises.
> 
> But when you read l0->max_std_leaf, you always get the current, highest base
> level. So there's nothing to protect against.
> 
> Or am I missing something?

Yeah, I am... might skip some leafs depending on how the max leaf changes.

So, just to be on the safe side, let's simply rescan the whole range again.

Diff ontop.

---
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 01b64d04eb3b..c51cdcad7875 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -340,7 +340,6 @@ 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)
@@ -354,15 +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 CPUID(0x3) can change the maximum standard CPUID level. */
+	/* 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 = 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;
+
+	/* Rescan from the whole range. */
+	cpuid_refresh_range(c, 0, CPUID_BASE_END);
 }
 
 static int __init x86_serial_nr_setup(char *s)

-- 
Regards/Gruss,
    Boris.

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