Skip to content

Commit 1028893

Browse files
committed
KVM: x86: Bury guest_cpuid_is_amd_or_hygon() in cpuid.c
Move guest_cpuid_is_amd_or_hygon() into cpuid.c now that, except for one Intel quirk in the emulator, KVM checks for AMD vs. Intel *compatible* vCPUs, not exact vendors, i.e. now that there should not be any reason for KVM at-large to care about the exact vendor. Opportunistically refactor the guts of the helper to use "entry" instead of "best", and short circuit the !entry path to make the common case more readable. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent bdaff4f commit 1028893

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ static bool kvm_cpuid_has_hyperv(struct kvm_cpuid_entry2 *entries, int nent)
335335
#endif
336336
}
337337

338+
static bool guest_cpuid_is_amd_or_hygon(struct kvm_vcpu *vcpu)
339+
{
340+
struct kvm_cpuid_entry2 *entry;
341+
342+
entry = kvm_find_cpuid_entry(vcpu, 0);
343+
if (!entry)
344+
return false;
345+
346+
return is_guest_vendor_amd(entry->ebx, entry->ecx, entry->edx) ||
347+
is_guest_vendor_hygon(entry->ebx, entry->ecx, entry->edx);
348+
}
349+
338350
static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
339351
{
340352
struct kvm_lapic *apic = vcpu->arch.apic;

arch/x86/kvm/cpuid.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ static __always_inline void guest_cpuid_clear(struct kvm_vcpu *vcpu,
102102
*reg &= ~__feature_bit(x86_feature);
103103
}
104104

105-
static inline bool guest_cpuid_is_amd_or_hygon(struct kvm_vcpu *vcpu)
106-
{
107-
struct kvm_cpuid_entry2 *best;
108-
109-
best = kvm_find_cpuid_entry(vcpu, 0);
110-
return best &&
111-
(is_guest_vendor_amd(best->ebx, best->ecx, best->edx) ||
112-
is_guest_vendor_hygon(best->ebx, best->ecx, best->edx));
113-
}
114-
115105
static inline bool guest_cpuid_is_amd_compatible(struct kvm_vcpu *vcpu)
116106
{
117107
return vcpu->arch.is_amd_compatible;

0 commit comments

Comments
 (0)