From nobody Mon Dec 15 03:08:42 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 1515077909927142.058409190235; Thu, 4 Jan 2018 06:58:29 -0800 (PST) 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 A5C37C058EB0; Thu, 4 Jan 2018 14:58:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4889A608F0; Thu, 4 Jan 2018 14:58:28 +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 4E1233FAE0; Thu, 4 Jan 2018 14:58:27 +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 w04EwQKA026565 for ; Thu, 4 Jan 2018 09:58:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 386CA5C8A0; Thu, 4 Jan 2018 14:58:26 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C39663121 for ; Thu, 4 Jan 2018 14:58:23 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B7FBB1015E7; Thu, 4 Jan 2018 15:58:21 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 4 Jan 2018 15:58:11 +0100 Message-Id: <5778dce5f8cf3aa5403dd216e683eaae2a365f9c.1515077784.git.jdenemar@redhat.com> 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 4/5] conf: include x86 microcode version in virsh capabilities 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.32]); Thu, 04 Jan 2018 14:58:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini A microcode update can cause the CPUID bits to change; an example from the past was the update that disabled TSX on several Haswell and Broadwell machines. In order to track the x86 microcode version in the QEMU capabilities, we have to fetch it and store it in the host CPU. This also makes the version visible in "virsh capabilities", which is a nice side effect. Signed-off-by: Paolo Bonzini Signed-off-by: Jiri Denemark --- src/conf/cpu_conf.c | 14 ++++++++++++++ src/conf/cpu_conf.h | 1 + src/cpu/cpu_x86.c | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 603cf0e471..43a3ab5dcd 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -130,6 +130,7 @@ virCPUDefCopyModelFilter(virCPUDefPtr dst, VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 || VIR_ALLOC_N(dst->features, src->nfeatures) < 0) return -1; + dst->microcodeVersion =3D src->microcodeVersion; dst->nfeatures_max =3D src->nfeatures; dst->nfeatures =3D 0; =20 @@ -181,6 +182,7 @@ virCPUDefStealModel(virCPUDefPtr dst, =20 VIR_STEAL_PTR(dst->model, src->model); VIR_STEAL_PTR(dst->features, src->features); + dst->microcodeVersion =3D src->microcodeVersion; dst->nfeatures_max =3D src->nfeatures_max; src->nfeatures_max =3D 0; dst->nfeatures =3D src->nfeatures; @@ -382,6 +384,14 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, goto cleanup; } VIR_FREE(arch); + + if (virXPathBoolean("boolean(./microcode[1]/@version)", ctxt) > 0 = && + virXPathUInt("string(./microcode[1]/@version)", ctxt, + &def->microcodeVersion) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("invalid microcode version")); + goto cleanup; + } } =20 if (!(def->model =3D virXPathString("string(./model[1])", ctxt)) && @@ -720,6 +730,10 @@ virCPUDefFormatBuf(virBufferPtr buf, if (formatModel && def->vendor) virBufferEscapeString(buf, "%s\n", def->vendor); =20 + if (def->type =3D=3D VIR_CPU_TYPE_HOST && def->microcodeVersion) + virBufferAsprintf(buf, "\n", + def->microcodeVersion); + if (def->sockets && def->cores && def->threads) { virBufferAddLit(buf, "sockets); diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index d1983f5d4f..9f2e7ee264 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -133,6 +133,7 @@ struct _virCPUDef { char *vendor_id; /* vendor id returned by CPUID in the guest */ int fallback; /* enum virCPUFallback */ char *vendor; + unsigned int microcodeVersion; unsigned int sockets; unsigned int cores; unsigned int threads; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index fddde64d8c..26314a5b3a 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -33,6 +33,7 @@ #include "virbuffer.h" #include "virendian.h" #include "virstring.h" +#include "virhostcpu.h" =20 #define VIR_FROM_THIS VIR_FROM_CPU =20 @@ -153,6 +154,8 @@ struct _virCPUx86Map { }; =20 static virCPUx86MapPtr cpuMap; +static unsigned int microcodeVersion; + int virCPUx86DriverOnceInit(void); VIR_ONCE_GLOBAL_INIT(virCPUx86Driver); =20 @@ -1409,6 +1412,8 @@ virCPUx86DriverOnceInit(void) if (!(cpuMap =3D virCPUx86LoadMap())) return -1; =20 + microcodeVersion =3D virHostCPUGetMicrocodeVersion(); + return 0; } =20 @@ -2424,6 +2429,9 @@ virCPUx86GetHost(virCPUDefPtr cpu, virCPUDataPtr cpuData =3D NULL; int ret =3D -1; =20 + if (virCPUx86DriverInitialize() < 0) + goto cleanup; + if (!(cpuData =3D virCPUDataNew(archs[0]))) goto cleanup; =20 @@ -2432,6 +2440,7 @@ virCPUx86GetHost(virCPUDefPtr cpu, goto cleanup; =20 ret =3D x86DecodeCPUData(cpu, cpuData, models); + cpu->microcodeVersion =3D microcodeVersion; =20 cleanup: virCPUx86DataFree(cpuData); --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list