Blame SOURCES/libvirt-qemu-capabilities-force-update-if-the-microcode-version-does-not-match.patch

c1c534
From 94ea163b2853d51a3037e8f8ee664058ae7c541d Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <94ea163b2853d51a3037e8f8ee664058ae7c541d@dist-git>
c1c534
From: Paolo Bonzini <pbonzini@redhat.com>
c1c534
Date: Tue, 12 Dec 2017 16:23:41 +0100
c1c534
Subject: [PATCH] qemu: capabilities: force update if the microcode version
c1c534
 does not match
c1c534
c1c534
A microcode update can cause the CPUID bits to change; an example
c1c534
from the past was the update that disabled TSX on several Haswell
c1c534
and Broadwell machines.
c1c534
c1c534
Therefore, place microcode version in the virQEMUCaps struct and
c1c534
XML, and rebuild the cache if the versions do not match.
c1c534
c1c534
CVE-2017-5715
c1c534
c1c534
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
c1c534
Conflicts:
c1c534
	tests/qemucapabilitiesdata/caps_2.10.0-gicv2.aarch64.xml
c1c534
	tests/qemucapabilitiesdata/caps_2.10.0-gicv3.aarch64.xml
c1c534
            - missing in 7.5
c1c534
---
c1c534
 src/qemu/qemu_capabilities.c                       | 40 +++++++++++++++++++++-
c1c534
 src/qemu/qemu_capabilities.h                       |  6 ++--
c1c534
 src/qemu/qemu_capspriv.h                           |  5 +++
c1c534
 src/qemu/qemu_driver.c                             |  9 ++++-
c1c534
 tests/qemucapabilitiesdata/caps_1.2.2.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_1.3.1.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_1.4.2.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_1.5.3.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_1.6.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_1.7.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml  |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  1 +
c1c534
 .../caps_2.6.0-gicv2.aarch64.xml                   |  1 +
c1c534
 .../caps_2.6.0-gicv3.aarch64.xml                   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64.xml    |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml    |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml    |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml    |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml    |  1 +
c1c534
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  1 +
c1c534
 tests/qemucapabilitiestest.c                       | 14 +++++---
c1c534
 tests/qemucapsprobe.c                              |  2 +-
c1c534
 tests/testutilsqemu.c                              |  2 +-
c1c534
 30 files changed, 91 insertions(+), 10 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
c1c534
index 165fdbc5ea..09323d2580 100644
c1c534
--- a/src/qemu/qemu_capabilities.c
c1c534
+++ b/src/qemu/qemu_capabilities.c
c1c534
@@ -507,6 +507,7 @@ struct _virQEMUCaps {
c1c534
     unsigned int version;
c1c534
     unsigned int kvmVersion;
c1c534
     unsigned int libvirtVersion;
c1c534
+    unsigned int microcodeVersion;
c1c534
     char *package;
c1c534
 
c1c534
     virArch arch;
c1c534
@@ -2296,6 +2297,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
c1c534
 
c1c534
     ret->version = qemuCaps->version;
c1c534
     ret->kvmVersion = qemuCaps->kvmVersion;
c1c534
+    ret->microcodeVersion = qemuCaps->microcodeVersion;
c1c534
 
c1c534
     if (VIR_STRDUP(ret->package, qemuCaps->package) < 0)
c1c534
         goto error;
c1c534
@@ -3819,6 +3821,7 @@ struct _virQEMUCapsCachePriv {
c1c534
     uid_t runUid;
c1c534
     gid_t runGid;
c1c534
     virArch hostArch;
c1c534
+    unsigned int microcodeVersion;
c1c534
 };
c1c534
 typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv;
c1c534
 typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr;
c1c534
@@ -3941,6 +3944,13 @@ virQEMUCapsLoadCache(virArch hostArch,
c1c534
         goto cleanup;
c1c534
     }
c1c534
 
c1c534
+    if (virXPathUInt("string(./microcodeVersion)", ctxt,
c1c534
+                     &qemuCaps->microcodeVersion) < 0) {
c1c534
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c1c534
+                       _("missing microcode version in QEMU capabilities cache"));
c1c534
+        goto cleanup;
c1c534
+    }
c1c534
+
c1c534
     if (virXPathBoolean("boolean(./package)", ctxt) > 0) {
c1c534
         qemuCaps->package = virXPathString("string(./package)", ctxt);
c1c534
         if (!qemuCaps->package &&
c1c534
@@ -4219,6 +4229,9 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps)
c1c534
     virBufferAsprintf(&buf, "<kvmVersion>%d</kvmVersion>\n",
c1c534
                       qemuCaps->kvmVersion);
c1c534
 
c1c534
+    virBufferAsprintf(&buf, "<microcodeVersion>%u</microcodeVersion>\n",
c1c534
+                      qemuCaps->microcodeVersion);
c1c534
+
c1c534
     if (qemuCaps->package)
c1c534
         virBufferAsprintf(&buf, "<package>%s</package>\n",
c1c534
                           qemuCaps->package);
c1c534
@@ -4360,6 +4373,16 @@ virQEMUCapsIsValid(void *data,
c1c534
         return false;
c1c534
     }
c1c534
 
c1c534
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
c1c534
+        priv->microcodeVersion != qemuCaps->microcodeVersion) {
c1c534
+        VIR_DEBUG("Outdated capabilities for '%s': microcode version changed "
c1c534
+                  "(%u vs %u)",
c1c534
+                  qemuCaps->binary,
c1c534
+                  priv->microcodeVersion,
c1c534
+                  qemuCaps->microcodeVersion);
c1c534
+        return false;
c1c534
+    }
c1c534
+
c1c534
     return true;
c1c534
 }
c1c534
 
c1c534
@@ -5189,6 +5212,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
c1c534
                                 const char *libDir,
c1c534
                                 uid_t runUid,
c1c534
                                 gid_t runGid,
c1c534
+                                unsigned int microcodeVersion,
c1c534
                                 bool qmpOnly)
c1c534
 {
c1c534
     virQEMUCapsPtr qemuCaps;
c1c534
@@ -5245,6 +5269,9 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
c1c534
     virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM);
c1c534
     virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU);
c1c534
 
c1c534
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
c1c534
+        qemuCaps->microcodeVersion = microcodeVersion;
c1c534
+
c1c534
  cleanup:
c1c534
     VIR_FREE(qmperr);
c1c534
     return qemuCaps;
c1c534
@@ -5266,6 +5293,7 @@ virQEMUCapsNewData(const char *binary,
c1c534
                                            priv->libDir,
c1c534
                                            priv->runUid,
c1c534
                                            priv->runGid,
c1c534
+                                           priv->microcodeVersion,
c1c534
                                            false);
c1c534
 }
c1c534
 
c1c534
@@ -5348,7 +5376,8 @@ virFileCachePtr
c1c534
 virQEMUCapsCacheNew(const char *libDir,
c1c534
                     const char *cacheDir,
c1c534
                     uid_t runUid,
c1c534
-                    gid_t runGid)
c1c534
+                    gid_t runGid,
c1c534
+                    unsigned int microcodeVersion)
c1c534
 {
c1c534
     char *capsCacheDir = NULL;
c1c534
     virFileCachePtr cache = NULL;
c1c534
@@ -5371,6 +5400,7 @@ virQEMUCapsCacheNew(const char *libDir,
c1c534
 
c1c534
     priv->runUid = runUid;
c1c534
     priv->runGid = runGid;
c1c534
+    priv->microcodeVersion = microcodeVersion;
c1c534
 
c1c534
  cleanup:
c1c534
     VIR_FREE(capsCacheDir);
c1c534
@@ -5848,3 +5878,11 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps,
c1c534
         return -1;
c1c534
     return 0;
c1c534
 }
c1c534
+
c1c534
+
c1c534
+void
c1c534
+virQEMUCapsSetMicrocodeVersion(virQEMUCapsPtr qemuCaps,
c1c534
+                               unsigned int microcodeVersion)
c1c534
+{
c1c534
+    qemuCaps->microcodeVersion = microcodeVersion;
c1c534
+}
c1c534
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
c1c534
index 0fb2a10a17..4b5d70fbb0 100644
c1c534
--- a/src/qemu/qemu_capabilities.h
c1c534
+++ b/src/qemu/qemu_capabilities.h
c1c534
@@ -520,8 +520,10 @@ void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
c1c534
                                     const char *machineType);
c1c534
 
c1c534
 virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
c1c534
-                                        const char *cacheDir,
c1c534
-                                        uid_t uid, gid_t gid);
c1c534
+                                    const char *cacheDir,
c1c534
+                                    uid_t uid,
c1c534
+                                    gid_t gid,
c1c534
+                                    unsigned int microcodeVersion);
c1c534
 virQEMUCapsPtr virQEMUCapsCacheLookup(virFileCachePtr cache,
c1c534
                                       const char *binary);
c1c534
 virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
c1c534
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
c1c534
index 219daa3629..98d163b920 100644
c1c534
--- a/src/qemu/qemu_capspriv.h
c1c534
+++ b/src/qemu/qemu_capspriv.h
c1c534
@@ -36,6 +36,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
c1c534
                                 const char *libDir,
c1c534
                                 uid_t runUid,
c1c534
                                 gid_t runGid,
c1c534
+                                unsigned int microcodeVersion,
c1c534
                                 bool qmpOnly);
c1c534
 
c1c534
 int virQEMUCapsLoadCache(virArch hostArch,
c1c534
@@ -102,4 +103,8 @@ int
c1c534
 virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
c1c534
                                   qemuMonitorPtr mon,
c1c534
                                   bool tcg);
c1c534
+
c1c534
+void
c1c534
+virQEMUCapsSetMicrocodeVersion(virQEMUCapsPtr qemuCaps,
c1c534
+                               unsigned int microcodeVersion);
c1c534
 #endif
c1c534
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
c1c534
index fa73fc30d6..0bc6eaa431 100644
c1c534
--- a/src/qemu/qemu_driver.c
c1c534
+++ b/src/qemu/qemu_driver.c
c1c534
@@ -633,6 +633,8 @@ qemuStateInitialize(bool privileged,
c1c534
     char *hugepagePath = NULL;
c1c534
     char *memoryBackingPath = NULL;
c1c534
     size_t i;
c1c534
+    virCPUDefPtr hostCPU = NULL;
c1c534
+    unsigned int microcodeVersion = 0;
c1c534
 
c1c534
     if (VIR_ALLOC(qemu_driver) < 0)
c1c534
         return -1;
c1c534
@@ -855,10 +857,15 @@ qemuStateInitialize(bool privileged,
c1c534
         run_gid = cfg->group;
c1c534
     }
c1c534
 
c1c534
+    if ((hostCPU = virCPUProbeHost(virArchFromHost())))
c1c534
+        microcodeVersion = hostCPU->microcodeVersion;
c1c534
+    virCPUDefFree(hostCPU);
c1c534
+
c1c534
     qemu_driver->qemuCapsCache = virQEMUCapsCacheNew(cfg->libDir,
c1c534
                                                      cfg->cacheDir,
c1c534
                                                      run_uid,
c1c534
-                                                     run_gid);
c1c534
+                                                     run_gid,
c1c534
+                                                     microcodeVersion);
c1c534
     if (!qemu_driver->qemuCapsCache)
c1c534
         goto error;
c1c534
 
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_1.2.2.x86_64.xml b/tests/qemucapabilitiesdata/caps_1.2.2.x86_64.xml
c1c534
index d560811ab7..3001d487c6 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_1.2.2.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_1.2.2.x86_64.xml
c1c534
@@ -112,6 +112,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>1002002</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>26900</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='qemu64'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_1.3.1.x86_64.xml b/tests/qemucapabilitiesdata/caps_1.3.1.x86_64.xml
c1c534
index 576475f7fa..283f30ef07 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_1.3.1.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_1.3.1.x86_64.xml
c1c534
@@ -130,6 +130,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>1003001</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>30198</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='qemu64'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_1.4.2.x86_64.xml b/tests/qemucapabilitiesdata/caps_1.4.2.x86_64.xml
c1c534
index 0c271d3e41..200069ae86 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_1.4.2.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_1.4.2.x86_64.xml
c1c534
@@ -131,6 +131,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>1004002</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>30915</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_1.5.3.x86_64.xml b/tests/qemucapabilitiesdata/caps_1.5.3.x86_64.xml
c1c534
index 5c667975bf..e02c0961cd 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_1.5.3.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_1.5.3.x86_64.xml
c1c534
@@ -143,6 +143,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>1005003</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>47019</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_1.6.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_1.6.0.x86_64.xml
c1c534
index 8ae07a91db..e3896685e9 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_1.6.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_1.6.0.x86_64.xml
c1c534
@@ -148,6 +148,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>1006000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>45248</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_1.7.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_1.7.0.x86_64.xml
c1c534
index 34bd6be1cd..5b4d1ea661 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_1.7.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_1.7.0.x86_64.xml
c1c534
@@ -150,6 +150,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>1007000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>50692</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml
c1c534
index 0d7c144ff7..200e57adac 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml
c1c534
@@ -166,6 +166,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2001001</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>59488</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
c1c534
index 09cce92067..d9ba077123 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml
c1c534
@@ -184,6 +184,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2010000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>383421</microcodeVersion>
c1c534
   <package> (v2.10.0)</package>
c1c534
   <arch>ppc64</arch>
c1c534
   <cpu type='kvm' name='default'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
c1c534
index 00fe1cffa7..d9cbbd8ccb 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
c1c534
@@ -146,6 +146,7 @@
c1c534
   <flag name='disk-share-rw'/>
c1c534
   <version>2010000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>304153</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>s390x</arch>
c1c534
   <hostCPU type='kvm' model='z14-base' migratability='no'>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
c1c534
index 2417251678..c7b9787142 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml
c1c534
@@ -229,6 +229,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2010000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>345185</microcodeVersion>
c1c534
   <package> (v2.10.0)</package>
c1c534
   <arch>x86_64</arch>
c1c534
   <hostCPU type='kvm' model='base' migratability='yes'>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
c1c534
index 5007523c1f..9b315aecf4 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
c1c534
@@ -191,6 +191,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2004000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>75653</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
c1c534
index a9ad292d01..3096eadf72 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
c1c534
@@ -197,6 +197,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2005000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>216775</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml b/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml
c1c534
index d3e2e18faa..4cdd894a97 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml
c1c534
@@ -176,6 +176,7 @@
c1c534
   <flag name='pl011'/>
c1c534
   <version>2006000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>228838</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>aarch64</arch>
c1c534
   <cpu type='kvm' name='pxa262'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml b/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml
c1c534
index bc86d03537..5655af7d3d 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml
c1c534
@@ -176,6 +176,7 @@
c1c534
   <flag name='pl011'/>
c1c534
   <version>2006000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>228838</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>aarch64</arch>
c1c534
   <cpu type='kvm' name='pxa262'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_2.6.0.ppc64.xml
c1c534
index 27d99bd937..31701bb40b 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.6.0.ppc64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.6.0.ppc64.xml
c1c534
@@ -171,6 +171,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2006000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>263602</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>ppc64</arch>
c1c534
   <cpu type='kvm' name='default'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
c1c534
index 97621612ab..6ae19ffd36 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
c1c534
@@ -207,6 +207,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2006000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>227579</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml b/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml
c1c534
index c2f310cd46..b6ec680d5c 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml
c1c534
@@ -138,6 +138,7 @@
c1c534
   <flag name='sclplmconsole'/>
c1c534
   <version>2007000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>217559</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>s390x</arch>
c1c534
   <cpu type='kvm' name='host'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
c1c534
index e4ea9452c5..294ac126e5 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
c1c534
@@ -211,6 +211,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2007000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>239276</microcodeVersion>
c1c534
   <package> (v2.7.0)</package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='Opteron_G5'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
c1c534
index f6e024dc61..d788ad206e 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
c1c534
@@ -140,6 +140,7 @@
c1c534
   <flag name='sclplmconsole'/>
c1c534
   <version>2007093</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>242460</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>s390x</arch>
c1c534
   <hostCPU type='kvm' model='zEC12.2-base' migratability='no'>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml
c1c534
index c6d3e21d5c..156563d99a 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml
c1c534
@@ -213,6 +213,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2008000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>255931</microcodeVersion>
c1c534
   <package> (v2.8.0)</package>
c1c534
   <arch>x86_64</arch>
c1c534
   <cpu type='kvm' name='host' usable='yes'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml
c1c534
index f5cf0ba932..aa0c833a0c 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml
c1c534
@@ -178,6 +178,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2009000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>347135</microcodeVersion>
c1c534
   <package> (v2.9.0)</package>
c1c534
   <arch>ppc64</arch>
c1c534
   <cpu type='kvm' name='default'/>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml b/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml
c1c534
index 5c4a02c8b1..ba809b6ae3 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml
c1c534
@@ -142,6 +142,7 @@
c1c534
   <flag name='disk-share-rw'/>
c1c534
   <version>2009000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>265878</microcodeVersion>
c1c534
   <package></package>
c1c534
   <arch>s390x</arch>
c1c534
   <hostCPU type='kvm' model='z13.2-base' migratability='no'>
c1c534
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
c1c534
index 82cc4e79f4..11f2508a04 100644
c1c534
--- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
c1c534
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
c1c534
@@ -225,6 +225,7 @@
c1c534
   <flag name='isa-serial'/>
c1c534
   <version>2009000</version>
c1c534
   <kvmVersion>0</kvmVersion>
c1c534
+  <microcodeVersion>321194</microcodeVersion>
c1c534
   <package> (v2.9.0)</package>
c1c534
   <arch>x86_64</arch>
c1c534
   <hostCPU type='kvm' model='base' migratability='yes'>
c1c534
diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c
c1c534
index 6e39866ebe..44b3b1fda5 100644
c1c534
--- a/tests/qemucapabilitiestest.c
c1c534
+++ b/tests/qemucapabilitiestest.c
c1c534
@@ -61,10 +61,16 @@ testQemuCaps(const void *opaque)
c1c534
                                   qemuMonitorTestGetMonitor(mon)) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
-    if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM) &&
c1c534
-        virQEMUCapsInitQMPMonitorTCG(capsActual,
c1c534
-                                     qemuMonitorTestGetMonitor(mon)) < 0)
c1c534
-        goto cleanup;
c1c534
+    if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM)) {
c1c534
+        if (virQEMUCapsInitQMPMonitorTCG(capsActual,
c1c534
+                                         qemuMonitorTestGetMonitor(mon)) < 0)
c1c534
+            goto cleanup;
c1c534
+
c1c534
+        /* Fill microcodeVersion with a "random" value which is the file
c1c534
+         * length to provide a reproducible number for testing.
c1c534
+         */
c1c534
+        virQEMUCapsSetMicrocodeVersion(capsActual, virFileLength(repliesFile, -1));
c1c534
+    }
c1c534
 
c1c534
     if (!(actual = virQEMUCapsFormatCache(capsActual)))
c1c534
         goto cleanup;
c1c534
diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c
c1c534
index 4b8d6229b4..a5f5a38b16 100644
c1c534
--- a/tests/qemucapsprobe.c
c1c534
+++ b/tests/qemucapsprobe.c
c1c534
@@ -72,7 +72,7 @@ main(int argc, char **argv)
c1c534
         return EXIT_FAILURE;
c1c534
 
c1c534
     if (!(caps = virQEMUCapsNewForBinaryInternal(VIR_ARCH_NONE, argv[1], "/tmp",
c1c534
-                                                 -1, -1, true)))
c1c534
+                                                 -1, -1, 0, true)))
c1c534
         return EXIT_FAILURE;
c1c534
 
c1c534
     virObjectUnref(caps);
c1c534
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
c1c534
index 2c7124bf26..f8182033fc 100644
c1c534
--- a/tests/testutilsqemu.c
c1c534
+++ b/tests/testutilsqemu.c
c1c534
@@ -603,7 +603,7 @@ int qemuTestDriverInit(virQEMUDriver *driver)
c1c534
 
c1c534
     /* Using /dev/null for libDir and cacheDir automatically produces errors
c1c534
      * upon attempt to use any of them */
c1c534
-    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0);
c1c534
+    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0, 0);
c1c534
     if (!driver->qemuCapsCache)
c1c534
         goto error;
c1c534
 
c1c534
-- 
c1c534
2.15.1
c1c534