KVM: x86: Introduce __kvm_get_hypervisor_cpuid() helper

commit 7ceb1c694fd9b8a049eb3b2853455caa7d98cb83 upstream.

Similar to kvm_find_kvm_cpuid_features()/__kvm_find_kvm_cpuid_features(),
introduce a helper to search for the specific hypervisor signature in any
struct kvm_cpuid_entry2 array, not only in vcpu->arch.cpuid_entries.

No functional change intended.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20240228101837.93642-2-vkuznets@redhat.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Like Xu <likexu@tencent.com>
This commit is contained in:
Vitaly Kuznetsov 2024-02-28 11:18:35 +01:00 committed by Like Xu
parent 4366f32772
commit 52f0e467d0
1 changed files with 10 additions and 3 deletions

View File

@ -189,15 +189,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
return 0; return 0;
} }
static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu, static struct kvm_hypervisor_cpuid __kvm_get_hypervisor_cpuid(struct kvm_cpuid_entry2 *entries,
const char *sig) int nent, const char *sig)
{ {
struct kvm_hypervisor_cpuid cpuid = {}; struct kvm_hypervisor_cpuid cpuid = {};
struct kvm_cpuid_entry2 *entry; struct kvm_cpuid_entry2 *entry;
u32 base; u32 base;
for_each_possible_hypervisor_cpuid_base(base) { for_each_possible_hypervisor_cpuid_base(base) {
entry = kvm_find_cpuid_entry(vcpu, base); entry = cpuid_entry2_find(entries, nent, base, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
if (entry) { if (entry) {
u32 signature[3]; u32 signature[3];
@ -217,6 +217,13 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcp
return cpuid; return cpuid;
} }
static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu,
const char *sig)
{
return __kvm_get_hypervisor_cpuid(vcpu->arch.cpuid_entries,
vcpu->arch.cpuid_nent, sig);
}
static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_vcpu *vcpu, static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_vcpu *vcpu,
struct kvm_cpuid_entry2 *entries, int nent) struct kvm_cpuid_entry2 *entries, int nent)
{ {