[PATCH v7 013/120] x86/cpu: Use parsed CPUID(0x80000000)

"Ahmed S. Darwish" <[email protected]> Thu, 28 May 2026 17:37:35 +0200
Newsgroups dev.linux.lists.x86-cpuid,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
At early boot code, use parsed CPUID(0x80000000) instead of invoking a
direct CPUID query.

The original code has the check:

    extended_cpuid_level = ((eax & 0xffff0000) == 0x80000000) ? eax : 0;

to protect against Intel 32-bit machines without an extended range, where a
CPUID(0x80000000) query will repeat the output of the max-valid standard
CPUID leaf output.

A similar check is already done at the CPUID parser's own CPUID(0x80000000)
read function:

    if (CPUID_RANGE(el0->max_ext_leaf) != CPUID_EXT_START) {
        // Handle error
    }

Thus, for the call-site, the parsed CPUID NULL check below:

    el0 = cpuid_leaf(c, 0x80000000);
    extended_cpuid_level = el0 ? el0->max_ext_leaf : 0;

is sufficient.

Signed-off-by: Ahmed S. Darwish <[email protected]>
---
 arch/x86/kernel/cpu/common.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 257808609ef5..9b05a747161f 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1019,6 +1019,7 @@ static void init_speculation_control(struct cpuinfo_x86 *c)
 
 void get_cpu_cap(struct cpuinfo_x86 *c)
 {
+	const struct leaf_0x80000000_0 *el0 = cpuid_leaf(c, 0x80000000);
 	u32 eax, ebx, ecx, edx;
 
 	/* Intel-defined flags: level 0x00000001 */
@@ -1054,12 +1055,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 		c->x86_capability[CPUID_D_1_EAX] = eax;
 	}
 
-	/*
-	 * Check if extended CPUID leaves are implemented: Max extended
-	 * CPUID leaf must be in the 0x80000001-0x8000ffff range.
-	 */
-	eax = cpuid_eax(0x80000000);
-	c->extended_cpuid_level = ((eax & 0xffff0000) == 0x80000000) ? eax : 0;
+	c->extended_cpuid_level = el0 ? el0->max_ext_leaf : 0;
 
 	if (c->extended_cpuid_level >= 0x80000001) {
 		cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
-- 
2.54.0