[PATCH v5 15/35] x86/cpu: Use parsed CPUID(0x80000002)..CPUID(0x80000004)

"Ahmed S. Darwish" <[email protected]> Fri, 5 Sep 2025 14:14:55 +0200
Newsgroups dev.linux.lists.x86-cpuid,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
For CPU brand string enumeration, use parsed CPUID(0x80000002) to
CPUID(0x80000004) access instead of directly invoking CPUID queries.

This allows centralizing CPUID queries, and the access of their cached
data output, to one place in the kernel.

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

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 0a0340a7ac1c..1d45dbdd0e05 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -780,16 +780,19 @@ static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
 
 static void get_model_name(struct cpuinfo_x86 *c)
 {
-	unsigned int *v;
+	const struct cpuid_regs *leaf[] = {
+		cpuid_leaf_raw(c, 0x80000002),
+		cpuid_leaf_raw(c, 0x80000003),
+		cpuid_leaf_raw(c, 0x80000004),
+	};
 	char *p, *q, *s;
 
-	if (c->extended_cpuid_level < 0x80000004)
+	if (!leaf[0] || !leaf[1] || !leaf[2])
 		return;
 
-	v = (unsigned int *)c->x86_model_id;
-	cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
-	cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
-	cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
+	for (int i = 0; i < ARRAY_SIZE(leaf); i++)
+		*(struct cpuid_regs *)&c->x86_model_id[16 * i] = *leaf[i];
+
 	c->x86_model_id[48] = 0;
 
 	/* Trim whitespace */
-- 
2.50.1