Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:Update
libvirt.10484
libvirt-conf-include-x86-microcode-version-in-v...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File libvirt-conf-include-x86-microcode-version-in-virsh-capabiltiies.patch of Package libvirt.10484
From 8938484e8362f60ac2b890193d0f624a149bdf1b Mon Sep 17 00:00:00 2001 Message-Id: <8938484e8362f60ac2b890193d0f624a149bdf1b@dist-git> From: Paolo Bonzini <pbonzini@redhat.com> Date: Tue, 12 Dec 2017 16:23:40 +0100 Subject: [PATCH] conf: include x86 microcode version in virsh capabiltiies 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. CVE-2017-5715 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Conflicts: src/conf/capabilities.h src/libvirt_private.syms - context src/conf/cpu_conf.c - no virCPUDefStealModel API in 7.3 src/cpu/cpu_x86.c - CPU driver was heavily refactored since 7.3; the code had to be moved to the caller of cpuNodeData Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/conf/capabilities.c | 12 ++++++++++++ src/conf/capabilities.h | 2 ++ src/conf/cpu_conf.c | 13 +++++++++++++ src/conf/cpu_conf.h | 1 + src/libvirt_private.syms | 1 + src/qemu/qemu_capabilities.c | 13 ++++++++++++- tests/testutilsqemu.c | 2 ++ 7 files changed, 43 insertions(+), 1 deletion(-) Index: libvirt-1.2.18.4/src/conf/capabilities.c =================================================================== --- libvirt-1.2.18.4.orig/src/conf/capabilities.c +++ libvirt-1.2.18.4/src/conf/capabilities.c @@ -321,6 +321,18 @@ virCapabilitiesAddHostNUMACell(virCapsPt /** + * virCapabilitiesGetMicrocodeVersion: + * @caps: capabilities to access + * + * Get host CPU microcode version, or 0 if unavailable + */ +unsigned int +virCapabilitiesGetMicrocodeVersion(virCapsPtr caps) +{ + return caps->host.cpu ? caps->host.cpu->microcodeVersion : 0; +} + +/** * virCapabilitiesSetHostCPU: * @caps: capabilities to extend * @cpu: CPU definition Index: libvirt-1.2.18.4/src/conf/capabilities.h =================================================================== --- libvirt-1.2.18.4.orig/src/conf/capabilities.h +++ libvirt-1.2.18.4/src/conf/capabilities.h @@ -290,4 +290,6 @@ virCapabilitiesFormatXML(virCapsPtr caps virBitmapPtr virCapabilitiesGetCpusForNodemask(virCapsPtr caps, virBitmapPtr nodemask); +unsigned int virCapabilitiesGetMicrocodeVersion(virCapsPtr caps); + #endif /* __VIR_CAPABILITIES_H */ Index: libvirt-1.2.18.4/src/conf/cpu_conf.c =================================================================== --- libvirt-1.2.18.4.orig/src/conf/cpu_conf.c +++ libvirt-1.2.18.4/src/conf/cpu_conf.c @@ -96,6 +96,7 @@ virCPUDefCopyModel(virCPUDefPtr dst, VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 || VIR_ALLOC_N(dst->features, src->nfeatures) < 0) return -1; + dst->microcodeVersion = src->microcodeVersion; dst->nfeatures_max = dst->nfeatures = src->nfeatures; for (i = 0; i < dst->nfeatures; i++) { @@ -243,6 +244,14 @@ virCPUDefParseXML(xmlNodePtr node, goto error; } 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; + } } if (!(def->model = virXPathString("string(./model[1])", ctxt)) && @@ -556,6 +565,10 @@ virCPUDefFormatBuf(virBufferPtr buf, if (formatModel && def->vendor) virBufferEscapeString(buf, "<vendor>%s</vendor>\n", def->vendor); + if (def->type == VIR_CPU_TYPE_HOST && def->microcodeVersion) + virBufferAsprintf(buf, "<microcode version='%u'/>\n", + def->microcodeVersion); + if (def->sockets && def->cores && def->threads) { virBufferAddLit(buf, "<topology"); virBufferAsprintf(buf, " sockets='%u'", def->sockets); Index: libvirt-1.2.18.4/src/conf/cpu_conf.h =================================================================== --- libvirt-1.2.18.4.orig/src/conf/cpu_conf.h +++ libvirt-1.2.18.4/src/conf/cpu_conf.h @@ -103,6 +103,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; Index: libvirt-1.2.18.4/src/libvirt_private.syms =================================================================== --- libvirt-1.2.18.4.orig/src/libvirt_private.syms +++ libvirt-1.2.18.4/src/libvirt_private.syms @@ -56,6 +56,7 @@ virCapabilitiesFormatXML; virCapabilitiesFreeMachines; virCapabilitiesFreeNUMAInfo; virCapabilitiesGetCpusForNodemask; +virCapabilitiesGetMicrocodeVersion; virCapabilitiesHostSecModelAddBaseLabel; virCapabilitiesNew; virCapabilitiesSetHostCPU; Index: libvirt-1.2.18.4/src/qemu/qemu_capabilities.c =================================================================== --- libvirt-1.2.18.4.orig/src/qemu/qemu_capabilities.c +++ libvirt-1.2.18.4/src/qemu/qemu_capabilities.c @@ -340,6 +340,8 @@ struct virQEMUCapsSearchData { static virClassPtr virQEMUCapsClass; static void virQEMUCapsDispose(void *obj); +static unsigned int cpuMicrocodeVersion; + static int virQEMUCapsOnceInit(void) { if (!(virQEMUCapsClass = virClassNew(virClassForObject(), @@ -348,6 +350,8 @@ static int virQEMUCapsOnceInit(void) virQEMUCapsDispose))) return -1; + cpuMicrocodeVersion = virHostCPUGetMicrocodeVersion(); + return 0; } @@ -958,6 +962,9 @@ virQEMUCapsInitCPU(virCapsPtr caps, virNodeInfo nodeinfo; int ret = -1; + if (virQEMUCapsInitialize() < 0) + goto error; + if (VIR_ALLOC(cpu) < 0) goto error; @@ -976,6 +983,9 @@ virQEMUCapsInitCPU(virCapsPtr caps, || cpuDecode(cpu, data, NULL, 0, NULL) < 0) goto cleanup; + if (ARCH_IS_X86(arch)) + cpu->microcodeVersion = cpuMicrocodeVersion; + ret = 0; cleanup: @@ -3005,7 +3015,8 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps static int -virQEMUCapsInitCached(virQEMUCapsPtr qemuCaps, const char *cacheDir) +virQEMUCapsInitCached(virQEMUCapsPtr qemuCaps, + const char *cacheDir) { char *capsdir = NULL; char *capsfile = NULL; Index: libvirt-1.2.18.4/tests/testutilsqemu.c =================================================================== --- libvirt-1.2.18.4.orig/tests/testutilsqemu.c +++ libvirt-1.2.18.4/tests/testutilsqemu.c @@ -39,6 +39,7 @@ static virCPUDef cpuDefaultData = { NULL, /* vendor_id */ 0, /* fallback */ (char *) "Intel", /* vendor */ + 0, /* microcodeVersion */ 1, /* sockets */ 2, /* cores */ 1, /* threads */ @@ -81,6 +82,7 @@ static virCPUDef cpuHaswellData = { NULL, /* vendor_id */ 0, /* fallback */ (char *) "Intel", /* vendor */ + 0, /* microcodeVersion */ 1, /* sockets */ 2, /* cores */ 2, /* threads */
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor