summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorAhmed S. Darwish <darwi@linutronix.de>2026-03-27 03:15:22 +0100
committerBorislav Petkov (AMD) <bp@alien8.de>2026-05-11 13:09:30 +0200
commit3aa8f9fce8602d722948df641c7ca2828ee0a2f5 (patch)
treecb71432c2641bab494e4bb1be34bfd7456bb7b5e /rust/kernel
parent202311a754d4208ef156bc23b7ac310feccdea3b (diff)
x86/cpu: Introduce a centralized CPUID data model
** Context The x86-cpuid-db project generates a C header file with full C99 bitfield listings for all known CPUID leaf/subleaf query outputs. That header is now merged by parent commits at <asm/cpuid/leaf_types.h>, and is of the form: struct leaf_0x0_0 { /* CPUID(0x0).0 C99 bitfields */ }; ... struct leaf_0x4_n { /* CPUID(0x4).n C99 bitfields */ }; ... struct leaf_0xd_0 { /* CPUID(0xd).0 C99 bitfields */ }; struct leaf_0xd_1 { /* CPUID(0xd).1 C99 bitfields */ }; struct leaf_0xd_n { /* CPUID(0xd).n C99 bitfields */ }; ... ** Goal Introduce a structured, size-efficient, per-CPU, CPUID data repository. Use the x86-cpuid-db auto-generated data types, and custom CPUID leaf parsers, to build that repository. Given a leaf, subleaf, and index, provide direct memory access to the parsed and cached per-CPU CPUID output. ** Long-term goal Remove the need for drivers and other areas in the kernel to invoke direct CPUID queries. Only one place in the kernel should be allowed to use the CPUID instruction: the CPUID parser code. ** Implementation Introduce CPUID_LEAF()/CPUID_LEAF_N() to build a compact CPUID storage layout in the form: struct leaf_0x0_0 leaf_0x0_0[1]; struct leaf_parse_info leaf_0x0_0_info; struct leaf_0x1_0 leaf_0x1_0[1]; struct leaf_parse_info leaf_0x0_0_info; struct leaf_0x4_n leaf_0x4_n[8]; struct leaf_parse_info leaf_0x4_n_info; ... where each CPUID query stores its output at the designated leaf/subleaf array and has an associated "CPUID query info" structure. Embed the CPUID tables inside "struct cpuinfo_x86" to ensure early-boot and per-CPU access through the CPUs capability structures. Use an array of CPUID output storage entries for each leaf/subleaf combination to accommodate leaves which produce the same output format for a large subleaf range. This is typical for CPUID leaves enumerating hierarchical objects; e.g. CPUID(0x4) cache topology enumeration, CPUID(0xd) XSAVE enumeration, and CPUID(0x12) SGX Enclave Page Cache enumeration. ** New CPUID APIs Assuming a CPU capability structure 'c', provide macros to access the parsed and cached CPUID leaf/subleaf output. These macros resolve to a compile-time tokenization that ensures type-safety: const struct leaf_0x7_0 *l7_0; l7_0 = cpuid_subleaf(c, 0x7, 0); | | └────────┐ | └─────────┐ | * * * &c.cpuid.leaf_0x7_0[0] For CPUID leaves with multiple subleaves having the same output format, provide the APIs: const struct leaf_0x4_n *l4_0, *l4_1; l4_0 = cpuid_subleaf_n(c, 0x4, 0); | | └──────────┐ | └─────────┐ | * * v &c.cpuid.leaf_0x4_n[0] l4_1 = cpuid_subleaf_n(c, 0x4, 1); | | └──────────┐ | └─────────┐ | * * v &c.cpuid.leaf_0x4_n[1] where the indices 0, 1, n above can be passed dynamically; e.g., in an enumeration for loop. Add a clear rationale on why call sites should use the these new APIs instead of directly invoking CPUID. ** Next steps For now, define cached parse entries for CPUID(0x0) and CPUID(0x1). Generic parser logic to fill the CPUID tables, along with more CPUID leaves support, will be added next. Suggested-by: Thomas Gleixner <tglx@kernel.org> # CPUID data model Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> # x86-cpuid-db schema Suggested-by: Borislav Petkov <bp@alien8.de> # Early CPUID centralization drafts Suggested-by: Ingo Molnar <mingo@kernel.org> # CPUID headers restructuring Suggested-by: Sean Christopherson <seanjc@google.com> # cpuid_subleaf_n() APIs Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/all/20260327021645.555257-1-darwi@linutronix.de Link: https://lore.kernel.org/all/874ixernra.ffs@tglx Link: https://gitlab.com/x86-cpuid.org/x86-cpuid-db Link: https://lore.kernel.org/all/aBnSgu_JyEi8fvog@gmail.com Link: https://lore.kernel.org/all/aJ9TbaNMgaplKSbH@google.com
Diffstat (limited to 'rust/kernel')
0 files changed, 0 insertions, 0 deletions