Skip to contentSkip to conversation

KVM: x86: Remove duplicated calls of reverse_cpuid_check()

PATCH In review Binbin Wu 2 participants 3 messages Feb 21, 2023 – Feb 22, 2023

Subsystems (3)
lore
Share & tools
lore

Binbin Wu

author
#0 lore raw

PATCH 1/1 KVM: x86: Remove duplicated calls of reverse_cpuid_check()

Remove duplicated calls of reverse_cpuid_check() in __kvm_cpu_cap_mask() and kvm_cpu_cap_{clear, set, get}().

reverse_cpuid_check() is directly called by:
- feature_bit() / __feature_bit()
- x86_feature_cpuid()
- kvm_cpu_cap_{clear, set, get}()
- __kvm_cpu_cap_mask()
Also __kvm_cpu_cap_mask() calls x86_feature_cpuid(), and kvm_cpu_cap_{clear, set, get}() calls __feature_bit(). It makes the direct call of reverse_cpuid_check() duplicated.

For functions call reverse_cpuid_check() twice indirectly (e.g. cpuid_entry_get() calls both __feature_bit() and x86_feature_cpuid()), keep them as they are.

---
 arch/x86/kvm/cpuid.c | 2 --
 arch/x86/kvm/cpuid.h | 3 ---
 2 files changed, 5 deletions(-)
arch/x86/kvm/cpuid.c +0 -2
index 8f8edeaf8177..f4089d7a7c4c 100644
@@ -545,8 +545,6 @@ static __always_inline void __kvm_cpu_cap_mask(unsigned int leaf)
 	const struct cpuid_reg cpuid = x86_feature_cpuid(leaf * 32);
 	struct kvm_cpuid_entry2 entry;
 
-	reverse_cpuid_check(leaf);
-
 	cpuid_count(cpuid.function, cpuid.index,
 		    &entry.eax, &entry.ebx, &entry.ecx, &entry.edx);
 
arch/x86/kvm/cpuid.h +0 -3
index b1658c0de847..d781372a01e8 100644
@@ -192,7 +192,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);
 }
 
@@ -200,7 +199,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);
 }
 
@@ -208,7 +206,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);
 }
 

base-commit: e73ba25fdc241c06ab48a1f708a30305d6036e66

Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Binbin Wu

Remove duplicated calls of reverse_cpuid_check() in __kvm_cpu_cap_mask() and kvm_cpu_cap_{clear, set, get}().

I want to keep the checks even though they are redundant. There is no runtime cost, and the intent of the direct calls in the "upper" helpers is as much to document their usage constraints (input feature must be a compile-time constant) as it is to enforce correctness.

author
#2 lore raw
Quoted 7 lines · Sean Christopherson
Quoted 2 lines · Binbin Wu

Remove duplicated calls of reverse_cpuid_check() in __kvm_cpu_cap_mask() and kvm_cpu_cap_{clear, set, get}().

I want to keep the checks even though they are redundant. There is no runtime cost, and the intent of the direct calls in the "upper" helpers is as much to document their usage constraints (input feature must be a compile-time constant) as it is to enforce correctness.

Got it.