Re: [PATCH 11/11] x86/cpu: Make all all CPUID leaf names consistent
From: Dave Hansen
Date: Fri Dec 06 2024 - 18:01:40 EST
On 11/29/24 10:27, Borislav Petkov wrote:
> Well, enum cpuid_leafs as it is now is the *indices* into the cap flags array:
>
> struct cpuinfo_x86 {
>
> ...
>
> __u32 x86_capability[NCAPINTS + NBUGINTS];
>
> And having a "CPUID_" prefixed thing and a "CPUID_LEAF_" prefixed other thing
> is going to cause confusion.
>
> And renaming enum cpuid_leafs is going to cause a massive churn...
Wait a sec though:
$ git grep 'enum cpuid_leafs' arch/x86/
arch/x86/include/asm/cpufeature.h:enum cpuid_leafs
arch/x86/kvm/cpuid.c:static __always_inline void kvm_cpu_cap_mask(enum
cpuid_leafs leaf, u32 mask)
So there is only one direct reference to the type.
I think all it will take to rename the _type_ is something like the
attached. Also, I think the new name 'x86_capability_words' and variable
'cap_nr' make the KVM site a lot more readable.
Thoughts?
---
b/arch/x86/include/asm/cpufeature.h | 2 +-
b/arch/x86/kvm/cpuid.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff -puN arch/x86/include/asm/cpufeature.h~rename-cpuid_leafs arch/x86/include/asm/cpufeature.h
--- a/arch/x86/include/asm/cpufeature.h~rename-cpuid_leafs 2024-12-06 14:57:52.350793675 -0800
+++ b/arch/x86/include/asm/cpufeature.h 2024-12-06 14:58:43.464719842 -0800
@@ -10,7 +10,7 @@
#include <linux/bitops.h>
#include <asm/alternative.h>
-enum cpuid_leafs
+enum x86_capability_words
{
CPUID_1_EDX = 0,
CPUID_8000_0001_EDX,
diff -puN arch/x86/kvm/cpuid.c~rename-cpuid_leafs arch/x86/kvm/cpuid.c
--- a/arch/x86/kvm/cpuid.c~rename-cpuid_leafs 2024-12-06 14:58:45.084780924 -0800
+++ b/arch/x86/kvm/cpuid.c 2024-12-06 14:59:24.818279432 -0800
@@ -594,14 +594,14 @@ void kvm_cpu_cap_init_kvm_defined(enum k
__kvm_cpu_cap_mask(leaf);
}
-static __always_inline void kvm_cpu_cap_mask(enum cpuid_leafs leaf, u32 mask)
+static __always_inline void kvm_cpu_cap_mask(enum x86_capability_words cap_nr, u32 mask)
{
/* Use kvm_cpu_cap_init_kvm_defined for KVM-only leafs. */
- BUILD_BUG_ON(leaf >= NCAPINTS);
+ BUILD_BUG_ON(cap_nr >= NCAPINTS);
- kvm_cpu_caps[leaf] &= mask;
+ kvm_cpu_caps[cap_nr] &= mask;
- __kvm_cpu_cap_mask(leaf);
+ __kvm_cpu_cap_mask(cap_nr);
}
void kvm_set_cpu_caps(void)
_