From nobody Sun Sep 28 00:37:55 2025 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; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1561081709; cv=none; d=zoho.com; s=zohoarc; b=Kaq9zigA2ib9OldSaV3XBA7TpEIVe+DOJ5pfJGPp0ukgtlMo9Vd20icx7JQMvfW2FV1C4S45J+oswU1YceVdPzdIAQOq0BP6tEt+YP/q/yy9w8cxvtBs6Wvs3KijnYFx0xfpKQRyDmhnxf4qPIksQZdxIh68jyRm6W+D1qWD/vA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561081709; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Qznel7g6fB8yvYmlOFOQWGexcJCqwQlz1eNoYvx8nfE=; b=iXYWddTnxD2uYEcD0Z4Iv8CUSrabVLwZNH6JXW7Jrk0X3oCPl0SXyjQU/V0uXWa9PbcYvShDAZj3r0y0olkIcbV0eAaI0TShVMkHEd8PrKQsY5PPVppI7mDOhsmxiNG467q8MCxtkdCsyt86xJENP4bqjUWG9LMJdQw5dFUhhpw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561081709768102.08165898289462; Thu, 20 Jun 2019 18:48:29 -0700 (PDT) Received: from localhost ([::1]:54040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8f6-0000ER-P0 for importer@patchew.org; Thu, 20 Jun 2019 21:48:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40779) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8Zg-0006O9-8L for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:42:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1he8Zb-0006Dw-Lf for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:42:43 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1he8Zb-0006CS-Ai for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:42:39 -0400 Received: by mail-wm1-x343.google.com with SMTP id x15so4781985wmj.3 for ; Thu, 20 Jun 2019 18:42:39 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d1sm1123125wru.41.2019.06.20.18.42.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 18:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qznel7g6fB8yvYmlOFOQWGexcJCqwQlz1eNoYvx8nfE=; b=uwDjoxtNwKWhkcDCmFCbjG47QdiGxto9pf0wfYY7d6Jwxd/4lVt4+QXpZ8GRsEOdKh /NlXcnZZ9p/I54EG6ecnSiBTw8Aeko64nvAEJsT+U8Zqp9nmGdGaDniVyguEUvWTifXT iYglC6cUIQpRN4Ls+RCoalWdVBirmBnSSKJJGW34vzKG0q1M6LrTx952RPoobAFuKxp4 Ds8ez04g/k0KrEcXel7hL3uX/1FJNePU9maxO5Q+UBiYHydQ9ozOJKFSsNzYa/GWxX33 tJwXviIHpmeo3FOl6Z0ub2KdUPqK5336LKKGbikZ/ZTR1HJIFypCciNj1f6Qbj/QRNEr +6ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Qznel7g6fB8yvYmlOFOQWGexcJCqwQlz1eNoYvx8nfE=; b=Z0dnO3S9ZxRnqnEWnBoEYWFrYwgFOzt6sb839ig7QTwDikVY7jgT13GriWE1fiFci0 hw3h53GhYocHmE8PjcO9iA3xn7i50/6RrF6214UOuDwxxE6ONe3wxM4hSUZLuDUQ9D7q jH2/wUK47dY0rfVlBu3xH1VhnAAhS3baQVM8Bpd+tu27PcywS+zqOtTPT+UOiRxWNWS5 9FazKka79btUxcceTLKVQimqhV4WFTMaTbCL+n7mWeRFHJVJG7YNFrwcEycliarj7ocu yWdtI4lEWxCpU/tLbm3mEEqbo78MQD5YnBfgzkjKGwbb9ritWe+PkRva3LFi7r4tsygE xESA== X-Gm-Message-State: APjAAAUA0ZOb/5eBdJtTMnnzJ1AE11ab3Kn9Z7PgDP2X+4ieHwGgRPDJ HvdCQZLC9qM7Qv+EAA5xKeWumqjK X-Google-Smtp-Source: APXvYqzpBChMODW8bDQdh5hmaKOFNTwT1biw+8jIOlcW8q3rgaCygfUZT6UGlrEADf0ipOgVUner9g== X-Received: by 2002:a7b:c933:: with SMTP id h19mr1621240wml.52.1561081358051; Thu, 20 Jun 2019 18:42:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 03:42:10 +0200 Message-Id: <1561081350-3723-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> References: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 05/25] i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vitaly Kuznetsov Let's consolidate Hyper-V features handling in hyperv_handle_properties(). The change is necessary to support 'hv-passthrough' mode as we'll be just copying CPUIDs from KVM instead of filling them in. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-4-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- 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 cd492d4..a041b4d 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1013,13 +1013,25 @@ static int hv_cpuid_check_and_set(CPUState *cs, str= uct kvm_cpuid2 *cpuid, return 0; } =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 (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { uint16_t evmcs_version; =20 @@ -1068,9 +1080,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 hyperv_feat_enabled(cpu, HYPERV_FEAT_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 (hyperv_feat_enabled(cpu, HYPERV_FEAT_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) @@ -1179,79 +1262,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 hyperv_feat_enabled(cpu, HYPERV_FEAT_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 (hyperv_feat_enabled(cpu, HYPERV_FEAT_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 1.8.3.1