x86/cpuid: Headers cleanup
Subsystems (6)
Ahmed S. Darwish
reviewerv2 cover x86/cpuid: Headers cleanup
Hi,
Most of the patch queue's v1 is now merged at tip:x86/core.
On top of that, introduce a kernel-doc fixup (Sorry, missed that).
Then, do the renames:
hypervisor_cpuid_base() ➤ cpuid_base_hypervisor()
for_…_hypervisor_cpuid_base() ➤ for_…_cpuid_base_hypervisor()
instead of:
hypervisor_cpuid_base() ➤ cpuid_hypervisor_base()
for_…_hypervisor_cpuid_base() ➤ for_…_cpuid_hypervisor_base()
to keep "cpuid_base" in one peace:
https://lore.kernel.org/x86-cpuid/[email protected]
Thanks!
Cover v1
--------
( [PATCH v1 0/9] x86/cpuid: Headers cleanup
https://lore.kernel.org/lkml/[email protected] )
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/[email protected]
as suggested by Ingo here:
https://lore.kernel.org/lkml/[email protected]
* 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/cpuid/
├── 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_REG_native()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 (2):
x86/cpuid: Fix CPUID(0x2) iterator kernel-doc
x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()
arch/x86/include/asm/acrn.h | 2 +- arch/x86/include/asm/cpuid/api.h | 18 +++++++++--------- arch/x86/include/asm/xen/hypervisor.h | 2 +- arch/x86/kernel/jailhouse.c | 2 +- arch/x86/kernel/kvm.c | 2 +- arch/x86/kvm/cpuid.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-)
base-commit: 234792ea4421499f123e73b2e6411469a561a123
Signature · 1 line
2.49.0
Ahmed S. Darwish
reviewerPATCH v2 1/2 x86/cpuid: Fix CPUID(0x2) iterator kernel-doc
The CPUID(0x2) cache/TLB descriptors iterator has been recently changed from:
for_each_leaf_0x2_entry(regs, __ptr, entry)
to:
for_each_cpuid_0x2_desc(_regs, _ptr, _desc)
but the attached kernel-doc was not fully adapted. Fix it.
--- arch/x86/include/asm/cpuid/api.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/cpuid/api.h +6 -6
@@ -252,15 +252,15 @@ static inline void cpuid_leaf_0x2(union leaf_0x2_regs *regs)/** * for_each_cpuid_0x2_desc() - Iterator for parsed CPUID(0x2) descriptors -* @regs: CPUID(0x2) register output, as returned by cpuid_leaf_0x2() -* @__ptr: u8 pointer, for macro internal use only -* @desc: Pointer to parsed CPUID(0x2) descriptor at each iteration +* @_regs: CPUID(0x2) register output, as returned by cpuid_leaf_0x2() +* @_ptr: u8 pointer, for macro internal use only +* @_desc: Pointer to the parsed CPUID(0x2) descriptor at each iteration * * Loop over the 1-byte descriptors in the passed CPUID(0x2) output registers -* @regs. Provide the parsed information for each descriptor through @desc. +* @_regs. Provide the parsed information for each descriptor through @_desc. * -* To handle cache-specific descriptors, switch on @entry->c_type. For TLB -* descriptors, switch on @entry->t_type. +* To handle cache-specific descriptors, switch on @_desc->c_type. For TLB +* descriptors, switch on @_desc->t_type. * * Example usage for cache descriptors:: *
Signature · 1 line
2.49.0
Re: [PATCH v2 1/2] x86/cpuid: Fix CPUID(0x2) iterator kernel-doc
Quoted 5 lines · Ahmed S. Darwish
The CPUID(0x2) cache/TLB descriptors iterator has been recently changed from:
for_each_leaf_0x2_entry(regs, __ptr, entry)
Quoted 8 lines
to:
for_each_cpuid_0x2_desc(_regs, _ptr, _desc)but the attached kernel-doc was not fully adapted. Fix it.
Fixes c4c9ea879c3b ("x86/cpuid: Rename cpuid_get_leaf_0x2_regs() to cpuid_leaf_0x2()")Signed-off-by Ahmed S. Darwish <[email protected]>
I've folded this fix back into the originator commit.
Thanks,
Ingo
Ahmed S. Darwish
reviewerPATCH v2 2/2 x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_hypervisor_base()
In reply to Ahmed S. DarwishIn order to let all the APIs under <cpuid/api.h> have a shared "cpuid_" namespace, rename hypervisor_cpuid_base() to cpuid_base_hypervisor().
To align with the new style, also rename:
for_each_possible_hypervisor_cpuid_base(function)
to:
for_each_possible_cpuid_base_hypervisor(function)
Adjust call-sites accordingly.
--- arch/x86/include/asm/acrn.h | 2 +- arch/x86/include/asm/cpuid/api.h | 6 +++--- arch/x86/include/asm/xen/hypervisor.h | 2 +- arch/x86/kernel/jailhouse.c | 2 +- arch/x86/kernel/kvm.c | 2 +- arch/x86/kvm/cpuid.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/include/asm/acrn.h +1 -1
@@ -25,7 +25,7 @@ void acrn_remove_intr_handler(void);static inline u32 acrn_cpuid_base (void ) {if (boot_cpu_has (X86_FEATURE_HYPERVISOR )) -return hypervisor_cpuid_base ("ACRNACRNACRN" ,0 ); +return cpuid_base_hypervisor ("ACRNACRNACRN" ,0 );return 0 ; }
arch/x86/include/asm/cpuid/api.h +3 -3
@@ -188,14 +188,14 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)return false; } -#define for_each_possible_hypervisor_cpuid_base (function) \ +#define for_each_possible_cpuid_base_hypervisor (function) \ for (function = 0x40000000; function < 0x40010000; function += 0x100) -static inline u32 hypervisor_cpuid_base (const char *sig,u32 leaves) +static inline u32 cpuid_base_hypervisor (const char *sig,u32 leaves) {u32 base, eax, signature[3 ]; -for_each_possible_hypervisor_cpuid_base (base) { +for_each_possible_cpuid_base_hypervisor (base) {cpuid (base, &eax, &signature[0 ], &signature[1 ], &signature[2 ]);/*
arch/x86/include/asm/xen/hypervisor.h +1 -1
@@ -43,7 +43,7 @@ extern struct start_info *xen_start_info;static inline uint32_t xen_cpuid_base (void ) { -return hypervisor_cpuid_base (XEN_SIGNATURE ,2 ); +return cpuid_base_hypervisor (XEN_SIGNATURE ,2 ); }struct pci_dev ;
arch/x86/kernel/jailhouse.c +1 -1
@@ -49,7 +49,7 @@ static uint32_t jailhouse_cpuid_base(void) !boot_cpu_has(X86_FEATURE_HYPERVISOR))return 0 ; -return hypervisor_cpuid_base ("Jailhouse\0\0\0" ,0 ); +return cpuid_base_hypervisor ("Jailhouse\0\0\0" ,0 ); }static uint32_t __init jailhouse_detect (void )
arch/x86/kernel/kvm.c +1 -1
@@ -875,7 +875,7 @@ static noinline uint32_t __kvm_cpuid_base(void)return 0 ;/* So we don't blow up on old processors */ if (boot_cpu_has (X86_FEATURE_HYPERVISOR )) -return hypervisor_cpuid_base (KVM_SIGNATURE ,0 ); +return cpuid_base_hypervisor (KVM_SIGNATURE ,0 );return 0 ; }
arch/x86/kvm/cpuid.c +1 -1
@@ -236,7 +236,7 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpstruct kvm_cpuid_entry2 *entry;u32 base; -for_each_possible_hypervisor_cpuid_base (base) { +for_each_possible_cpuid_base_hypervisor (base) { entry =kvm_find_cpuid_entry (vcpu, base);if (entry) {
Signature · 1 line
2.49.0
Ahmed S. Darwish
reviewerPATCH v3 1/1 x86/cpuid: Rename hypervisor_cpuid_base() to cpuid_base_hypervisor()
In order to let all the APIs under <cpuid/api.h> have a shared "cpuid_" namespace, rename hypervisor_cpuid_base() to cpuid_base_hypervisor().
To align with the new style, also rename:
for_each_possible_hypervisor_cpuid_base(function)
to:
for_each_possible_cpuid_base_hypervisor(function)
Adjust call-sites accordingly.
---
Changelog-v3: Fix commit subject line to include the new function name, cpuid_base_hypervisor().
arch/x86/include/asm/acrn.h | 2 +- arch/x86/include/asm/cpuid/api.h | 6 +++--- arch/x86/include/asm/xen/hypervisor.h | 2 +- arch/x86/kernel/jailhouse.c | 2 +- arch/x86/kernel/kvm.c | 2 +- arch/x86/kvm/cpuid.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/include/asm/acrn.h +1 -1
@@ -25,7 +25,7 @@ void acrn_remove_intr_handler(void);static inline u32 acrn_cpuid_base (void ) {if (boot_cpu_has (X86_FEATURE_HYPERVISOR )) -return hypervisor_cpuid_base ("ACRNACRNACRN" ,0 ); +return cpuid_base_hypervisor ("ACRNACRNACRN" ,0 );return 0 ; }
arch/x86/include/asm/cpuid/api.h +3 -3
@@ -188,14 +188,14 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)return false; } -#define for_each_possible_hypervisor_cpuid_base (function) \ +#define for_each_possible_cpuid_base_hypervisor (function) \ for (function = 0x40000000; function < 0x40010000; function += 0x100) -static inline u32 hypervisor_cpuid_base (const char *sig,u32 leaves) +static inline u32 cpuid_base_hypervisor (const char *sig,u32 leaves) {u32 base, eax, signature[3 ]; -for_each_possible_hypervisor_cpuid_base (base) { +for_each_possible_cpuid_base_hypervisor (base) {cpuid (base, &eax, &signature[0 ], &signature[1 ], &signature[2 ]);/*
arch/x86/include/asm/xen/hypervisor.h +1 -1
@@ -43,7 +43,7 @@ extern struct start_info *xen_start_info;static inline uint32_t xen_cpuid_base (void ) { -return hypervisor_cpuid_base (XEN_SIGNATURE ,2 ); +return cpuid_base_hypervisor (XEN_SIGNATURE ,2 ); }struct pci_dev ;
arch/x86/kernel/jailhouse.c +1 -1
@@ -49,7 +49,7 @@ static uint32_t jailhouse_cpuid_base(void) !boot_cpu_has(X86_FEATURE_HYPERVISOR))return 0 ; -return hypervisor_cpuid_base ("Jailhouse\0\0\0" ,0 ); +return cpuid_base_hypervisor ("Jailhouse\0\0\0" ,0 ); }static uint32_t __init jailhouse_detect (void )
arch/x86/kernel/kvm.c +1 -1
@@ -875,7 +875,7 @@ static noinline uint32_t __kvm_cpuid_base(void)return 0 ;/* So we don't blow up on old processors */ if (boot_cpu_has (X86_FEATURE_HYPERVISOR )) -return hypervisor_cpuid_base (KVM_SIGNATURE ,0 ); +return cpuid_base_hypervisor (KVM_SIGNATURE ,0 );return 0 ; }
arch/x86/kvm/cpuid.c +1 -1
@@ -236,7 +236,7 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpstruct kvm_cpuid_entry2 *entry;u32 base; -for_each_possible_hypervisor_cpuid_base (base) { +for_each_possible_cpuid_base_hypervisor (base) { entry =kvm_find_cpuid_entry (vcpu, base);if (entry) {
--
2.49.0
[tip: x86/core] x86/cpuid: Rename hypervisor_cpuid_base()/for_each_possible_hypervisor_cpuid_base() to cpuid_base_hypervisor()/for_each_possible_cpuid_base_hypervisor()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 3bf8ce828419810f45a272948805cf9a2b685529 Gitweb: https://git.kernel.org/tip/3bf8ce828419810f45a272948805cf9a2b685529 Author: Ahmed S. Darwish <[email protected]> AuthorDate: Thu, 15 May 2025 22:28:59 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 16 May 2025 10:54:47 +02:00
x86/cpuid: Rename hypervisor_cpuid_base()/for_each_possible_hypervisor_cpuid_base() to cpuid_base_hypervisor()/for_each_possible_cpuid_base_hypervisor()
In order to let all the APIs under <cpuid/api.h> have a shared "cpuid_" namespace, rename hypervisor_cpuid_base() to cpuid_base_hypervisor().
To align with the new style, also rename:
for_each_possible_hypervisor_cpuid_base(function)
to:
for_each_possible_cpuid_base_hypervisor(function)
Adjust call-sites accordingly.
--- arch/x86/include/asm/acrn.h | 2 +- arch/x86/include/asm/cpuid/api.h | 6 +++--- arch/x86/include/asm/xen/hypervisor.h | 2 +- arch/x86/kernel/jailhouse.c | 2 +- arch/x86/kernel/kvm.c | 2 +- arch/x86/kvm/cpuid.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/include/asm/acrn.h +1 -1
@@ -25,7 +25,7 @@ void acrn_remove_intr_handler(void);static inline u32 acrn_cpuid_base (void ) {if (boot_cpu_has (X86_FEATURE_HYPERVISOR )) -return hypervisor_cpuid_base ("ACRNACRNACRN" ,0 ); +return cpuid_base_hypervisor ("ACRNACRNACRN" ,0 );return 0 ; }
arch/x86/include/asm/cpuid/api.h +3 -3
@@ -188,14 +188,14 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)return false; } -#define for_each_possible_hypervisor_cpuid_base (function) \ +#define for_each_possible_cpuid_base_hypervisor (function) \ for (function = 0x40000000; function < 0x40010000; function += 0x100) -static inline u32 hypervisor_cpuid_base (const char *sig,u32 leaves) +static inline u32 cpuid_base_hypervisor (const char *sig,u32 leaves) {u32 base, eax, signature[3 ]; -for_each_possible_hypervisor_cpuid_base (base) { +for_each_possible_cpuid_base_hypervisor (base) {cpuid (base, &eax, &signature[0 ], &signature[1 ], &signature[2 ]);/*
arch/x86/include/asm/xen/hypervisor.h +1 -1
@@ -43,7 +43,7 @@ extern struct start_info *xen_start_info;static inline uint32_t xen_cpuid_base (void ) { -return hypervisor_cpuid_base (XEN_SIGNATURE ,2 ); +return cpuid_base_hypervisor (XEN_SIGNATURE ,2 ); }struct pci_dev ;
arch/x86/kernel/jailhouse.c +1 -1
@@ -49,7 +49,7 @@ static uint32_t jailhouse_cpuid_base(void) !boot_cpu_has(X86_FEATURE_HYPERVISOR))return 0 ; -return hypervisor_cpuid_base ("Jailhouse\0\0\0" ,0 ); +return cpuid_base_hypervisor ("Jailhouse\0\0\0" ,0 ); }static uint32_t __init jailhouse_detect (void )
arch/x86/kernel/kvm.c +1 -1
@@ -875,7 +875,7 @@ static noinline uint32_t __kvm_cpuid_base(void)return 0 ;/* So we don't blow up on old processors */ if (boot_cpu_has (X86_FEATURE_HYPERVISOR )) -return hypervisor_cpuid_base (KVM_SIGNATURE ,0 ); +return cpuid_base_hypervisor (KVM_SIGNATURE ,0 );return 0 ; }
arch/x86/kvm/cpuid.c +1 -1
@@ -236,7 +236,7 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpstruct kvm_cpuid_entry2 *entry;u32 base; -for_each_possible_hypervisor_cpuid_base (base) { +for_each_possible_cpuid_base_hypervisor (base) { entry =kvm_find_cpuid_entry (vcpu, base);if (entry) {