From nobody Thu May 15 13:06:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507129495736362.4901558664045; Wed, 4 Oct 2017 08:04:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CE1480E6A; Wed, 4 Oct 2017 15:04:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 793635D96E; Wed, 4 Oct 2017 15:04:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4331E18355C6; Wed, 4 Oct 2017 15:04:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v94EwvSW006866 for ; Wed, 4 Oct 2017 10:58:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49E7B5E1A1; Wed, 4 Oct 2017 14:58:57 +0000 (UTC) Received: from mamuti.net (unknown [10.34.246.102]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ECD905E1A0 for ; Wed, 4 Oct 2017 14:58:56 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 608181084D9; Wed, 4 Oct 2017 16:58:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9CE1480E6A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 4 Oct 2017 16:58:40 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/23] cputest: Use CPU models from QEMU when available X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 04 Oct 2017 15:04:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When testing cpuDecode for computing guest CPU definition from CPUID data (the CPU definition reported by domain capabilities), we need to use CPU models (and their usability blockers) from QEMU if they are available to cpuDecode in the same way it is actually used in the qemu driver. Signed-off-by: Jiri Denemark Reviewed-by: John Ferlan --- tests/cputest.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/tests/cputest.c b/tests/cputest.c index b72c17a168..18618ad309 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -515,6 +515,37 @@ cpuTestMakeQEMUCaps(const struct data *data) qemuCaps =3D NULL; goto cleanup; } + + +static virDomainCapsCPUModelsPtr +cpuTestGetCPUModels(const struct data *data) +{ + virDomainCapsCPUModelsPtr models =3D NULL; + virQEMUCapsPtr qemuCaps; + + if (data->flags !=3D JSON_MODELS) + return NULL; + + if (!(qemuCaps =3D cpuTestMakeQEMUCaps(data))) + return NULL; + + models =3D virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM); + if (models) + virObjectRef(models); + + virObjectUnref(qemuCaps); + + return models; +} + +#else /* if WITH_QEMU && WITH_YAJL */ + +static virDomainCapsCPUModelsPtr +cpuTestGetCPUModels(const struct data *data ATTRIBUTE_UNUSED) +{ + return NULL; +} + #endif =20 =20 @@ -528,6 +559,7 @@ cpuTestCPUID(bool guest, const void *arg) char *host =3D NULL; virCPUDefPtr cpu =3D NULL; char *result =3D NULL; + virDomainCapsCPUModelsPtr models =3D NULL; =20 if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir, virArchToString(data->arch), data->host) <= 0) @@ -549,7 +581,10 @@ cpuTestCPUID(bool guest, const void *arg) cpu->type =3D VIR_CPU_TYPE_HOST; } =20 - if (cpuDecode(cpu, hostData, NULL) < 0) + if (guest) + models =3D cpuTestGetCPUModels(data); + + if (cpuDecode(cpu, hostData, models) < 0) goto cleanup; =20 if (virAsprintf(&result, "cpuid-%s-%s", @@ -565,6 +600,7 @@ cpuTestCPUID(bool guest, const void *arg) virCPUDataFree(hostData); virCPUDefFree(cpu); VIR_FREE(result); + virObjectUnref(models); return ret; } =20 @@ -686,6 +722,8 @@ cpuTestUpdateLive(const void *arg) virCPUDataPtr disabledData =3D NULL; char *expectedFile =3D NULL; virCPUDefPtr expected =3D NULL; + virDomainCapsCPUModelsPtr hvModels =3D NULL; + virDomainCapsCPUModelsPtr models =3D NULL; int ret =3D -1; =20 if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 || @@ -704,13 +742,42 @@ cpuTestUpdateLive(const void *arg) !(disabledData =3D virCPUDataParse(disabled))) goto cleanup; =20 - if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0) - goto cleanup; - if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 || !(expected =3D cpuTestLoadXML(data->arch, expectedFile))) goto cleanup; =20 + /* In case the host CPU signature does not exactly match any CPU model= from + * cpu_map.xml, the CPU model we detect from CPUID may differ from the= one + * we compute by asking QEMU. Since this test expands both CPU models = and + * compares their features, we can try to translate the 'actual' CPU to + * use the CPU model from 'expected'. + */ + if (STRNEQ(cpu->model, expected->model)) { + virDomainCapsCPUModelPtr hvModel; + char **blockers =3D NULL; + virDomainCapsCPUUsable usable =3D VIR_DOMCAPS_CPU_USABLE_UNKNOWN; + + if (!(models =3D virDomainCapsCPUModelsNew(0))) + goto cleanup; + + if ((hvModels =3D cpuTestGetCPUModels(data)) && + virCPUModelIsAllowed(expected->model, hvModels, &hvModel)) { + blockers =3D hvModel->blockers; + usable =3D hvModel->usable; + } + + if (virDomainCapsCPUModelsAdd(models, expected->model, -1, + usable, blockers) < 0) + goto cleanup; + + cpu->fallback =3D VIR_CPU_FALLBACK_ALLOW; + ignore_value(virCPUTranslate(data->arch, cpu, models)); + cpu->fallback =3D VIR_CPU_FALLBACK_FORBID; + } + + if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0) + goto cleanup; + ret =3D cpuTestUpdateLiveCompare(data->arch, cpu, expected); =20 cleanup: @@ -724,6 +791,8 @@ cpuTestUpdateLive(const void *arg) virCPUDataFree(disabledData); VIR_FREE(expectedFile); virCPUDefFree(expected); + virObjectUnref(hvModels); + virObjectUnref(models); return ret; } =20 @@ -915,11 +984,11 @@ mymain(void) DO_TEST(arch, cpuTestHostCPUID, host, host, \ NULL, NULL, 0, 0); \ DO_TEST(arch, cpuTestGuestCPUID, host, host, \ - NULL, NULL, 0, 0); \ + NULL, NULL, json, 0); \ DO_TEST_CPUID_JSON(arch, host, json); \ if (json !=3D JSON_NONE) { \ DO_TEST(arch, cpuTestUpdateLive, host, host, \ - NULL, NULL, 0, 0); \ + NULL, NULL, json, 0); \ } \ } while (0) =20 --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list