RFC x86: Rework system-wide configuration masquerading as per-cpu data
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest34 patches 19 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/34 | x86/xen: Explain why calling get_cpu_cap() so early is a hackarch/ | +5 | 1 reply | |
| 2/34 | x86/xen: Remove early "debug" physical address lookupsarch/ arch/ | +2 | 2 replies | |
| 3/34 | x86/pci: Assume that clflush size is always providedarch/ | +3 | 1 reply | |
| 4/34 | x86/mm: Introduce physical address limit helperarch/ arch/ arch/ +12 more | +28 | 1 reply | |
| 5/34 | x86/cpu: Move /proc per-cpu ->x86_phys_bits reference to global onearch/ | +1 | 1 reply | |
| 6/34 | x86/boot: Use consistent value for iomem_resource.endarch/ arch/ | +9 | 2 replies | |
| 7/34 | x86/mm: Introduce virtual address space limit helperarch/ arch/ arch/ +3 more | +12 | 1 reply | |
| 8/34 | x86/cpu: Add CLFLUSH size helperarch/ arch/ arch/ +9 more | +23 | 0 replies | |
| 9/34 | x86/cpu: Introduce address configuration structurearch/ arch/ arch/ | +19 | 2 replies | |
| 10/34 | x86/cpu/amd: Use new "address configuration" infrastructurearch/ | +2 | 0 replies | |
| 11/34 | x86/cpu/intel: Prepare MKTME for "address configuration" infrastructurearch/ | +87 | 6 replies | |
| 12/34 | x86/cpu/intel: Actually use "address configuration" infrastructure for MKTMEarch/ | +2 | 2 replies | |
| 13/34 | x86/boot: Use address reduction config to handle erratumarch/ | +17 | 0 replies | |
| 14/34 | x86/cpu: Remove default physical address space settingsarch/ | +0 | 0 replies | |
| 15/34 | x86/cpu: Remove default x86_phys_bits assignmentarch/ | +0 | 0 replies | |
| 16/34 | x86/cpu: Move physical address limit out of cpuinfo_x86arch/ arch/ arch/ | +21 | 0 replies | |
| 17/34 | x86/cpu: Move virtual address limit out of cpuinfo_x86arch/ arch/ arch/ | +11 | 0 replies | |
| 18/34 | x86/cpu/centaur: Move cache alignment override to BSP initarch/ | +9 | 0 replies | |
| 19/34 | x86/cpu: Introduce cache alignment multiplierarch/ arch/ arch/ +1 more | +15 | 0 replies | |
| 20/34 | x86/cpu: Remove superfluous cache alignment assignmentsarch/ | +0 | 0 replies | |
| 21/34 | x86/cpu: Consolidate CLFLUSH size setting.arch/ | +24 | 0 replies | |
| 22/34 | x86/cpu: Move CLFLUSH size into global configarch/ arch/ | +3 | 0 replies | |
| 23/34 | x86/cpu: Move cache alignment configuration to global structarch/ arch/ arch/ | +5 | 0 replies | |
| 24/34 | x86/cpu: Establish 'min_cache_bits' configurationarch/ arch/ arch/ +1 more | +48 | 0 replies | |
| 25/34 | x86/cpu: Move cache bits to global configarch/ arch/ arch/ | +14 | 0 replies | |
| 26/34 | x86/cpu: Zap superfluous get_cpu_address_sizes()arch/ | +0 | 0 replies | |
| 27/34 | x86/cpu: Enforce read-only x86_config state (lightly)arch/ arch/ arch/ | +33 | 0 replies | |
| 28/34 | x86/cpu: Return sane defaults for early x86_config readsarch/ | +26 | 0 replies | |
| 29/34 | x86/xen: Remove extra get_cpu_address_sizes() callarch/ | +0 | 0 replies | |
| 30/34 | x86/cpu/centaur: Mark BSP init function as __initarch/ | +1 | 0 replies | |
| 31/34 | x86/cpu/intel: Mark BSP init function as __initarch/ | +1 | 0 replies | |
| 32/34 | x86/cpu/amd: Move memory encryption detectionarch/ | +55 | 0 replies | |
| 33/34 | x86/cpu: Make get_cpu_address_sizes() static and __initarch/ arch/ | +1 | 0 replies | |
| 34/34 | x86/cpu: Mark new boot CPU and config structures appropriatelyarch/ | +2 | 0 replies |
Reviews trailers per patch
6 of 34 patches have a Reviewed-by or Acked-by.
| Patch | Kai Huang | Borislav Petkov (AMD) | Juergen Gross |
|---|---|---|---|
| 1/34 | |||
| 2/34 | R-b | R-b | |
| 3/34 | R-b | ||
| 4/34 | R-b | ||
| 5/34 | R-b | ||
| 6/34 | |||
| 7/34 | R-b | ||
| 8/34 | |||
| 9/34 | |||
| 10/34 | |||
| 11/34 | R-b | ||
| 12/34 | |||
| 13/34 | |||
| 14/34 | |||
| 15/34 | |||
| 16/34 | |||
| 17/34 | |||
| 18/34 | |||
| 19/34 | |||
| 20/34 | |||
| 21/34 | |||
| 22/34 | |||
| 23/34 | |||
| 24/34 | |||
| 25/34 | |||
| 26/34 | |||
| 27/34 | |||
| 28/34 | |||
| 29/34 | |||
| 30/34 | |||
| 31/34 | |||
| 32/34 | |||
| 33/34 | |||
| 34/34 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.
Cover letter [RFC][PATCH 00/34] [RFC] x86: Rework system-wide configuration masquerading as per-cpu data
tl;dr: This tries to be more regimented in how system-wide x86 processor configuration data is initialized. It does that by moving fields out of the per-cpu 'struct cpuinfo_x86' and into a new structure. It also requires that the boot CPU set these data up *once* and then be left alone.
This is a more comprehensive approach to avoid the random tinkering in patches like these:
https://lore.kernel.org/all/[email protected]/
--
'struct cpuinfo_x86' is a mess. At a high level, it can be thought of as a CPU enumeration cache that (among other things) avoids using CPUID constantly. There's a copy of it for each CPU, but often the 'boot_cpu_data' version is the only one that counts. Its fields are written in basically random order, including a memcpy() into the secondary processor copies from 'boot_cpu_data'.
This series focuses on a subset of the 'cpuinfo_x86' fields that must be consistent across all CPUs:
* The virtual and physical sizes supported by the CPU
* The number of those physical bits that the caches comprehend
* The size of a cacheline that CLFLUSH works on
* The actual alignment that matters to the caches (can be different from that CLFLUSH size)
There are a few random folks cc'd here because their subsystem reads one or more of these things in an x86 #ifdef of some kind.
There's a mishmash of ways to obtain these from CPUID, plus fixups for erratum and general processor wonkiness. There are also defaults for these for processors that, for instance, don't even _have_ CPUID support. I think virt/phys_bits can be set and overwritten no fewer than five times!
Let's bring some order to the chaos.
First, create some abstractions so that there are no longer direct explicit accesses to some 'boot_cpu_data' fields. This also provides a way to do sanity checking so nothing consumes garbage.
Second, separate out the address configuration inputs from the resulting values. The inputs are provided in early boot by the boot processor and stashed in x86_addr_config.
Third, remove global, shared configuration from 'struct cpuinfo_x86'. Put it in a new structure: 'struct x86_sys_config'.
This creates a simple set of rules:
1. The boot CPU populates 'bsp_addr_config' and nothing ever writes to it again
2. get_cpu_address_sizes() reads 'bsp_addr_config' and writes
'x86_config'
3. 'bsp_addr_config' is never read again
4. 'x86_config' is never written again
The centralized helpers also now provide a chance of enforcing those rules. Finish up the series by enforcing those rules and spitting out a warning when they are violated. This warning mechanism works in *very* early boot and is a little unusual. It could use some more eyeballs (Subject: Enforce read-only x86_config state).
=== FAQ ===
== Why are both 'bsp_addr_config' and 'x86_config' needed? ==
Having defined, separate lifetimes helps enforce the new rules.
Once everything is in place 'bsp_addr_config' is only used at boot and can be marked __init. Mostpost can help find users of it that leak to after boot. Secondary CPU startup code can't be __init (because of CPU hotplug) this helps ensure that 'bsp_addr_config' can only be referenced from boot CPU code.
'x86_config' can also be __ro_after_init, which helps mitigate the chance of it becoming tweaked after boot and growing into a little mini version of 'boot_cpu_data' with all the same problems.
--
Ideas for future work (probably in another series):
* Consolidate defaults in x86_config accessors and get_cpu_address_sizes() down to one copy
* Can we do something more aggressive with x86_clflush_size()? Is it ever anything other than 64 bytes on 64-bit?