From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869728747240.49925883477738; Fri, 29 Mar 2019 07:28:48 -0700 (PDT) Received: from localhost ([127.0.0.1]:54479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sUs-0006u8-FW for importer@patchew.org; Fri, 29 Mar 2019 10:28:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sRr-0004oH-EO for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:25:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sRo-0006c9-Vs for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:25:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48074) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sRo-0006b4-HG for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:25:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 65B38C00732E; Fri, 29 Mar 2019 14:18:39 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 475AE1001DD6; Fri, 29 Mar 2019 14:18:37 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:25 +0100 Message-Id: <20190329141832.22882-2-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 29 Mar 2019 14:18:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/8] i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" KVM now supports reporting supported Hyper-V features through CPUID (KVM_GET_SUPPORTED_HV_CPUID ioctl). Going forward, this is going to be the only way to announce new functionality and this has already happened with Direct Mode stimers. While we could just support KVM_GET_SUPPORTED_HV_CPUID for new features, it seems to be beneficial to use it for all Hyper-V enlightenments when possible. This way we can implement 'hv-all' pass-through mode giving the guest all supported Hyper-V features even when QEMU knows nothing about them. Implementation-wise we create a new kvm_hyperv_properties structure defining Hyper-V features, get_supported_hv_cpuid()/ get_supported_hv_cpuid_legacy() returning the supported CPUID set and a bit over-engineered hv_cpuid_check_and_set() which we will also be used to set cpu->hyperv_* properties for 'hv-all' mode. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 487 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 372 insertions(+), 115 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 3b29ce5c0d..9abee81998 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -700,141 +700,360 @@ static bool tsc_is_stable_and_known(CPUX86State *en= v) || env->user_tsc_khz; } =20 -static int hyperv_handle_properties(CPUState *cs) +static struct { + const char *name; + const char *desc; + struct { + uint32_t fw; + uint32_t bits; + } flags[2]; +} kvm_hyperv_properties[] =3D { + { + .name =3D "hv-relaxed", + .desc =3D "relaxed timing", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_HYPERCALL_AVAILABLE}, + {.fw =3D FEAT_HV_RECOMM_EAX, + .bits =3D HV_RELAXED_TIMING_RECOMMENDED} + } + }, + { + .name =3D "hv-vapic", + .desc =3D "virtual APIC", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_HYPERCALL_AVAILABLE | HV_APIC_ACCESS_AVAILABLE}, + {.fw =3D FEAT_HV_RECOMM_EAX, + .bits =3D HV_APIC_ACCESS_RECOMMENDED} + } + }, + { + .name =3D "hv-time", + .desc =3D "clocksources", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_HYPERCALL_AVAILABLE | HV_TIME_REF_COUNT_AVAILABL= E | + HV_REFERENCE_TSC_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-frequencies", + .desc =3D "frequency MSRs", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_ACCESS_FREQUENCY_MSRS}, + {.fw =3D FEAT_HYPERV_EDX, + .bits =3D HV_FREQUENCY_MSRS_AVAILABLE} + } + }, + { + .name =3D "hv-crash", + .desc =3D "crash MSRs", + .flags =3D { + {.fw =3D FEAT_HYPERV_EDX, + .bits =3D HV_GUEST_CRASH_MSR_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-reenlightenment", + .desc =3D "Reenlightenment MSRs", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_ACCESS_REENLIGHTENMENTS_CONTROL}, + {0} + } + }, + { + .name =3D "hv-reset", + .desc =3D "reset MSR", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_RESET_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-vpindex", + .desc =3D "VP_INDEX MSR", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_VP_INDEX_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-runtime", + .desc =3D "VP_RUNTIME MSR", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_VP_RUNTIME_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-synic", + .desc =3D "SynIC", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_SYNIC_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-stimer", + .desc =3D "timers", + .flags =3D { + {.fw =3D FEAT_HYPERV_EAX, + .bits =3D HV_SYNTIMERS_AVAILABLE}, + {0} + } + }, + { + .name =3D "hv-tlbflush", + .desc =3D "TLB flush support", + .flags =3D { + {.fw =3D FEAT_HV_RECOMM_EAX, + .bits =3D HV_REMOTE_TLB_FLUSH_RECOMMENDED | + HV_EX_PROCESSOR_MASKS_RECOMMENDED}, + {0} + } + }, + { + .name =3D "hv-ipi", + .desc =3D "IPI send support", + .flags =3D { + {.fw =3D FEAT_HV_RECOMM_EAX, + .bits =3D HV_CLUSTER_IPI_RECOMMENDED | + HV_EX_PROCESSOR_MASKS_RECOMMENDED}, + {0} + } + }, +}; + +static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) +{ + struct kvm_cpuid2 *cpuid; + int r, size; + + size =3D sizeof(*cpuid) + max * sizeof(*cpuid->entries); + cpuid =3D g_malloc0(size); + cpuid->nent =3D max; + + r =3D kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + if (r =3D=3D 0 && cpuid->nent >=3D max) { + r =3D -E2BIG; + } + if (r < 0) { + if (r =3D=3D -E2BIG) { + g_free(cpuid); + return NULL; + } else { + fprintf(stderr, "KVM_GET_SUPPORTED_HV_CPUID failed: %s\n", + strerror(-r)); + exit(1); + } + } + return cpuid; +} + +/* + * Run KVM_GET_SUPPORTED_HV_CPUID ioctl(), allocating a buffer large enough + * for all entries. + */ +static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs) +{ + struct kvm_cpuid2 *cpuid; + int max =3D 7; /* 0x40000000..0x40000005, 0x4000000A */ + + while ((cpuid =3D try_get_hv_cpuid(cs, max)) =3D=3D NULL) { + max++; + } + return cpuid; +} + +/* + * When KVM_GET_SUPPORTED_HV_CPUID is not supported we fill CPUID feature + * leaves from KVM_CAP_HYPERV* and present MSRs data. + */ +static struct kvm_cpuid2 *get_supported_hv_cpuid_legacy(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; + struct kvm_cpuid2 *cpuid; + struct kvm_cpuid_entry2 *entry_feat, *entry_recomm; + + /* HV_CPUID_FEATURES, HV_CPUID_ENLIGHTMENT_INFO */ + cpuid =3D g_malloc0(sizeof(*cpuid) + 2 * sizeof(*cpuid->entries)); + cpuid->nent =3D 2; + + /* HV_CPUID_VENDOR_AND_MAX_FUNCTIONS */ + entry_feat =3D &cpuid->entries[0]; + entry_feat->function =3D HV_CPUID_FEATURES; + + entry_recomm =3D &cpuid->entries[1]; + entry_recomm->function =3D HV_CPUID_ENLIGHTMENT_INFO; =20 - if (cpu->hyperv_relaxed_timing) { - env->features[FEAT_HYPERV_EAX] |=3D HV_HYPERCALL_AVAILABLE; + if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0) { + entry_feat->eax |=3D HV_HYPERCALL_AVAILABLE; + entry_feat->eax |=3D HV_APIC_ACCESS_AVAILABLE; + entry_feat->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; + entry_recomm->eax |=3D HV_RELAXED_TIMING_RECOMMENDED; + entry_recomm->eax |=3D HV_APIC_ACCESS_RECOMMENDED; } - if (cpu->hyperv_vapic) { - env->features[FEAT_HYPERV_EAX] |=3D HV_HYPERCALL_AVAILABLE; - env->features[FEAT_HYPERV_EAX] |=3D HV_APIC_ACCESS_AVAILABLE; + + if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) > 0) { + entry_feat->eax |=3D HV_TIME_REF_COUNT_AVAILABLE; + entry_feat->eax |=3D HV_REFERENCE_TSC_AVAILABLE; } - if (cpu->hyperv_time) { - if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) <=3D 0= ) { - fprintf(stderr, "Hyper-V clocksources " - "(requested by 'hv-time' cpu flag) " - "are not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EAX] |=3D HV_HYPERCALL_AVAILABLE; - env->features[FEAT_HYPERV_EAX] |=3D HV_TIME_REF_COUNT_AVAILABLE; - env->features[FEAT_HYPERV_EAX] |=3D HV_REFERENCE_TSC_AVAILABLE; + + if (has_msr_hv_frequencies) { + entry_feat->eax |=3D HV_ACCESS_FREQUENCY_MSRS; + entry_feat->edx |=3D HV_FREQUENCY_MSRS_AVAILABLE; } - if (cpu->hyperv_frequencies) { - if (!has_msr_hv_frequencies) { - fprintf(stderr, "Hyper-V frequency MSRs " - "(requested by 'hv-frequencies' cpu flag) " - "are not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EAX] |=3D HV_ACCESS_FREQUENCY_MSRS; - env->features[FEAT_HYPERV_EDX] |=3D HV_FREQUENCY_MSRS_AVAILABLE; + + if (has_msr_hv_crash) { + entry_feat->edx |=3D HV_GUEST_CRASH_MSR_AVAILABLE; } - if (cpu->hyperv_crash) { - if (!has_msr_hv_crash) { - fprintf(stderr, "Hyper-V crash MSRs " - "(requested by 'hv-crash' cpu flag) " - "are not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EDX] |=3D HV_GUEST_CRASH_MSR_AVAILABLE; + + if (has_msr_hv_reenlightenment) { + entry_feat->eax |=3D HV_ACCESS_REENLIGHTENMENTS_CONTROL; } - if (cpu->hyperv_reenlightenment) { - if (!has_msr_hv_reenlightenment) { - fprintf(stderr, - "Hyper-V Reenlightenment MSRs " - "(requested by 'hv-reenlightenment' cpu flag) " - "are not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EAX] |=3D HV_ACCESS_REENLIGHTENMENTS_CON= TROL; + + if (has_msr_hv_reset) { + entry_feat->eax |=3D HV_RESET_AVAILABLE; } - env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; - if (cpu->hyperv_reset) { - if (!has_msr_hv_reset) { - fprintf(stderr, "Hyper-V reset MSR " - "(requested by 'hv-reset' cpu flag) " - "is not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EAX] |=3D HV_RESET_AVAILABLE; + + if (has_msr_hv_vpindex) { + entry_feat->eax |=3D HV_VP_INDEX_AVAILABLE; } - if (cpu->hyperv_vpindex) { - if (!has_msr_hv_vpindex) { - fprintf(stderr, "Hyper-V VP_INDEX MSR " - "(requested by 'hv-vpindex' cpu flag) " - "is not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EAX] |=3D HV_VP_INDEX_AVAILABLE; + + if (has_msr_hv_runtime) { + entry_feat->eax |=3D HV_VP_RUNTIME_AVAILABLE; } - if (cpu->hyperv_runtime) { - if (!has_msr_hv_runtime) { - fprintf(stderr, "Hyper-V VP_RUNTIME MSR " - "(requested by 'hv-runtime' cpu flag) " - "is not supported by kernel\n"); - return -ENOSYS; + + if (has_msr_hv_synic) { + unsigned int cap =3D cpu->hyperv_synic_kvm_only ? + KVM_CAP_HYPERV_SYNIC : KVM_CAP_HYPERV_SYNIC2; + + if (kvm_check_extension(cs->kvm_state, cap) > 0) { + entry_feat->eax |=3D HV_SYNIC_AVAILABLE; } - env->features[FEAT_HYPERV_EAX] |=3D HV_VP_RUNTIME_AVAILABLE; } - if (cpu->hyperv_synic) { - unsigned int cap =3D KVM_CAP_HYPERV_SYNIC; - if (!cpu->hyperv_synic_kvm_only) { - if (!cpu->hyperv_vpindex) { - fprintf(stderr, "Hyper-V SynIC " - "(requested by 'hv-synic' cpu flag) " - "requires Hyper-V VP_INDEX ('hv-vpindex')\n"); - return -ENOSYS; - } - cap =3D KVM_CAP_HYPERV_SYNIC2; - } =20 - if (!has_msr_hv_synic || !kvm_check_extension(cs->kvm_state, cap))= { - fprintf(stderr, "Hyper-V SynIC (requested by 'hv-synic' cpu fl= ag) " - "is not supported by kernel\n"); - return -ENOSYS; - } + if (has_msr_hv_stimer) { + entry_feat->eax |=3D HV_SYNTIMERS_AVAILABLE; + } =20 - env->features[FEAT_HYPERV_EAX] |=3D HV_SYNIC_AVAILABLE; + if (kvm_check_extension(cs->kvm_state, + KVM_CAP_HYPERV_TLBFLUSH) > 0) { + entry_recomm->eax |=3D HV_REMOTE_TLB_FLUSH_RECOMMENDED; + entry_recomm->eax |=3D HV_EX_PROCESSOR_MASKS_RECOMMENDED; } - if (cpu->hyperv_stimer) { - if (!has_msr_hv_stimer) { - fprintf(stderr, "Hyper-V timers aren't supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HYPERV_EAX] |=3D HV_SYNTIMERS_AVAILABLE; + + if (kvm_check_extension(cs->kvm_state, + KVM_CAP_HYPERV_SEND_IPI) > 0) { + entry_recomm->eax |=3D HV_CLUSTER_IPI_RECOMMENDED; + entry_recomm->eax |=3D HV_EX_PROCESSOR_MASKS_RECOMMENDED; } - if (cpu->hyperv_relaxed_timing) { - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_RELAXED_TIMING_RECOMMEND= ED; + + return cpuid; +} + +static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid, int fw, uint32_t *r) +{ + struct kvm_cpuid_entry2 *entry; + uint32_t func; + int reg; + + switch (fw) { + case FEAT_HYPERV_EAX: + reg =3D R_EAX; + func =3D HV_CPUID_FEATURES; + break; + case FEAT_HYPERV_EDX: + reg =3D R_EDX; + func =3D HV_CPUID_FEATURES; + break; + case FEAT_HV_RECOMM_EAX: + reg =3D R_EAX; + func =3D HV_CPUID_ENLIGHTMENT_INFO; + break; + default: + return -EINVAL; } - if (cpu->hyperv_vapic) { - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_APIC_ACCESS_RECOMMENDED; - } - if (cpu->hyperv_tlbflush) { - if (kvm_check_extension(cs->kvm_state, - KVM_CAP_HYPERV_TLBFLUSH) <=3D 0) { - fprintf(stderr, "Hyper-V TLB flush support " - "(requested by 'hv-tlbflush' cpu flag) " - " is not supported by kernel\n"); - return -ENOSYS; - } - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_REMOTE_TLB_FLUSH_RECOMME= NDED; - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_EX_PROCESSOR_MASKS_RECOM= MENDED; + + entry =3D cpuid_find_entry(cpuid, func, 0); + if (!entry) { + return -ENOENT; } - if (cpu->hyperv_ipi) { - if (kvm_check_extension(cs->kvm_state, - KVM_CAP_HYPERV_SEND_IPI) <=3D 0) { - fprintf(stderr, "Hyper-V IPI send support " - "(requested by 'hv-ipi' cpu flag) " - " is not supported by kernel\n"); - return -ENOSYS; + + switch (reg) { + case R_EAX: + *r =3D entry->eax; + break; + case R_EDX: + *r =3D entry->edx; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, + const char *name, bool flag) +{ + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; + uint32_t r, fw, bits;; + int i, j; + + if (!flag) { + return 0; + } + + for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties); i++) { + if (strcmp(kvm_hyperv_properties[i].name, name)) { + continue; } - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_CLUSTER_IPI_RECOMMENDED; - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_EX_PROCESSOR_MASKS_RECOM= MENDED; + + for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { + fw =3D kvm_hyperv_properties[i].flags[j].fw; + bits =3D kvm_hyperv_properties[i].flags[j].bits; + + if (!fw) { + continue; + } + + if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { + fprintf(stderr, + "Hyper-V %s (requested by '%s' cpu flag) " + "is not supported by kernel\n", + kvm_hyperv_properties[i].desc, + kvm_hyperv_properties[i].name); + return 1; + } + + env->features[fw] |=3D bits; + } + + return 0; } + + /* the requested feature is undefined in kvm_hyperv_properties */ + return 1; +} + +static int hyperv_handle_properties(CPUState *cs) +{ + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; + struct kvm_cpuid2 *cpuid; + int r =3D 0; + if (cpu->hyperv_evmcs) { uint16_t evmcs_version; =20 @@ -849,7 +1068,45 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HV_NESTED_EAX] =3D evmcs_version; } =20 - return 0; + if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_CPUID) > 0) { + cpuid =3D get_supported_hv_cpuid(cs); + } else { + cpuid =3D get_supported_hv_cpuid_legacy(cs); + } + + /* Features */ + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-relaxed", + cpu->hyperv_relaxed_timing); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-vapic", cpu->hyperv_vapic= ); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-time", cpu->hyperv_time); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-frequencies", + cpu->hyperv_frequencies); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-crash", cpu->hyperv_crash= ); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-reenlightenment", + cpu->hyperv_reenlightenment); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-reset", cpu->hyperv_reset= ); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-vpindex", cpu->hyperv_vpi= ndex); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-runtime", cpu->hyperv_run= time); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-synic", cpu->hyperv_synic= ); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-stimer", cpu->hyperv_stim= er); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush", cpu->hyperv_tl= bflush); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", cpu->hyperv_ipi); + + /* Dependencies */ + if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only && + !cpu->hyperv_vpindex) { + fprintf(stderr, "Hyper-V SynIC " + "(requested by 'hv-synic' cpu flag) " + "requires Hyper-V VP_INDEX ('hv-vpindex')\n"); + r |=3D 1; + } + + /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ + env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; + + g_free(cpuid); + + return r ? -ENOSYS : 0; } =20 static int hyperv_init_vcpu(X86CPU *cpu) --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869997425123.97564276390585; Fri, 29 Mar 2019 07:33:17 -0700 (PDT) Received: from localhost ([127.0.0.1]:54543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sZ9-0002aS-QC for importer@patchew.org; Fri, 29 Mar 2019 10:33:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sTZ-0006IU-7p for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:27:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sTY-0007ox-0b for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:27:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sTX-0007oc-MH for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:27:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 77CD83087BA8; Fri, 29 Mar 2019 14:18:41 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA0CA1001E91; Fri, 29 Mar 2019 14:18:39 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:26 +0100 Message-Id: <20190329141832.22882-3-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 29 Mar 2019 14:18:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/8] i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Let's consolidate Hyper-V features handling in hyperv_handle_properties(). The change is necessary to support pass-through 'hv-all' mode as we'll be just copying CPUIDs from KVM instead of filling them in. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 163 +++++++++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 73 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 9abee81998..63031358ae 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1047,13 +1047,25 @@ static int hv_cpuid_check_and_set(CPUState *cs, str= uct kvm_cpuid2 *cpuid, return 1; } =20 -static int hyperv_handle_properties(CPUState *cs) +/* + * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt in + * case of success, errno < 0 in case of failure and 0 when no Hyper-V + * extentions are enabled. + */ +static int hyperv_handle_properties(CPUState *cs, + struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; struct kvm_cpuid2 *cpuid; + struct kvm_cpuid_entry2 *c; + uint32_t signature[3]; + uint32_t cpuid_i =3D 0; int r =3D 0; =20 + if (!hyperv_enabled(cpu)) + return 0; + if (cpu->hyperv_evmcs) { uint16_t evmcs_version; =20 @@ -1104,9 +1116,80 @@ 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] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; =20 + if (r) { + r =3D -ENOSYS; + goto free; + } + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; + if (!cpu->hyperv_vendor_id) { + memcpy(signature, "Microsoft Hv", 12); + } else { + size_t len =3D strlen(cpu->hyperv_vendor_id); + + if (len > 12) { + error_report("hv-vendor-id truncated to 12 characters"); + len =3D 12; + } + memset(signature, 0, 12); + memcpy(signature, cpu->hyperv_vendor_id, len); + } + c->eax =3D cpu->hyperv_evmcs ? + HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS; + c->ebx =3D signature[0]; + c->ecx =3D signature[1]; + c->edx =3D signature[2]; + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_INTERFACE; + memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); + c->eax =3D signature[0]; + c->ebx =3D 0; + c->ecx =3D 0; + c->edx =3D 0; + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_VERSION; + c->eax =3D 0x00001bbc; + c->ebx =3D 0x00060001; + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_FEATURES; + c->eax =3D env->features[FEAT_HYPERV_EAX]; + c->ebx =3D env->features[FEAT_HYPERV_EBX]; + c->edx =3D env->features[FEAT_HYPERV_EDX]; + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_ENLIGHTMENT_INFO; + c->eax =3D env->features[FEAT_HV_RECOMM_EAX]; + c->ebx =3D cpu->hyperv_spinlock_attempts; + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_IMPLEMENT_LIMITS; + c->eax =3D cpu->hv_max_vps; + c->ebx =3D 0x40; + + if (cpu->hyperv_evmcs) { + __u32 function; + + /* Create zeroed 0x40000006..0x40000009 leaves */ + for (function =3D HV_CPUID_IMPLEMENT_LIMITS + 1; + function < HV_CPUID_NESTED_FEATURES; function++) { + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D function; + } + + c =3D &cpuid_ent[cpuid_i++]; + c->function =3D HV_CPUID_NESTED_FEATURES; + c->eax =3D env->features[FEAT_HV_NESTED_EAX]; + } + r =3D cpuid_i; + +free: g_free(cpuid); =20 - return r ? -ENOSYS : 0; + return r; } =20 static int hyperv_init_vcpu(X86CPU *cpu) @@ -1215,79 +1298,13 @@ int kvm_arch_init_vcpu(CPUState *cs) } =20 /* Paravirtualization CPUIDs */ - if (hyperv_enabled(cpu)) { - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; - if (!cpu->hyperv_vendor_id) { - memcpy(signature, "Microsoft Hv", 12); - } else { - size_t len =3D strlen(cpu->hyperv_vendor_id); - - if (len > 12) { - error_report("hv-vendor-id truncated to 12 characters"); - len =3D 12; - } - memset(signature, 0, 12); - memcpy(signature, cpu->hyperv_vendor_id, len); - } - c->eax =3D cpu->hyperv_evmcs ? - HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS; - c->ebx =3D signature[0]; - c->ecx =3D signature[1]; - c->edx =3D signature[2]; - - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_INTERFACE; - memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); - c->eax =3D signature[0]; - c->ebx =3D 0; - c->ecx =3D 0; - c->edx =3D 0; - - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_VERSION; - c->eax =3D 0x00001bbc; - c->ebx =3D 0x00060001; - - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_FEATURES; - r =3D hyperv_handle_properties(cs); - if (r) { - return r; - } - c->eax =3D env->features[FEAT_HYPERV_EAX]; - c->ebx =3D env->features[FEAT_HYPERV_EBX]; - c->edx =3D env->features[FEAT_HYPERV_EDX]; - - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_ENLIGHTMENT_INFO; - - c->eax =3D env->features[FEAT_HV_RECOMM_EAX]; - c->ebx =3D cpu->hyperv_spinlock_attempts; - - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_IMPLEMENT_LIMITS; - - c->eax =3D cpu->hv_max_vps; - c->ebx =3D 0x40; - + r =3D hyperv_handle_properties(cs, cpuid_data.entries); + if (r < 0) { + return r; + } else if (r > 0) { + cpuid_i =3D r; kvm_base =3D KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall =3D true; - - if (cpu->hyperv_evmcs) { - __u32 function; - - /* Create zeroed 0x40000006..0x40000009 leaves */ - for (function =3D HV_CPUID_IMPLEMENT_LIMITS + 1; - function < HV_CPUID_NESTED_FEATURES; function++) { - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D function; - } - - c =3D &cpuid_data.entries[cpuid_i++]; - c->function =3D HV_CPUID_NESTED_FEATURES; - c->eax =3D env->features[FEAT_HV_NESTED_EAX]; - } } =20 if (cpu->expose_kvm) { --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869750656889.9002812815202; Fri, 29 Mar 2019 07:29:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:54481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sVH-0007Gg-Hs for importer@patchew.org; Fri, 29 Mar 2019 10:29:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sTZ-0006Iw-Mq for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:27:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sTY-0007os-0M for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:27:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sTX-0007oe-Mx for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:27:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 871C03087BA1; Fri, 29 Mar 2019 14:18:43 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDDD81001DD6; Fri, 29 Mar 2019 14:18:41 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:27 +0100 Message-Id: <20190329141832.22882-4-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 29 Mar 2019 14:18:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/8] i386/kvm: document existing Hyper-V enlightenments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, there is no doc describing hv-* CPU flags, people are encouraged to get the information from Microsoft Hyper-V Top Level Functional specification (TLFS). There is, however, a bit of QEMU specifics. Signed-off-by: Vitaly Kuznetsov --- docs/hyperv.txt | 180 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 docs/hyperv.txt diff --git a/docs/hyperv.txt b/docs/hyperv.txt new file mode 100644 index 0000000000..397f2517b8 --- /dev/null +++ b/docs/hyperv.txt @@ -0,0 +1,180 @@ +Hyper-V Enlightenments +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + + +1. Description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +In some cases when implementing a hardware interface in software is slow, = KVM +implements its own paravirtualized interfaces. This works well for Linux as +guest support for such features is added simultaneously with the feature i= tself. +It may, however, be hard-to-impossible to add support for these interfaces= to +proprietary OSes, namely, Microsoft Windows. + +KVM on x86 implements Hyper-V Enlightenments for Windows guests. These fea= tures +make Windows and Hyper-V guests think they're running on top of a Hyper-V +compatible hypervisor and use Hyper-V specific features. + + +2. Setup +=3D=3D=3D=3D=3D=3D=3D=3D=3D +No Hyper-V enlightenments are enabled by default by either KVM or QEMU. In +QEMU, individual enlightenments can be enabled through CPU flags, e.g: + + qemu-system-x86_64 --enable-kvm --cpu host,hv_relaxed,hv_vpindex,hv_time= , ... + +Sometimes there are dependencies between enlightenments, QEMU is supposed = to +check that the supplied configuration is sane. + +When any set of the Hyper-V enlightenments is enabled, QEMU changes hyperv= isor +identification (CPUID 0x40000000..0x4000000A) to Hyper-V. KVM identificati= on +and features are kept in leaves 0x40000100..0x40000101. + + +3. Existing enlightenments +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +3.1. hv-relaxed +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +This feature tells guest OS to disable watchdog timeouts as it is running = on a +hypervisor. It is known that some Windows versions will do this even when = they +see 'hypervisor' CPU flag. + +3.2. hv-vapic +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Provides so-called VP Assist page MSR to guest allowing it to work with AP= IC +more efficiently. In particular, this enlightenment allows paravirtualized +(exit-less) EOI processing. + +3.3. hv-spinlocks=3Dxxx +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enables paravirtualized spinlocks. The parameter indicates how many times +spinlock acquisition should be attempted before indicating the situation t= o the +hypervisor. A special value 0xffffffff indicates "never to retry". + +3.4. hv-vpindex +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Provides HV_X64_MSR_VP_INDEX (0x40000002) MSR to the guest which has Virtu= al +processor index information. This enlightenment makes sense in conjunction= with +hv-synic, hv-stimer and other enlightenments which require the guest to kn= ow its +Virtual Processor indices (e.g. when VP index needs to be passed in a +hypercall). + +3.5. hv-runtime +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Provides HV_X64_MSR_VP_RUNTIME (0x40000010) MSR to the guest. The MSR keep= s the +virtual processor run time in 100ns units. This gives guest operating syst= em an +idea of how much time was 'stolen' from it (when the virtual CPU was preem= pted +to perform some other work). + +3.6. hv-crash +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Provides HV_X64_MSR_CRASH_P0..HV_X64_MSR_CRASH_P5 (0x40000100..0x40000105)= and +HV_X64_MSR_CRASH_CTL (0x40000105) MSRs to the guest. These MSRs are writte= n to +by the guest when it crashes, HV_X64_MSR_CRASH_P0..HV_X64_MSR_CRASH_P5 MSRs +contain additional crash information. This information is outputted in QEM= U log +and through QAPI. +Note: unlike under genuine Hyper-V, write to HV_X64_MSR_CRASH_CTL causes g= uest +to shutdown. This effectively blocks crash dump generation by Windows. + +3.7. hv-time +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enables two Hyper-V-specific clocksources available to the guest: MSR-based +Hyper-V clocksource (HV_X64_MSR_TIME_REF_COUNT, 0x40000020) and Reference = TSC +page (enabled via MSR HV_X64_MSR_REFERENCE_TSC, 0x40000021). Both clocksou= rces +are per-guest, Reference TSC page clocksource allows for exit-less time st= amp +readings. Using this enlightenment leads to significant speedup of all tim= estamp +related operations. + +3.8. hv-synic +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enables Hyper-V Synthetic interrupt controller - an extension of a local A= PIC. +When enabled, this enlightenment provides additional communication facilit= ies +to the guest: SynIC messages and Events. This is a pre-requisite for +implementing VMBus devices (not yet in QEMU). Additionally, this enlighten= ment +is needed to enable Hyper-V synthetic timers. SynIC is controlled through = MSRs +HV_X64_MSR_SCONTROL..HV_X64_MSR_EOM (0x40000080..0x40000084) and +HV_X64_MSR_SINT0..HV_X64_MSR_SINT15 (0x40000090..0x4000009F) + +Requires: hv-vpindex + +3.9. hv-stimer +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enables Hyper-V synthetic timers. There are four synthetic timers per virt= ual +CPU controlled through HV_X64_MSR_STIMER0_CONFIG..HV_X64_MSR_STIMER3_COUNT +(0x400000B0..0x400000B7) MSRs. These timers can work either in single-shot= or +periodic mode. It is known that certain Windows versions revert to using R= TC +extensively when this enlightenment is not provided; this leads to signifi= cant +CPU consumption, even when virtual CPU is idle. + +Requires: hv-vpindex, hv-synic, hv-time + +3.10. hv-tlbflush +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enables paravirtualized TLB shoot-down mechanism. On x86 architecture, rem= ote +TLB flush procedure requires sending IPIs and waiting for other CPUs to pe= rform +local TLB flush. In virtualized environment some virtual CPUs may not even= be +scheduled at the time of the call and may not require flushing (or, flushi= ng +may be postponed until the virtual CPU is scheduled). hv-tlbflush enlighte= nment +implements TLB shoot-down through hypervisor enabling the optimization. + +Requires: hv-vpindex + +3.11. hv-ipi +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Enables paravirtualized IPI send mechanism. HvCallSendSyntheticClusterIpi +hypercall may target more than 64 virtual CPUs simultaneously, doing the s= ame +through APIC requires more than one access (and thus exit to the hyperviso= r). + +Requires: hv-vpindex + +3.12. hv-vendor-id=3Dxxx +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +This changes Hyper-V identification in CPUID 0x40000000.EBX-EDX from the d= efault +"Microsoft Hv". The parameter should be no longer than 12 characters. Acco= rding +to the specification, guests shouldn't use this information and it is unkn= own +if there is a Windows version which acts differently. +Note: hv-vendor-id is not an enlightenment and thus doesn't enable Hyper-V +identification when specified without some other enlightenment. + +3.13. hv-reset +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Provides HV_X64_MSR_RESET (0x40000003) MSR to the guest allowing it to res= et +itself by writing to it. Even when this MSR is enabled, it is not a recomm= ended +way for Windows to perform system reboot and thus it may not be used. + +3.14. hv-frequencies +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Provides HV_X64_MSR_TSC_FREQUENCY (0x40000022) and HV_X64_MSR_APIC_FREQUEN= CY +(0x40000023) allowing the guest to get its TSC/APIC frequencies without do= ing +measurements. + +3.15 hv-reenlightenment +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +The enlightenment is nested specific, it targets Hyper-V on KVM guests. Wh= en +enabled, it provides HV_X64_MSR_REENLIGHTENMENT_CONTROL (0x40000106), +HV_X64_MSR_TSC_EMULATION_CONTROL (0x40000107)and HV_X64_MSR_TSC_EMULATION_= STATUS +(0x40000108) MSRs allowing the guest to get notified when TSC frequency ch= anges +(only happens on migration) and keep using old frequency (through emulatio= n in +the hypervisor) until it is ready to switch to the new one. This, in conju= nction +with hv-frequencies, allows Hyper-V on KVM to pass stable clocksource (Ref= erence +TSC page) to its own guests. + +Recommended: hv-frequencies + +3.16. hv-evmcs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +The enlightenment is nested specific, it targets Hyper-V on KVM guests. Wh= en +enabled, it provides Enlightened VMCS feature to the guest. The feature +implements paravirtualized protocol between L0 (KVM) and L1 (Hyper-V) +hypervisors making L2 exits to the hypervisor faster. The feature is Intel= -only. +Note: some virtualization features (e.g. Posted Interrupts) are disabled w= hen +hv-evmcs is enabled. It may make sense to measure your nested workload wit= h and +without the feature to find out if enabling it is beneficial. + +Requires: hv-vapic + + +4. Useful links +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Hyper-V Top Level Functional specification and other information: +https://github.com/MicrosoftDocs/Virtualization-Documentation --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869772152489.9070404243515; Fri, 29 Mar 2019 07:29:32 -0700 (PDT) Received: from localhost ([127.0.0.1]:54483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sVd-0007bP-0L for importer@patchew.org; Fri, 29 Mar 2019 10:29:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sSY-0005Ja-Qi for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:26:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sSX-0007Hq-3y for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:26:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50126) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sSW-0007Ee-O6 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:26:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CAA2330241; Fri, 29 Mar 2019 14:18:45 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF0F21001E91; Fri, 29 Mar 2019 14:18:43 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:28 +0100 Message-Id: <20190329141832.22882-5-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 29 Mar 2019 14:18:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/8] i386/kvm: implement 'hv-all' pass-through mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID. hv_cpuid_check_and_set() is modified to also set cpu->hyperv_* flags as we may want to check them later (and we actually do for hv_runtime, hv_synic,...). 'hv-all' is a development only feature, a migration blocker is added to prevent issues while migrating between hosts with different feature sets. Signed-off-by: Vitaly Kuznetsov --- docs/hyperv.txt | 10 ++++ target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/kvm.c | 148 +++++++++++++++++++++++++++++++++++++--------- 4 files changed, 132 insertions(+), 28 deletions(-) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index 397f2517b8..d1299aba81 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -174,6 +174,16 @@ without the feature to find out if enabling it is bene= ficial. Requires: hv-vapic =20 =20 +4. Development features +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +In some cases (e.g. during development) it may make sense to use QEMU in +'pass-through' mode and give Windows guests all enlightenments currently +supported by KVM. This pass-through mode is enabled by "hv-all" CPU flag. +Note: enabling this flag effectively prevents migration as supported featu= res +may differ between target and destination. +Note: "hv-all" doesn't include 'hv-evmcs', it needs to be enabled explicit= ly. + + 4. Useful links =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Hyper-V Top Level Functional specification and other information: diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d6bb57d210..4e01ad076e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5785,6 +5785,7 @@ static Property x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false), DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false), DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false), + DEFINE_PROP_BOOL("hv-all", X86CPU, hyperv_all, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 83fb522554..9cd3a8bc2f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1396,6 +1396,7 @@ struct X86CPU { bool hyperv_tlbflush; bool hyperv_evmcs; bool hyperv_ipi; + bool hyperv_all; bool check_cpuid; bool enforce_cpuid; bool expose_kvm; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 63031358ae..af45241adb 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -656,7 +656,8 @@ static bool hyperv_enabled(X86CPU *cpu) cpu->hyperv_stimer || cpu->hyperv_reenlightenment || cpu->hyperv_tlbflush || - cpu->hyperv_ipi); + cpu->hyperv_ipi || + cpu->hyperv_all); } =20 static int kvm_arch_set_tsc_khz(CPUState *cs) @@ -1004,14 +1005,15 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid= , int fw, uint32_t *r) } =20 static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, - const char *name, bool flag) + const char *name, bool *flag) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; uint32_t r, fw, bits;; int i, j; + bool present; =20 - if (!flag) { + if (!*flag && !cpu->hyperv_all) { return 0; } =20 @@ -1020,6 +1022,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, continue; } =20 + present =3D true; for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { fw =3D kvm_hyperv_properties[i].flags[j].fw; bits =3D kvm_hyperv_properties[i].flags[j].bits; @@ -1029,17 +1032,26 @@ static int hv_cpuid_check_and_set(CPUState *cs, str= uct kvm_cpuid2 *cpuid, } =20 if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { - fprintf(stderr, - "Hyper-V %s (requested by '%s' cpu flag) " - "is not supported by kernel\n", - kvm_hyperv_properties[i].desc, - kvm_hyperv_properties[i].name); - return 1; + if (*flag) { + fprintf(stderr, + "Hyper-V %s (requested by '%s' cpu flag) " + "is not supported by kernel\n", + kvm_hyperv_properties[i].desc, + kvm_hyperv_properties[i].name); + return 1; + } else { + present =3D false; + break; + } } =20 env->features[fw] |=3D bits; } =20 + if (cpu->hyperv_all && present) { + *flag =3D true; + } + return 0; } =20 @@ -1047,6 +1059,43 @@ static int hv_cpuid_check_and_set(CPUState *cs, stru= ct kvm_cpuid2 *cpuid, return 1; } =20 +static int hv_report_missing_dep(X86CPU *cpu, const char *name, + const char *dep_name) +{ + int i, j, nprops =3D sizeof(kvm_hyperv_properties); + + for (i =3D 0; i < nprops; i++) { + if (!strcmp(kvm_hyperv_properties[i].name, name)) { + break; + } + } + for (j =3D 0; j < nprops; j++) { + if (!strcmp(kvm_hyperv_properties[j].name, dep_name)) { + break; + } + } + + /* + * Internal error: either feature or its dependency is not in + * kvm_hyperv_properties! + */ + if (i =3D=3D nprops || j =3D=3D nprops) { + return 1; + } + + if (cpu->hyperv_all) { + fprintf(stderr, "Hyper-V %s (requested by 'hv-all' cpu flag) " + "requires %s (is not supported by kernel)\n", + kvm_hyperv_properties[i].desc, kvm_hyperv_properties[j].de= sc); + } else { + fprintf(stderr, "Hyper-V %s (requested by '%s' cpu flag) " + "requires %s ('%s')\n", kvm_hyperv_properties[i].desc, + name, kvm_hyperv_properties[j].desc, dep_name); + } + + return 1; +} + /* * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt in * case of success, errno < 0 in case of failure and 0 when no Hyper-V @@ -1086,32 +1135,54 @@ static int hyperv_handle_properties(CPUState *cs, cpuid =3D get_supported_hv_cpuid_legacy(cs); } =20 + if (cpu->hyperv_all) { + memcpy(cpuid_ent, &cpuid->entries[0], + cpuid->nent * sizeof(cpuid->entries[0])); + + c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); + if (c) { + env->features[FEAT_HYPERV_EAX] =3D c->eax; + env->features[FEAT_HYPERV_EBX] =3D c->ebx; + env->features[FEAT_HYPERV_EDX] =3D c->eax; + } + c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); + if (c) { + env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; + + /* hv-spinlocks may have been overriden */ + if (cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_R= ETRY) { + c->ebx =3D cpu->hyperv_spinlock_attempts; + } + } + c =3D cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); + if (c) { + env->features[FEAT_HV_NESTED_EAX] =3D c->eax; + } + } + /* Features */ r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-relaxed", - cpu->hyperv_relaxed_timing); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-vapic", cpu->hyperv_vapic= ); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-time", cpu->hyperv_time); + &cpu->hyperv_relaxed_timing); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-vapic", &cpu->hyperv_vapi= c); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-time", &cpu->hyperv_time); r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-frequencies", - cpu->hyperv_frequencies); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-crash", cpu->hyperv_crash= ); + &cpu->hyperv_frequencies); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-crash", &cpu->hyperv_cras= h); r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-reenlightenment", - cpu->hyperv_reenlightenment); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-reset", cpu->hyperv_reset= ); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-vpindex", cpu->hyperv_vpi= ndex); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-runtime", cpu->hyperv_run= time); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-synic", cpu->hyperv_synic= ); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-stimer", cpu->hyperv_stim= er); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush", cpu->hyperv_tl= bflush); - r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", cpu->hyperv_ipi); + &cpu->hyperv_reenlightenment); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-reset", &cpu->hyperv_rese= t); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-vpindex", &cpu->hyperv_vp= index); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-runtime", &cpu->hyperv_ru= ntime); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-synic", &cpu->hyperv_syni= c); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-stimer", &cpu->hyperv_sti= mer); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush", + &cpu->hyperv_tlbflush); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", &cpu->hyperv_ipi); =20 /* Dependencies */ if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only && - !cpu->hyperv_vpindex) { - fprintf(stderr, "Hyper-V SynIC " - "(requested by 'hv-synic' cpu flag) " - "requires Hyper-V VP_INDEX ('hv-vpindex')\n"); - r |=3D 1; - } + !cpu->hyperv_vpindex) + r |=3D hv_report_missing_dep(cpu, "hv-synic", "hv-vpindex"); =20 /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; @@ -1121,6 +1192,12 @@ static int hyperv_handle_properties(CPUState *cs, goto free; } =20 + if (cpu->hyperv_all) { + /* We already copied all feature words from KVM as is */ + r =3D cpuid->nent; + goto free; + } + c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; if (!cpu->hyperv_vendor_id) { @@ -1192,11 +1269,26 @@ free: return r; } =20 +static Error *hv_all_mig_blocker; + static int hyperv_init_vcpu(X86CPU *cpu) { CPUState *cs =3D CPU(cpu); + Error *local_err =3D NULL; int ret; =20 + if (cpu->hyperv_all && hv_all_mig_blocker =3D=3D NULL) { + error_setg(&hv_all_mig_blocker, + "'hv-all' CPU flag prevents migration, use explicit set= of " + "hv-* flags instead"); + ret =3D migrate_add_blocker(hv_all_mig_blocker, &local_err); + if (local_err) { + error_report_err(local_err); + error_free(hv_all_mig_blocker); + return ret; + } + } + if (cpu->hyperv_vpindex && !hv_vpindex_settable) { /* * the kernel doesn't support setting vp_index; assert that its va= lue --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869799907382.26082745052145; Fri, 29 Mar 2019 07:29:59 -0700 (PDT) Received: from localhost ([127.0.0.1]:54485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sW5-0008Qc-LH for importer@patchew.org; Fri, 29 Mar 2019 10:29:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sUI-0006sP-RV for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:28:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sUI-0007zB-04 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:28:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sUH-0007yw-Oq for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:28:05 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A94FA308402A; Fri, 29 Mar 2019 14:18:47 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0FC91001DD6; Fri, 29 Mar 2019 14:18:45 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:29 +0100 Message-Id: <20190329141832.22882-6-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 29 Mar 2019 14:18:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/8] i386/kvm: hv-evmcs requires hv-vapic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Enlightened VMCS is enabled by writing to a field in VP assist page and these require virtual APIC. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index af45241adb..9edf76e473 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1083,7 +1083,7 @@ static int hv_report_missing_dep(X86CPU *cpu, const c= har *name, return 1; } =20 - if (cpu->hyperv_all) { + if (cpu->hyperv_all && strcmp(name, "hv-evmcs")) { fprintf(stderr, "Hyper-V %s (requested by 'hv-all' cpu flag) " "requires %s (is not supported by kernel)\n", kvm_hyperv_properties[i].desc, kvm_hyperv_properties[j].de= sc); @@ -1183,6 +1183,9 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only && !cpu->hyperv_vpindex) r |=3D hv_report_missing_dep(cpu, "hv-synic", "hv-vpindex"); + if (cpu->hyperv_evmcs && !cpu->hyperv_vapic) { + r |=3D hv_report_missing_dep(cpu, "hv-evmcs", "hv-vapic"); + } =20 /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869628355938.7820350692903; Fri, 29 Mar 2019 07:27:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:54461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sTJ-0005Ze-9D for importer@patchew.org; Fri, 29 Mar 2019 10:27:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sRp-0004n5-VR for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:25:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sRo-0006bw-T4 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:25:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52192) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sRo-0006aT-Iy for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:25:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA7BF85528; Fri, 29 Mar 2019 14:18:49 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFAD71001E91; Fri, 29 Mar 2019 14:18:47 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:30 +0100 Message-Id: <20190329141832.22882-7-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 29 Mar 2019 14:18:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/8] i386/kvm: hv-stimer requires hv-time and hv-synic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Synthetic timers operate in hv-time time and Windows won't use these without SynIC. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 9edf76e473..524ee28e9c 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1186,6 +1186,12 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_evmcs && !cpu->hyperv_vapic) { r |=3D hv_report_missing_dep(cpu, "hv-evmcs", "hv-vapic"); } + if (cpu->hyperv_stimer && !cpu->hyperv_synic) { + r |=3D hv_report_missing_dep(cpu, "hv-stimer", "hv-synic"); + } + if (cpu->hyperv_stimer && !cpu->hyperv_time) { + r |=3D hv_report_missing_dep(cpu, "hv-stimer", "hv-time"); + } =20 /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869922669851.02382483127; Fri, 29 Mar 2019 07:32:02 -0700 (PDT) Received: from localhost ([127.0.0.1]:54533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sY1-0001rm-JX for importer@patchew.org; Fri, 29 Mar 2019 10:31:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sUP-0006yC-MA for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:28:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sUO-00080w-TH for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:28:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sUO-00080d-N1 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:28:12 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE9BF3086218; Fri, 29 Mar 2019 14:18:51 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D9771001DD6; Fri, 29 Mar 2019 14:18:49 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:31 +0100 Message-Id: <20190329141832.22882-8-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 29 Mar 2019 14:18:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 7/8] i386/kvm: hv-tlbflush/ipi require hv-vpindex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The corresponding hypercalls require using VP indexes. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 524ee28e9c..976c1d570f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1192,6 +1192,12 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_stimer && !cpu->hyperv_time) { r |=3D hv_report_missing_dep(cpu, "hv-stimer", "hv-time"); } + if (cpu->hyperv_tlbflush && !cpu->hyperv_vpindex) { + r |=3D hv_report_missing_dep(cpu, "hv-tlbflush", "hv-vpindex"); + } + if (cpu->hyperv_ipi && !cpu->hyperv_vpindex) { + r |=3D hv_report_missing_dep(cpu, "hv-ipi", "hv-vpindex"); + } =20 /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; --=20 2.20.1 From nobody Sat May 4 11:30:38 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553869526581896.920033468869; Fri, 29 Mar 2019 07:25:26 -0700 (PDT) Received: from localhost ([127.0.0.1]:54419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sRO-0004EX-On for importer@patchew.org; Fri, 29 Mar 2019 10:25:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sQW-0003U0-Fd for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:24:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sQV-0006Eg-AF for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:24:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sQV-0006EC-05 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:24:11 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E16F1F74D4; Fri, 29 Mar 2019 14:18:53 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 206EA1001E91; Fri, 29 Mar 2019 14:18:51 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:32 +0100 Message-Id: <20190329141832.22882-9-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 29 Mar 2019 14:18:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 8/8] i386/kvm: add support for Direct Mode for Hyper-V synthetic timers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Hyper-V on KVM can only use Synthetic timers with Direct Mode (opting for an interrupt instead of VMBus message). This new capability is only announced in KVM_GET_SUPPORTED_HV_CPUID. Signed-off-by: Vitaly Kuznetsov --- docs/hyperv.txt | 10 ++++++++++ target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/hyperv-proto.h | 1 + target/i386/kvm.c | 15 +++++++++++++++ 5 files changed, 28 insertions(+) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index d1299aba81..e1988ab648 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -173,6 +173,16 @@ without the feature to find out if enabling it is bene= ficial. =20 Requires: hv-vapic =20 +3.17. hv-stimer-direct +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Hyper-V specification allows synthetic timer operation in two modes: "clas= sic", +when expiration event is delivered as SynIC message and "direct", when the= event +is delivered via normal interrupt. It is known that nested Hyper-V can only +use synthetic timers in direct mode and thus 'hv-stimer-direct' needs to be +enabled. + +Requires: hv-vpindex, hv-synic, hv-time, hv-stimer + =20 4. Development features =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4e01ad076e..ea3843ed0c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5785,6 +5785,7 @@ static Property x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false), DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false), DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false), + DEFINE_PROP_BOOL("hv-stimer-direct", X86CPU, hyperv_stimer_direct, fal= se), DEFINE_PROP_BOOL("hv-all", X86CPU, hyperv_all, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 9cd3a8bc2f..3f1ada3e39 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1396,6 +1396,7 @@ struct X86CPU { bool hyperv_tlbflush; bool hyperv_evmcs; bool hyperv_ipi; + bool hyperv_stimer_direct; bool hyperv_all; bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h index c0272b3a01..cffac10b45 100644 --- a/target/i386/hyperv-proto.h +++ b/target/i386/hyperv-proto.h @@ -49,6 +49,7 @@ #define HV_GUEST_IDLE_STATE_AVAILABLE (1u << 5) #define HV_FREQUENCY_MSRS_AVAILABLE (1u << 8) #define HV_GUEST_CRASH_MSR_AVAILABLE (1u << 10) +#define HV_STIMER_DIRECT_MODE_AVAILABLE (1u << 19) =20 /* * HV_CPUID_ENLIGHTMENT_INFO.EAX bits diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 976c1d570f..f3c73b7c4e 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -657,6 +657,7 @@ static bool hyperv_enabled(X86CPU *cpu) cpu->hyperv_reenlightenment || cpu->hyperv_tlbflush || cpu->hyperv_ipi || + cpu->hyperv_stimer_direct || cpu->hyperv_all); } =20 @@ -832,6 +833,15 @@ static struct { {0} } }, + { + .name =3D "hv-stimer-direct", + .desc =3D "direct mode timers", + .flags =3D { + {.fw =3D FEAT_HYPERV_EDX, + .bits =3D HV_STIMER_DIRECT_MODE_AVAILABLE}, + {0} + } + }, }; =20 static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) @@ -1178,6 +1188,8 @@ static int hyperv_handle_properties(CPUState *cs, r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush", &cpu->hyperv_tlbflush); r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", &cpu->hyperv_ipi); + r |=3D hv_cpuid_check_and_set(cs, cpuid, "hv-stimer-direct", + &cpu->hyperv_stimer_direct); =20 /* Dependencies */ if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only && @@ -1198,6 +1210,9 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_ipi && !cpu->hyperv_vpindex) { r |=3D hv_report_missing_dep(cpu, "hv-ipi", "hv-vpindex"); } + if (cpu->hyperv_stimer_direct && !cpu->hyperv_stimer) { + r |=3D hv_report_missing_dep(cpu, "hv-stimer-direct", "hv-stimer"); + } =20 /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; --=20 2.20.1