[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 13/22] i386: split hyperv_handle_properties() into hyperv_exp
From: |
Vitaly Kuznetsov |
Subject: |
[PATCH RFC 13/22] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids() |
Date: |
Fri, 4 Sep 2020 16:54:22 +0200 |
The intention is to call hyperv_expand_features() early, before vCPUs
are created and use the acquired data later when we set guest visible
CPUID data.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
target/i386/kvm.c | 45 +++++++++++++++++++++++++++++----------------
1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index b7f0e200a75f..c4bb147090a9 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1177,18 +1177,18 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct
kvm_cpuid2 *cpuid,
}
/*
- * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_ent in
- * case of success, errno < 0 in case of failure and 0 when no Hyper-V
- * extentions are enabled.
+ * Expand Hyper-V CPU features. In partucular, check that all the requested
+ * features are supported by the host and the sanity of the configuration
+ * (that all the required dependencies are included). Also, this takes care
+ * of 'hv_passthrough' mode and fills the environment with all supported
+ * Hyper-V features.
*/
-static int hyperv_handle_properties(CPUState *cs,
- struct kvm_cpuid_entry2 *cpuid_ent)
+static int hyperv_expand_features(CPUState *cs)
{
X86CPU *cpu = X86_CPU(cs);
CPUX86State *env = &cpu->env;
struct kvm_cpuid2 *cpuid;
struct kvm_cpuid_entry2 *c;
- uint32_t cpuid_i = 0;
int r;
if (!hyperv_enabled(cpu))
@@ -1317,11 +1317,26 @@ static int hyperv_handle_properties(CPUState *cs,
/* Not exposed by KVM but needed to make CPU hotplug in Windows work */
env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
+ g_free(cpuid);
+
if (r) {
- r = -ENOSYS;
- goto free;
+ return -ENOSYS;
}
+ return 0;
+}
+
+/*
+ * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_ent.
+ */
+static int hyperv_fill_cpuids(CPUState *cs,
+ struct kvm_cpuid_entry2 *cpuid_ent)
+{
+ X86CPU *cpu = X86_CPU(cs);
+ CPUX86State *env = &cpu->env;
+ struct kvm_cpuid_entry2 *c;
+ uint32_t cpuid_i = 0;
+
c = &cpuid_ent[cpuid_i++];
c->function = HV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
c->eax = hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ?
@@ -1382,12 +1397,8 @@ static int hyperv_handle_properties(CPUState *cs,
c->ecx = env->features[FEAT_HV_NESTED_ECX];
c->edx = env->features[FEAT_HV_NESTED_EDX];
}
- r = cpuid_i;
-free:
- g_free(cpuid);
-
- return r;
+ return cpuid_i;
}
static Error *hv_passthrough_mig_blocker;
@@ -1529,11 +1540,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
env->apic_bus_freq = KVM_APIC_BUS_FREQUENCY;
/* Paravirtualization CPUIDs */
- r = hyperv_handle_properties(cs, cpuid_data.entries);
+ r = hyperv_expand_features(cs);
if (r < 0) {
return r;
- } else if (r > 0) {
- cpuid_i = r;
+ }
+
+ if (hyperv_enabled(cpu)) {
+ cpuid_i = hyperv_fill_cpuids(cs, cpuid_data.entries);
kvm_base = KVM_CPUID_SIGNATURE_NEXT;
has_msr_hv_hypercall = true;
}
--
2.25.4
- Re: [PATCH RFC 07/22] i386: fill in FEAT_HYPERV_EDX from edx instead of eax, (continued)
- [PATCH RFC 11/22] i386: add reserved FEAT_HV_NESTED_EBX/ECX/EDX CPUID leaves, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 08/22] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 02/22] i386: drop x86_cpu_get_supported_feature_word() forward declaration, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 10/22] i386: add reserved FEAT_HV_RECOMM_ECX/FEAT_HV_RECOMM_EDX CPUID leaves, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 05/22] i386: move hyperv_version_id initialization to x86_cpu_realizefn(), Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 09/22] i386: add reserved FEAT_HYPERV_ECX CPUID leaf, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 13/22] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids(),
Vitaly Kuznetsov <=
- [PATCH RFC 12/22] i386: always fill Hyper-V CPUID feature leaves from X86CPU data, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 15/22] i386: switch hyperv_expand_features() to using error_setg(), Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 18/22] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 22/22] i386: expand Hyper-V features early, Vitaly Kuznetsov, 2020/09/04