From nobody Wed May 14 07:58:21 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; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523920588866507.4943102620456; Mon, 16 Apr 2018 16:16:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D289326227A; Mon, 16 Apr 2018 23:16:26 +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 0C0876E412; Mon, 16 Apr 2018 23:16:26 +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 144FE180BAD3; Mon, 16 Apr 2018 23:16:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3GNGNPL008603 for ; Mon, 16 Apr 2018 19:16:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3F6C76E412; Mon, 16 Apr 2018 23:16:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38EFE7A41B for ; Mon, 16 Apr 2018 23:16:20 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50161C057F4E for ; Mon, 16 Apr 2018 23:16:19 +0000 (UTC) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3GN9Wqm099584 for ; Mon, 16 Apr 2018 19:16:18 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hd23gytr8-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 16 Apr 2018 19:16:18 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Apr 2018 19:16:17 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Apr 2018 19:16:14 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3GNGEte52035732; Mon, 16 Apr 2018 23:16:14 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC64FB2050; Mon, 16 Apr 2018 20:18:18 -0400 (EDT) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.57]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id B698AB204D; Mon, 16 Apr 2018 20:18:18 -0400 (EDT) From: Collin Walling To: libvir-list@redhat.com Date: Mon, 16 Apr 2018 19:16:09 -0400 In-Reply-To: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> References: <1523920569-9386-1-git-send-email-walling@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041623-2213-0000-0000-00000292B9E2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008866; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018943; UDB=6.00519786; IPR=6.00798184; MB=3.00020604; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-16 23:16:15 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041623-2214-0000-0000-000059C7CDF8 Message-Id: <1523920569-9386-5-git-send-email-walling@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-16_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804160192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 16 Apr 2018 23:16:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 16 Apr 2018 23:16:19 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'walling@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: cventeic@redhat.com Subject: [libvirt] [PATCH v1 4/4] qemu: hook up cpu-comparison to qemu driver 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 16 Apr 2018 23:16:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virsh cpu-compare command accepts an xml file that describes a cpu definition and compares it to a master xml file containing the host CPU. Not all architectures follow this procedure, and instead compare CPU's via QEMU. Let's hook up this capability to the QEMU driver and, if the capabilitiy is available, compare the host CPU with the CPU defined in the xml file. Signed-off-by: Collin Walling --- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_capabilities.h | 3 ++ src/qemu/qemu_driver.c | 96 ++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d385ad8..e4ce086 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -657,7 +657,7 @@ virQEMUCapsFindBinary(const char *format, return ret; } =20 -static char * +char * virQEMUCapsFindBinaryForArch(virArch hostarch, virArch guestarch) { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f27a359..01770f9 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -579,6 +579,9 @@ bool virQEMUCapsGuestIsNative(virArch host, bool virQEMUCapsCPUFilterFeatures(const char *name, void *opaque); =20 +char *virQEMUCapsFindBinaryForArch(virArch hostarch, + virArch guestarch); + qemuMonitorCPUModelInfoPtr virQEMUCapsProbeQMPCPUModelComparison(char *binary, virCPUDefPtr cpuA, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 92f5fe6..c87792b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13100,6 +13100,85 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) return ret; } =20 + +/** + * qemuCompareCPU: + * @binary: QEMU binary to issue the comparison command to + * @host: host CPU definition + * @xml: XML description of either guest or host CPU to be compared with @= host + * @failIncompatible: return an error instead of VIR_CPU_COMPARE_INCOMPATI= BLE + * + * Compares the target CPU described by @xml with @host CPU to produce a t= hird + * model containing the comparison result and the list of features respons= ible + * format the result. This function discards the responsible features. + * + * Compared model results: + * + * "incompatible": target cpu cannot run on @host. + * + * "subset": @host is an older cpu model than target, or @host does not + * support all features enabled on target. + * + * This result is considered incompatible. + * + * "identical": @host and target are identical; target can run on @host. + * + * "superset": @host is a newer cpu model than target, or @host supports = some + * features not supported by target; target can run on @host. + * + * Returns: virCPUCompareResult based on the produced "compared" model's n= ame, + * or VIR_CPU_COMPARE_ERROR upon error. + */ +static virCPUCompareResult +qemuCompareCPU(char *binary, + virCPUDefPtr hostCPU, + const char *xml, + bool failIncompatible) +{ + virCPUDefPtr targetCPU =3D NULL; + qemuMonitorCPUModelInfoPtr result =3D NULL; + virCPUCompareResult ret =3D VIR_CPU_COMPARE_ERROR; + + VIR_DEBUG("binary=3D%s, hostCPU=3D%p, xml=3D%s", binary, hostCPU, NULL= STR(xml)); + + if (!hostCPU || !hostCPU->model) { + if (failIncompatible) { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", + _("cannot get host CPU capabilities")); + } else { + VIR_WARN("cannot get host CPU capabilities"); + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + } + goto cleanup; + } + + if (virCPUDefParseXMLHelper(xml, NULL, VIR_CPU_TYPE_AUTO, &targetCPU) = < 0) + goto cleanup; + + if (!(result =3D virQEMUCapsProbeQMPCPUModelComparison(binary, hostCPU, + targetCPU))) + goto cleanup; + + if (STREQ(result->name, "incompatible") || + STREQ(result->name, "subset")) + ret =3D VIR_CPU_COMPARE_INCOMPATIBLE; + else if (STREQ(result->name, "identical")) + ret =3D VIR_CPU_COMPARE_IDENTICAL; + else if (STREQ(result->name, "superset")) + ret =3D VIR_CPU_COMPARE_SUPERSET; + + if (failIncompatible && ret =3D=3D VIR_CPU_COMPARE_INCOMPATIBLE) { + ret =3D VIR_CPU_COMPARE_ERROR; + virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); + } + + cleanup: + virCPUDefFree(targetCPU); + qemuMonitorCPUModelInfoFree(result); + return ret; +} + + static int qemuConnectCompareCPU(virConnectPtr conn, const char *xmlDesc, @@ -13109,6 +13188,8 @@ qemuConnectCompareCPU(virConnectPtr conn, int ret =3D VIR_CPU_COMPARE_ERROR; virCapsPtr caps =3D NULL; bool failIncompatible; + char *binary =3D NULL; + virQEMUCapsPtr qemuCaps =3D NULL; =20 virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE, VIR_CPU_COMPARE_ERROR); @@ -13121,11 +13202,26 @@ qemuConnectCompareCPU(virConnectPtr conn, if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; =20 + binary =3D virQEMUCapsFindBinaryForArch(caps->host.arch, caps->host.ar= ch); + + if (binary) { + qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, binary); + + if (qemuCaps && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON)= ) { + ret =3D qemuCompareCPU(binary, caps->host.cpu, xmlDesc, + failIncompatible); + goto cleanup; + } + } + ret =3D virCPUCompareXML(caps->host.arch, caps->host.cpu, xmlDesc, failIncompatible); =20 cleanup: + VIR_FREE(binary); virObjectUnref(caps); + virObjectUnref(qemuCaps); return ret; } =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list