]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Do reverse CPUID sanity checks in __feature_leaf()
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:33:47 +0000 (17:33 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:19:42 +0000 (14:19 -0800)
Do the compile-time sanity checks on reverse_cpuid in __feature_leaf() so
that higher level APIs don't need to "manually" perform the sanity checks.

No functional change intended.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241128013424.4096668-21-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.h
arch/x86/kvm/reverse_cpuid.h

index e76a1f008faf5ee6df3d91575c4cc4a921eb3e38..99d4f624561082a86442a7ac09a20eede742e114 100644 (file)
@@ -180,7 +180,6 @@ static __always_inline void kvm_cpu_cap_clear(unsigned int x86_feature)
 {
        unsigned int x86_leaf = __feature_leaf(x86_feature);
 
-       reverse_cpuid_check(x86_leaf);
        kvm_cpu_caps[x86_leaf] &= ~__feature_bit(x86_feature);
 }
 
@@ -188,7 +187,6 @@ static __always_inline void kvm_cpu_cap_set(unsigned int x86_feature)
 {
        unsigned int x86_leaf = __feature_leaf(x86_feature);
 
-       reverse_cpuid_check(x86_leaf);
        kvm_cpu_caps[x86_leaf] |= __feature_bit(x86_feature);
 }
 
@@ -196,7 +194,6 @@ static __always_inline u32 kvm_cpu_cap_get(unsigned int x86_feature)
 {
        unsigned int x86_leaf = __feature_leaf(x86_feature);
 
-       reverse_cpuid_check(x86_leaf);
        return kvm_cpu_caps[x86_leaf] & __feature_bit(x86_feature);
 }
 
index e46220ece83c60b986faee8e3e8421a82cb176ae..1d2db9d529ff69b5573f9289df55c27e1b487312 100644 (file)
@@ -145,7 +145,10 @@ static __always_inline u32 __feature_translate(int x86_feature)
 
 static __always_inline u32 __feature_leaf(int x86_feature)
 {
-       return __feature_translate(x86_feature) / 32;
+       u32 x86_leaf = __feature_translate(x86_feature) / 32;
+
+       reverse_cpuid_check(x86_leaf);
+       return x86_leaf;
 }
 
 /*
@@ -168,7 +171,6 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned int x86_featu
 {
        unsigned int x86_leaf = __feature_leaf(x86_feature);
 
-       reverse_cpuid_check(x86_leaf);
        return reverse_cpuid[x86_leaf];
 }