Re: [PATCH v6 09/90] x86/cpuid: Introduce a centralized CPUID parser

From: Maciej Wieczor-Retman

Date: Wed Apr 15 2026 - 02:10:32 EST


On 2026-03-27 at 03:15:23 +0100, Ahmed S. Darwish wrote:
>Introduce a CPUID parser for populating the system's CPUID tables.
>
>Since accessing a leaf within the CPUID table requires compile time
>tokenization, split the parser into two stages:
>
> (a) Compile-time macros for tokenizing the leaf/subleaf offsets within
> the CPUID table.
>
> (b) Generic runtime code to fill the CPUID data, using a parsing table
> which collects these compile-time offsets.
>
>For actual CPUID output parsing, support both generic and leaf-specific
>read functions.
>
>To ensure CPUID data early availability, invoke the parser during early
>boot, early Xen boot, and at early secondary CPUs bring up.
>
>Provide call site APIs to refresh a single leaf, or a leaf range, within
>the CPUID tables. This is for sites issuing MSR writes that partially
>changes the CPU's CPUID layout. Doing full CPUID table rescans in such

changes -> change?

>cases will be destructive since the CPUID tables will host all of the
>kernel's X86_FEATURE flags at a later stage.

Also should cpuid_parser.c/.h be attached to some subsystem in MAINTAINERS? Not
sure if it should or shouldn't but I noticed you added leaf_types.h before and
was curious if not adding new files is intentional here.

>
...
>diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid_parser.c
>new file mode 100644
>index 000000000000..898b0c441431
>--- /dev/null
>+++ b/arch/x86/kernel/cpu/cpuid_parser.c
...
>+static unsigned int cpuid_range_max_leaf(const struct cpuid_table *t, unsigned int range)
>+{
>+ const struct leaf_0x0_0 *l0 = __cpuid_table_subleaf(t, 0x0, 0);
>+
>+ switch (range) {
>+ case CPUID_BASE_START: return l0 ? l0->max_std_leaf : 0;
>+ default: return 0;
>+ }
>+}

Trailing statements should go on the next line, right?

(resending this email as the old one lost the in-reply-to)
--
Kind regards
Maciej Wieczór-Retman