[tip: x86/cpu] x86/cpu: Use parsed CPUID(0x1)
From: tip-bot2 for Ahmed S. Darwish
Date: Fri Jul 31 2026 - 18:25:00 EST
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 173dfdce3ba8b7d54d2476f76f723438dbaff391
Gitweb: https://git.kernel.org/tip/173dfdce3ba8b7d54d2476f76f723438dbaff391
Author: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
AuthorDate: Thu, 28 May 2026 17:37:33 +02:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Fri, 31 Jul 2026 14:52:55 -07:00
x86/cpu: Use parsed CPUID(0x1)
On early boot CPU detection, use parsed CPUID(0x1) instead of a direct CPUID
query.
Beside the parser's centralization benefits, use the auto generated CPUID data
types, and their C99 bitfields, instead of doing ugly bitwise operations.
[ bp: - Use a common code pattern for l1 of fetching and checking it
right after that
- flip the check to save an indentation level
- align assignments vertically.
]
Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Link: https://patch.msgid.link/20260528153923.403473-12-darwi@xxxxxxxxxxxxx
---
arch/x86/kernel/cpu/common.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index e658f76..695319f 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -943,6 +943,7 @@ void get_cpu_vendor(struct cpuinfo_x86 *c)
void cpu_detect(struct cpuinfo_x86 *c)
{
const struct leaf_0x0_0 *l0 = cpuid_leaf(c, 0x0);
+ const struct leaf_0x1_0 *l1;
c->cpuid_level = l0->max_std_leaf;
*(u32 *)&c->x86_vendor_id[0] = l0->cpu_vendorid_0;
@@ -950,19 +951,18 @@ void cpu_detect(struct cpuinfo_x86 *c)
*(u32 *)&c->x86_vendor_id[8] = l0->cpu_vendorid_2;
c->x86 = 4;
- /* Intel-defined flags: level 0x00000001 */
- if (c->cpuid_level >= 0x00000001) {
- u32 junk, tfms, cap0, misc;
- cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
- c->x86 = x86_family(tfms);
- c->x86_model = x86_model(tfms);
- c->x86_stepping = x86_stepping(tfms);
+ l1 = cpuid_leaf(c, 0x1);
+ if (!l1)
+ return;
- if (cap0 & (1<<19)) {
- c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
- c->x86_cache_alignment = c->x86_clflush_size;
- }
+ c->x86 = cpuid_family(l1);
+ c->x86_model = cpuid_model(l1);
+ c->x86_stepping = l1->stepping;
+
+ if (l1->clflush) {
+ c->x86_clflush_size = l1->clflush_size * 8;
+ c->x86_cache_alignment = c->x86_clflush_size;
}
}