[PATCH v1 0/9] x86/cpuid: Headers cleanup

Ahmed S. Darwish posted 9 patches 7 months, 1 week ago
There is a newer version of this series
arch/x86/boot/compressed/pgtable_64.c     |   4 +-
arch/x86/boot/compressed/sev.c            |   8 +-
arch/x86/coco/sev/core.c                  |   2 +-
arch/x86/events/intel/pt.c                |   2 +-
arch/x86/include/asm/acrn.h               |   2 +-
arch/x86/include/asm/cpuid.h              |   9 --
arch/x86/include/asm/cpuid/api.h          | 103 ++++++++++++++++++----
arch/x86/include/asm/cpuid/leaf_0x2_api.h |  73 ---------------
arch/x86/include/asm/cpuid/types.h        |   3 +-
arch/x86/include/asm/microcode.h          |   2 +-
arch/x86/include/asm/processor.h          |   2 +-
arch/x86/include/asm/xen/hypervisor.h     |   2 +-
arch/x86/kernel/acpi/cstate.c             |   2 +-
arch/x86/kernel/amd_nb.c                  |   2 +-
arch/x86/kernel/cpu/cacheinfo.c           |  18 ++--
arch/x86/kernel/cpu/common.c              |  12 +--
arch/x86/kernel/cpu/intel.c               |  16 ++--
arch/x86/kernel/cpu/microcode/amd.c       |   2 +-
arch/x86/kernel/cpu/microcode/core.c      |   8 +-
arch/x86/kernel/cpu/microcode/intel.c     |   2 +-
arch/x86/kernel/cpu/microcode/internal.h  |   4 +-
arch/x86/kernel/fpu/xstate.c              |   2 +-
arch/x86/kernel/head32.c                  |   2 +-
arch/x86/kernel/hpet.c                    |   2 +-
arch/x86/kernel/jailhouse.c               |   2 +-
arch/x86/kernel/kvm.c                     |   2 +-
arch/x86/kernel/paravirt.c                |   2 +-
arch/x86/kernel/process.c                 |   2 +-
arch/x86/kernel/smpboot.c                 |   2 +-
arch/x86/kernel/tsc.c                     |   2 +-
arch/x86/kvm/cpuid.c                      |   4 +-
arch/x86/mm/mem_encrypt_identity.c        |   6 +-
arch/x86/virt/svm/sev.c                   |   2 +-
arch/x86/xen/enlighten_pv.c               |   6 +-
drivers/acpi/acpi_pad.c                   |   2 +-
drivers/dma/ioat/dca.c                    |   2 +-
drivers/firmware/efi/libstub/x86-5lvl.c   |   4 +-
drivers/idle/intel_idle.c                 |   2 +-
drivers/platform/x86/intel/pmc/core.c     |   2 +-
sound/soc/intel/avs/tgl.c                 |   2 +-
40 files changed, 159 insertions(+), 169 deletions(-)
delete mode 100644 arch/x86/include/asm/cpuid.h
delete mode 100644 arch/x86/include/asm/cpuid/leaf_0x2_api.h
[PATCH v1 0/9] x86/cpuid: Headers cleanup
Posted by Ahmed S. Darwish 7 months, 1 week ago
Hi,

This is a CPUID headers cleanup series, on top of tip:x86/cpu.  It is a
precursor for the upcoming v2 of the CPUID parser:

    [PATCH v1 00/26] x86: Introduce centralized CPUID model
    https://lore.kernel.org/lkml/20250506050437.10264-1-darwi@linutronix.de

as suggested by Ingo here:

    https://lore.kernel.org/lkml/aBnSgu_JyEi8fvog@gmail.com

* Summary:

The current CPUID header structure is:

    include/asm/
    ├── cpuid
    │   ├── api.h
    │   ├── leaf_0x2_api.h
    │   └── types.h
    └── cpuid.h

Simplify it into:

    include/asm/
    ├── api.h
    └── types.h

Standardize the CPUID header namespace by enforcing a "cpuid_" prefix for
all exported symbols.  That is:

    have_cpuid_p()		➤	cpuid_feature()
    hypervisor_cpuid_base()	➤	cpuid_hypervisor_base()
    native_cpuid()		➤	cpuid_native()
    native_cpuid_REG()		➤	cpuid_native_REG()

Also rename:

    cpuid_get_leaf_0x2_regs()	➤	cpuid_leaf_0x2()

for consistency with the other <asm/cpuid/api.h> accessors that return
full CPUID register output; i.e., cpuid_leaf() and cpuid_subleaf().

Finally, rename:

    for_each_leaf_0x2_entry()   ➤	for_each_cpuid_0x2_desc()

to include "cpuid" in the iterator name, and since what is being iterated
upon is CPUID(0x2) cache and TLB "descriptos", not "entries".

* Testing:

- Basic one-by-one allyesconfig compilation

- Comparison of a before/after of below files:

  - /proc/cpuinfo
  - /sys/devices/system/cpu/
  - /sys/kernel/debug/x86/topo/
  - dmesg --notime | grep 'Last level [id]TLB entries'

Thanks!

8<--

Ahmed S. Darwish (9):
  x86/cpuid: Move CPUID(0x2) APIs into <cpuid/api.h>
  x86/cpuid: Set <asm/cpuid/api.h> as the main CPUID header
  x86/cpuid: Rename have_cpuid_p() to cpuid_feature()
  x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()
  x86/cpuid: Rename cpuid_get_leaf_0x2_regs() to cpuid_leaf_0x2()
  x86/cacheinfo: Rename CPUID(0x2) descriptors iterator parameter
  x86/cpu: Rename CPUID(0x2) descriptors iterator parameter
  x86/cpuid: Rename native_cpuid() to cpuid_native()
  x86/cpuid: Rename native_cpuid_REG() to cpuid_native_REG()

 arch/x86/boot/compressed/pgtable_64.c     |   4 +-
 arch/x86/boot/compressed/sev.c            |   8 +-
 arch/x86/coco/sev/core.c                  |   2 +-
 arch/x86/events/intel/pt.c                |   2 +-
 arch/x86/include/asm/acrn.h               |   2 +-
 arch/x86/include/asm/cpuid.h              |   9 --
 arch/x86/include/asm/cpuid/api.h          | 103 ++++++++++++++++++----
 arch/x86/include/asm/cpuid/leaf_0x2_api.h |  73 ---------------
 arch/x86/include/asm/cpuid/types.h        |   3 +-
 arch/x86/include/asm/microcode.h          |   2 +-
 arch/x86/include/asm/processor.h          |   2 +-
 arch/x86/include/asm/xen/hypervisor.h     |   2 +-
 arch/x86/kernel/acpi/cstate.c             |   2 +-
 arch/x86/kernel/amd_nb.c                  |   2 +-
 arch/x86/kernel/cpu/cacheinfo.c           |  18 ++--
 arch/x86/kernel/cpu/common.c              |  12 +--
 arch/x86/kernel/cpu/intel.c               |  16 ++--
 arch/x86/kernel/cpu/microcode/amd.c       |   2 +-
 arch/x86/kernel/cpu/microcode/core.c      |   8 +-
 arch/x86/kernel/cpu/microcode/intel.c     |   2 +-
 arch/x86/kernel/cpu/microcode/internal.h  |   4 +-
 arch/x86/kernel/fpu/xstate.c              |   2 +-
 arch/x86/kernel/head32.c                  |   2 +-
 arch/x86/kernel/hpet.c                    |   2 +-
 arch/x86/kernel/jailhouse.c               |   2 +-
 arch/x86/kernel/kvm.c                     |   2 +-
 arch/x86/kernel/paravirt.c                |   2 +-
 arch/x86/kernel/process.c                 |   2 +-
 arch/x86/kernel/smpboot.c                 |   2 +-
 arch/x86/kernel/tsc.c                     |   2 +-
 arch/x86/kvm/cpuid.c                      |   4 +-
 arch/x86/mm/mem_encrypt_identity.c        |   6 +-
 arch/x86/virt/svm/sev.c                   |   2 +-
 arch/x86/xen/enlighten_pv.c               |   6 +-
 drivers/acpi/acpi_pad.c                   |   2 +-
 drivers/dma/ioat/dca.c                    |   2 +-
 drivers/firmware/efi/libstub/x86-5lvl.c   |   4 +-
 drivers/idle/intel_idle.c                 |   2 +-
 drivers/platform/x86/intel/pmc/core.c     |   2 +-
 sound/soc/intel/avs/tgl.c                 |   2 +-
 40 files changed, 159 insertions(+), 169 deletions(-)
 delete mode 100644 arch/x86/include/asm/cpuid.h
 delete mode 100644 arch/x86/include/asm/cpuid/leaf_0x2_api.h

base-commit: c1ab4ce3cb759f69fb9085a060e568b73e8f5cd8
-- 
2.49.0

Re: [PATCH v1 0/9] x86/cpuid: Headers cleanup
Posted by Ahmed S. Darwish 7 months, 1 week ago
On Thu, 08 May, Ahmed S. Darwish wrote:
>
> Simplify it into:
>
>     include/asm/
>     ├── api.h
>     └── types.h
>

Typo:

      include/asm/cpuid/
      ├── api.h
      └── types.h

Thanks,
Ahmed
Re: [PATCH v1 0/9] x86/cpuid: Headers cleanup
Posted by Ingo Molnar 7 months ago
* Ahmed S. Darwish <darwi@linutronix.de> wrote:

> Hi,
> 
> This is a CPUID headers cleanup series, on top of tip:x86/cpu.  It is a
> precursor for the upcoming v2 of the CPUID parser:
> 
>     [PATCH v1 00/26] x86: Introduce centralized CPUID model
>     https://lore.kernel.org/lkml/20250506050437.10264-1-darwi@linutronix.de
> 
> as suggested by Ingo here:
> 
>     https://lore.kernel.org/lkml/aBnSgu_JyEi8fvog@gmail.com
> 
> * Summary:
> 
> The current CPUID header structure is:
> 
>     include/asm/
>     ├── cpuid
>     │   ├── api.h
>     │   ├── leaf_0x2_api.h
>     │   └── types.h
>     └── cpuid.h
> 
> Simplify it into:
> 
>     include/asm/
>     ├── api.h
>     └── types.h
> 
> Standardize the CPUID header namespace by enforcing a "cpuid_" prefix for
> all exported symbols.  That is:
> 
>     have_cpuid_p()		➤	cpuid_feature()
>     hypervisor_cpuid_base()	➤	cpuid_hypervisor_base()
>     native_cpuid()		➤	cpuid_native()
>     native_cpuid_REG()		➤	cpuid_native_REG()
> 
> Also rename:
> 
>     cpuid_get_leaf_0x2_regs()	➤	cpuid_leaf_0x2()
> 
> for consistency with the other <asm/cpuid/api.h> accessors that return
> full CPUID register output; i.e., cpuid_leaf() and cpuid_subleaf().
> 
> Finally, rename:
> 
>     for_each_leaf_0x2_entry()   ➤	for_each_cpuid_0x2_desc()
> 
> to include "cpuid" in the iterator name, and since what is being iterated
> upon is CPUID(0x2) cache and TLB "descriptos", not "entries".
> 
> * Testing:
> 
> - Basic one-by-one allyesconfig compilation
> 
> - Comparison of a before/after of below files:
> 
>   - /proc/cpuinfo
>   - /sys/devices/system/cpu/
>   - /sys/kernel/debug/x86/topo/
>   - dmesg --notime | grep 'Last level [id]TLB entries'
> 
> Thanks!
> 
> 8<--
> 
> Ahmed S. Darwish (9):
>   x86/cpuid: Move CPUID(0x2) APIs into <cpuid/api.h>
>   x86/cpuid: Set <asm/cpuid/api.h> as the main CPUID header
>   x86/cpuid: Rename have_cpuid_p() to cpuid_feature()
>   x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()
>   x86/cpuid: Rename cpuid_get_leaf_0x2_regs() to cpuid_leaf_0x2()
>   x86/cacheinfo: Rename CPUID(0x2) descriptors iterator parameter
>   x86/cpu: Rename CPUID(0x2) descriptors iterator parameter
>   x86/cpuid: Rename native_cpuid() to cpuid_native()
>   x86/cpuid: Rename native_cpuid_REG() to cpuid_native_REG()

Thank you for doing this. I've reviewed the series and applied these:

    x86/cpuid: Move CPUID(0x2) APIs into <cpuid/api.h>
    x86/cpuid: Set <asm/cpuid/api.h> as the main CPUID header
    x86/cpuid: Rename have_cpuid_p() to cpuid_feature()
    x86/cpuid: Rename cpuid_get_leaf_0x2_regs() to cpuid_leaf_0x2()
    x86/cacheinfo: Rename CPUID(0x2) descriptors iterator parameter
    x86/cpu/intel: Rename CPUID(0x2) descriptors iterator parameter

I had some questions about:

    x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()
    x86/cpuid: Rename native_cpuid() to cpuid_native()

and you had better ideas about:

    x86/cpuid: Rename native_cpuid_REG() to cpuid_native_REG()

Thanks,

	Ingo
Re: [PATCH v1 0/9] x86/cpuid: Headers cleanup
Posted by Ahmed S. Darwish 7 months ago
On Thu, 15 May 2025, Ingo Molnar wrote:
>
> Thank you for doing this. I've reviewed the series and applied these:
>
>     x86/cpuid: Move CPUID(0x2) APIs into <cpuid/api.h>
>     x86/cpuid: Set <asm/cpuid/api.h> as the main CPUID header
>     x86/cpuid: Rename have_cpuid_p() to cpuid_feature()
>     x86/cpuid: Rename cpuid_get_leaf_0x2_regs() to cpuid_leaf_0x2()
>     x86/cacheinfo: Rename CPUID(0x2) descriptors iterator parameter
>     x86/cpu/intel: Rename CPUID(0x2) descriptors iterator parameter
>
> I had some questions about:
>
>     x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()
>     x86/cpuid: Rename native_cpuid() to cpuid_native()
>
> and you had better ideas about:
>
>     x86/cpuid: Rename native_cpuid_REG() to cpuid_native_REG()
>

Thanks a lot for all the support as usual :)

I'll send a v2 then for the single one left:

    x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()

and indeed drop:

   x86/cpuid: Rename native_cpuid() to cpuid_native()
   x86/cpuid: Rename native_cpuid_REG() to cpuid_native_REG()

All the best,
~ Ahmed