99cbc7
From e5c98595ed558673ecd179b5c6204d981a6cdd2b Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <e5c98595ed558673ecd179b5c6204d981a6cdd2b@dist-git>
99cbc7
From: Jiri Denemark <jdenemar@redhat.com>
99cbc7
Date: Mon, 15 Apr 2019 15:49:01 +0200
99cbc7
Subject: [PATCH] qemu: Don't cache microcode version
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
My earlier commit be46f61326 was incomplete. It removed caching of
99cbc7
microcode version in the CPU driver, which means the capabilities XML
99cbc7
will see the correct microcode version. But it is also cached in the
99cbc7
QEMU capabilities cache where it is used to detect whether we need to
99cbc7
reprobe QEMU. By missing the second place, the original commit
99cbc7
be46f61326 made the situation even worse since libvirt would report
99cbc7
correct microcode version while still using the old host CPU model
99cbc7
(visible in domain capabilities XML).
99cbc7
99cbc7
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
(cherry picked from commit 673c62a3b7855a0685d8f116e227c402720b9ee9)
99cbc7
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1576369
99cbc7
99cbc7
Conflicts:
99cbc7
	src/qemu/qemu_capabilities.c
99cbc7
            - virQEMUCapsCacheLookupByArch refactoring (commits
99cbc7
              7948ad4129a and 1a3de67001c) are missing
99cbc7
99cbc7
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
99cbc7
Message-Id: <d277660601022095d263f57bf5349cd535ee4c9f.1555334286.git.jdenemar@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 src/qemu/qemu_capabilities.c | 12 ++++++++----
99cbc7
 src/qemu/qemu_capabilities.h |  3 +--
99cbc7
 src/qemu/qemu_driver.c       |  9 +--------
99cbc7
 tests/testutilsqemu.c        |  2 +-
99cbc7
 4 files changed, 11 insertions(+), 15 deletions(-)
99cbc7
99cbc7
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
99cbc7
index 8819452ff6..a27ea85824 100644
99cbc7
--- a/src/qemu/qemu_capabilities.c
99cbc7
+++ b/src/qemu/qemu_capabilities.c
99cbc7
@@ -4614,7 +4614,7 @@ virQEMUCapsNewData(const char *binary,
99cbc7
                                            priv->libDir,
99cbc7
                                            priv->runUid,
99cbc7
                                            priv->runGid,
99cbc7
-                                           priv->microcodeVersion,
99cbc7
+                                           virHostCPUGetMicrocodeVersion(),
99cbc7
                                            priv->kernelVersion);
99cbc7
 }
99cbc7
 
99cbc7
@@ -4697,8 +4697,7 @@ virFileCachePtr
99cbc7
 virQEMUCapsCacheNew(const char *libDir,
99cbc7
                     const char *cacheDir,
99cbc7
                     uid_t runUid,
99cbc7
-                    gid_t runGid,
99cbc7
-                    unsigned int microcodeVersion)
99cbc7
+                    gid_t runGid)
99cbc7
 {
99cbc7
     char *capsCacheDir = NULL;
99cbc7
     virFileCachePtr cache = NULL;
99cbc7
@@ -4722,7 +4721,6 @@ virQEMUCapsCacheNew(const char *libDir,
99cbc7
 
99cbc7
     priv->runUid = runUid;
99cbc7
     priv->runGid = runGid;
99cbc7
-    priv->microcodeVersion = microcodeVersion;
99cbc7
 
99cbc7
     if (uname(&uts) == 0 &&
99cbc7
         virAsprintf(&priv->kernelVersion, "%s %s", uts.release, uts.version) < 0)
99cbc7
@@ -4743,8 +4741,11 @@ virQEMUCapsPtr
99cbc7
 virQEMUCapsCacheLookup(virFileCachePtr cache,
99cbc7
                        const char *binary)
99cbc7
 {
99cbc7
+    virQEMUCapsCachePrivPtr priv = virFileCacheGetPriv(cache);
99cbc7
     virQEMUCapsPtr ret = NULL;
99cbc7
 
99cbc7
+    priv->microcodeVersion = virHostCPUGetMicrocodeVersion();
99cbc7
+
99cbc7
     ret = virFileCacheLookup(cache, binary);
99cbc7
 
99cbc7
     VIR_DEBUG("Returning caps %p for %s", ret, binary);
99cbc7
@@ -4790,10 +4791,13 @@ virQEMUCapsPtr
99cbc7
 virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
99cbc7
                              virArch arch)
99cbc7
 {
99cbc7
+    virQEMUCapsCachePrivPtr priv = virFileCacheGetPriv(cache);
99cbc7
     virQEMUCapsPtr ret = NULL;
99cbc7
     virArch target;
99cbc7
     struct virQEMUCapsSearchData data = { .arch = arch };
99cbc7
 
99cbc7
+    priv->microcodeVersion = virHostCPUGetMicrocodeVersion();
99cbc7
+
99cbc7
     ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
99cbc7
     if (!ret) {
99cbc7
         /* If the first attempt at finding capabilities has failed, try
99cbc7
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
99cbc7
index 6acd9fe825..25ad4218e0 100644
99cbc7
--- a/src/qemu/qemu_capabilities.h
99cbc7
+++ b/src/qemu/qemu_capabilities.h
99cbc7
@@ -572,8 +572,7 @@ void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
99cbc7
 virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
99cbc7
                                     const char *cacheDir,
99cbc7
                                     uid_t uid,
99cbc7
-                                    gid_t gid,
99cbc7
-                                    unsigned int microcodeVersion);
99cbc7
+                                    gid_t gid);
99cbc7
 virQEMUCapsPtr virQEMUCapsCacheLookup(virFileCachePtr cache,
99cbc7
                                       const char *binary);
99cbc7
 virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
99cbc7
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
99cbc7
index e11f57a56a..3b3281c13f 100644
99cbc7
--- a/src/qemu/qemu_driver.c
99cbc7
+++ b/src/qemu/qemu_driver.c
99cbc7
@@ -592,8 +592,6 @@ qemuStateInitialize(bool privileged,
99cbc7
     char *hugepagePath = NULL;
99cbc7
     char *memoryBackingPath = NULL;
99cbc7
     size_t i;
99cbc7
-    virCPUDefPtr hostCPU = NULL;
99cbc7
-    unsigned int microcodeVersion = 0;
99cbc7
 
99cbc7
     if (VIR_ALLOC(qemu_driver) < 0)
99cbc7
         return -1;
99cbc7
@@ -813,15 +811,10 @@ qemuStateInitialize(bool privileged,
99cbc7
         run_gid = cfg->group;
99cbc7
     }
99cbc7
 
99cbc7
-    if ((hostCPU = virCPUProbeHost(virArchFromHost())))
99cbc7
-        microcodeVersion = hostCPU->microcodeVersion;
99cbc7
-    virCPUDefFree(hostCPU);
99cbc7
-
99cbc7
     qemu_driver->qemuCapsCache = virQEMUCapsCacheNew(cfg->libDir,
99cbc7
                                                      cfg->cacheDir,
99cbc7
                                                      run_uid,
99cbc7
-                                                     run_gid,
99cbc7
-                                                     microcodeVersion);
99cbc7
+                                                     run_gid);
99cbc7
     if (!qemu_driver->qemuCapsCache)
99cbc7
         goto error;
99cbc7
 
99cbc7
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
99cbc7
index dc7e90b952..3e0b753549 100644
99cbc7
--- a/tests/testutilsqemu.c
99cbc7
+++ b/tests/testutilsqemu.c
99cbc7
@@ -617,7 +617,7 @@ int qemuTestDriverInit(virQEMUDriver *driver)
99cbc7
 
99cbc7
     /* Using /dev/null for libDir and cacheDir automatically produces errors
99cbc7
      * upon attempt to use any of them */
99cbc7
-    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0, 0);
99cbc7
+    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0);
99cbc7
     if (!driver->qemuCapsCache)
99cbc7
         goto error;
99cbc7
 
99cbc7
-- 
99cbc7
2.21.0
99cbc7