KVM: x86/cpuid: generalize kvm_update_kvm_cpuid_base() and also capture limit
A subsequent patch will need to acquire the CPUID leaf range for emulated Xen so explicitly pass the signature of the hypervisor we're interested in to the new function. Also introduce a new kvm_hypervisor_cpuid structure so we can neatly store both the base and limit leaf indices. Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://lore.kernel.org/r/20230106103600.528-2-pdurrant@amazon.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
ee661d8ea9
commit
48639df8a9
|
@ -678,6 +678,11 @@ struct kvm_vcpu_hv {
|
||||||
} nested;
|
} nested;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct kvm_hypervisor_cpuid {
|
||||||
|
u32 base;
|
||||||
|
u32 limit;
|
||||||
|
};
|
||||||
|
|
||||||
/* Xen HVM per vcpu emulation context */
|
/* Xen HVM per vcpu emulation context */
|
||||||
struct kvm_vcpu_xen {
|
struct kvm_vcpu_xen {
|
||||||
u64 hypercall_rip;
|
u64 hypercall_rip;
|
||||||
|
@ -826,7 +831,7 @@ struct kvm_vcpu_arch {
|
||||||
|
|
||||||
int cpuid_nent;
|
int cpuid_nent;
|
||||||
struct kvm_cpuid_entry2 *cpuid_entries;
|
struct kvm_cpuid_entry2 *cpuid_entries;
|
||||||
u32 kvm_cpuid_base;
|
struct kvm_hypervisor_cpuid kvm_cpuid;
|
||||||
|
|
||||||
u64 reserved_gpa_bits;
|
u64 reserved_gpa_bits;
|
||||||
int maxphyaddr;
|
int maxphyaddr;
|
||||||
|
|
|
@ -181,15 +181,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *vcpu)
|
static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu,
|
||||||
|
const char *sig)
|
||||||
{
|
{
|
||||||
u32 function;
|
struct kvm_hypervisor_cpuid cpuid = {};
|
||||||
struct kvm_cpuid_entry2 *entry;
|
struct kvm_cpuid_entry2 *entry;
|
||||||
|
u32 base;
|
||||||
|
|
||||||
vcpu->arch.kvm_cpuid_base = 0;
|
for_each_possible_hypervisor_cpuid_base(base) {
|
||||||
|
entry = kvm_find_cpuid_entry(vcpu, base);
|
||||||
for_each_possible_hypervisor_cpuid_base(function) {
|
|
||||||
entry = kvm_find_cpuid_entry(vcpu, function);
|
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
u32 signature[3];
|
u32 signature[3];
|
||||||
|
@ -198,19 +198,21 @@ static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *vcpu)
|
||||||
signature[1] = entry->ecx;
|
signature[1] = entry->ecx;
|
||||||
signature[2] = entry->edx;
|
signature[2] = entry->edx;
|
||||||
|
|
||||||
BUILD_BUG_ON(sizeof(signature) > sizeof(KVM_SIGNATURE));
|
if (!memcmp(signature, sig, sizeof(signature))) {
|
||||||
if (!memcmp(signature, KVM_SIGNATURE, sizeof(signature))) {
|
cpuid.base = base;
|
||||||
vcpu->arch.kvm_cpuid_base = function;
|
cpuid.limit = entry->eax;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cpuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
u32 base = vcpu->arch.kvm_cpuid_base;
|
u32 base = vcpu->arch.kvm_cpuid.base;
|
||||||
|
|
||||||
if (!base)
|
if (!base)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -440,7 +442,7 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
|
||||||
vcpu->arch.cpuid_entries = e2;
|
vcpu->arch.cpuid_entries = e2;
|
||||||
vcpu->arch.cpuid_nent = nent;
|
vcpu->arch.cpuid_nent = nent;
|
||||||
|
|
||||||
kvm_update_kvm_cpuid_base(vcpu);
|
vcpu->arch.kvm_cpuid = kvm_get_hypervisor_cpuid(vcpu, KVM_SIGNATURE);
|
||||||
kvm_vcpu_after_set_cpuid(vcpu);
|
kvm_vcpu_after_set_cpuid(vcpu);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue