[PATCH v7 040/120] x86/cpu/amd: Use parsed CPUID(0x80000005)
From: Ahmed S. Darwish
Date: Thu May 28 2026 - 12:06:15 EST
For AMD BSP init, use parsed CPUID(0x80000005) instead of issuing a direct
CPUID query and doing ugly bitwise operations.
Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/amd.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 62f74a7f2f8d..4fa16f2fd402 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -4,6 +4,7 @@
#include <linux/dmi.h>
#include <linux/elf.h>
#include <linux/mm.h>
+#include <linux/sizes.h>
#include <linux/kvm_types.h>
#include <linux/io.h>
#include <linux/sched.h>
@@ -422,6 +423,8 @@ static void tsa_init(struct cpuinfo_x86 *c)
static void bsp_init_amd(struct cpuinfo_x86 *c)
{
+ const struct leaf_0x80000005_0 *el5 = cpuid_leaf(c, 0x80000005);
+
if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
if (c->x86 > 0x10 ||
@@ -434,13 +437,8 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
}
}
- if (c->x86 == 0x15) {
- unsigned long upperbit;
- u32 cpuid, assoc;
-
- cpuid = cpuid_edx(0x80000005);
- assoc = cpuid >> 16 & 0xff;
- upperbit = ((cpuid >> 24) << 10) / assoc;
+ if (c->x86 == 0x15 && el5) {
+ unsigned long upperbit = (el5->l1_icache_size_kb * SZ_1K) / el5->l1_icache_assoc;
va_align.mask = (upperbit - 1) & PAGE_MASK;
va_align.flags = ALIGN_VA_32 | ALIGN_VA_64;
--
2.54.0