[PATCH v7 045/120] x86/cpu: Use parsed CPUID(0x80000008)

"Ahmed S. Darwish" <[email protected]> Thu, 28 May 2026 17:38:07 +0200
Newsgroups dev.linux.lists.x86-cpuid,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Use parsed CPUID(0x80000008) instead of issuing a direct CPUID query and
doing ugly bitwise operations.

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

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index d8e46eb0f5c5..d78063e4e665 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1102,10 +1102,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 
 void get_cpu_address_sizes(struct cpuinfo_x86 *c)
 {
-	u32 eax, ebx, ecx, edx;
+	const struct leaf_0x80000008_0 *el8 = cpuid_leaf(c, 0x80000008);
 
-	if (!cpu_has(c, X86_FEATURE_CPUID) ||
-	    (c->extended_cpuid_level < 0x80000008)) {
+	if (!cpu_has(c, X86_FEATURE_CPUID) || !el8) {
 		if (IS_ENABLED(CONFIG_X86_64)) {
 			c->x86_clflush_size = 64;
 			c->x86_phys_bits = 36;
@@ -1120,10 +1119,8 @@ void get_cpu_address_sizes(struct cpuinfo_x86 *c)
 				c->x86_phys_bits = 36;
 		}
 	} else {
-		cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
-
-		c->x86_virt_bits = (eax >> 8) & 0xff;
-		c->x86_phys_bits = eax & 0xff;
+		c->x86_virt_bits = el8->virt_addr_bits;
+		c->x86_phys_bits = el8->phys_addr_bits;
 
 		/* Provide a sane default if not enumerated: */
 		if (!c->x86_clflush_size)
-- 
2.54.0