aboutsummaryrefslogtreecommitdiff
path: root/target/i386/kvm/kvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'target/i386/kvm/kvm.c')
-rw-r--r--target/i386/kvm/kvm.c62
1 files changed, 49 insertions, 13 deletions
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 7f1b060e6d..f25837f63f 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -821,9 +821,7 @@ static struct {
.desc = "virtual APIC (hv-vapic)",
.flags = {
{.func = HV_CPUID_FEATURES, .reg = R_EAX,
- .bits = HV_APIC_ACCESS_AVAILABLE},
- {.func = HV_CPUID_ENLIGHTMENT_INFO, .reg = R_EAX,
- .bits = HV_APIC_ACCESS_RECOMMENDED}
+ .bits = HV_APIC_ACCESS_AVAILABLE}
}
},
[HYPERV_FEAT_TIME] = {
@@ -926,6 +924,13 @@ static struct {
},
.dependencies = BIT(HYPERV_FEAT_STIMER)
},
+ [HYPERV_FEAT_AVIC] = {
+ .desc = "AVIC/APICv support (hv-avic/hv-apicv)",
+ .flags = {
+ {.func = HV_CPUID_ENLIGHTMENT_INFO, .reg = R_EAX,
+ .bits = HV_DEPRECATING_AEOI_RECOMMENDED}
+ }
+ },
};
static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max,
@@ -1253,14 +1258,18 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp)
cpu->hyperv_interface_id[3] =
hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EDX);
- cpu->hyperv_version_id[0] =
+ cpu->hyperv_ver_id_build =
hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EAX);
- cpu->hyperv_version_id[1] =
- hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EBX);
- cpu->hyperv_version_id[2] =
+ cpu->hyperv_ver_id_major =
+ hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EBX) >> 16;
+ cpu->hyperv_ver_id_minor =
+ hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EBX) & 0xffff;
+ cpu->hyperv_ver_id_sp =
hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_ECX);
- cpu->hyperv_version_id[3] =
- hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX);
+ cpu->hyperv_ver_id_sb =
+ hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX) >> 24;
+ cpu->hyperv_ver_id_sn =
+ hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX) & 0xffffff;
cpu->hv_max_vps = hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS,
R_EAX);
@@ -1346,10 +1355,12 @@ static int hyperv_fill_cpuids(CPUState *cs,
c = &cpuid_ent[cpuid_i++];
c->function = HV_CPUID_VERSION;
- c->eax = cpu->hyperv_version_id[0];
- c->ebx = cpu->hyperv_version_id[1];
- c->ecx = cpu->hyperv_version_id[2];
- c->edx = cpu->hyperv_version_id[3];
+ c->eax = cpu->hyperv_ver_id_build;
+ c->ebx = (uint32_t)cpu->hyperv_ver_id_major << 16 |
+ cpu->hyperv_ver_id_minor;
+ c->ecx = cpu->hyperv_ver_id_sp;
+ c->edx = (uint32_t)cpu->hyperv_ver_id_sb << 24 |
+ (cpu->hyperv_ver_id_sn & 0xffffff);
c = &cpuid_ent[cpuid_i++];
c->function = HV_CPUID_FEATURES;
@@ -1366,6 +1377,7 @@ static int hyperv_fill_cpuids(CPUState *cs,
c->ebx |= HV_POST_MESSAGES | HV_SIGNAL_EVENTS;
}
+
/* Not exposed by KVM but needed to make CPU hotplug in Windows work */
c->edx |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
@@ -1374,6 +1386,11 @@ static int hyperv_fill_cpuids(CPUState *cs,
c->eax = hv_build_cpuid_leaf(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX);
c->ebx = cpu->hyperv_spinlock_attempts;
+ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VAPIC) &&
+ !hyperv_feat_enabled(cpu, HYPERV_FEAT_AVIC)) {
+ c->eax |= HV_APIC_ACCESS_RECOMMENDED;
+ }
+
if (cpu->hyperv_no_nonarch_cs == ON_OFF_AUTO_ON) {
c->eax |= HV_NO_NONARCH_CORESHARING;
} else if (cpu->hyperv_no_nonarch_cs == ON_OFF_AUTO_AUTO) {
@@ -1531,6 +1548,15 @@ static int hyperv_init_vcpu(X86CPU *cpu)
cpu->hyperv_nested[0] = evmcs_version;
}
+ if (cpu->hyperv_enforce_cpuid) {
+ ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENFORCE_CPUID, 0, 1);
+ if (ret < 0) {
+ error_report("failed to enable KVM_CAP_HYPERV_ENFORCE_CPUID: %s",
+ strerror(-ret));
+ return ret;
+ }
+ }
+
return 0;
}
@@ -1629,6 +1655,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused);
+ if (cpu->kvm_pv_enforce_cpuid) {
+ r = kvm_vcpu_enable_cap(cs, KVM_CAP_ENFORCE_PV_FEATURE_CPUID, 0, 1);
+ if (r < 0) {
+ fprintf(stderr,
+ "failed to enable KVM_CAP_ENFORCE_PV_FEATURE_CPUID: %s",
+ strerror(-r));
+ abort();
+ }
+ }
+
for (i = 0; i <= limit; i++) {
if (cpuid_i == KVM_MAX_CPUID_ENTRIES) {
fprintf(stderr, "unsupported level value: 0x%x\n", limit);