]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Invalidate capabilities cache on host cpuid mismatch
authorTim Wiederhake <twiederh@redhat.com>
Mon, 2 Aug 2021 14:44:30 +0000 (16:44 +0200)
committerTim Wiederhake <twiederh@redhat.com>
Fri, 5 Nov 2021 16:12:25 +0000 (17:12 +0100)
See https://bugzilla.redhat.com/show_bug.cgi?id=1953389.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capspriv.h
tests/qemucapsprobe.c

index 5fa3111201ad7fd443644ca3ae0041450d02b573..67fae46a34c019eb2b26b1b5ca406160297fb846 100644 (file)
@@ -4907,6 +4907,13 @@ virQEMUCapsIsValid(void *data,
             return false;
         }
 
+        if (virCPUDataIsIdentical(priv->cpuData, qemuCaps->cpuData) !=
+            VIR_CPU_COMPARE_IDENTICAL) {
+            VIR_DEBUG("Outdated capabilities for '%s': host cpuid changed",
+                      qemuCaps->binary);
+            return false;
+        }
+
         kvmSupportsNesting = virQEMUCapsKVMSupportsNesting();
         if (kvmSupportsNesting != qemuCaps->kvmSupportsNesting) {
             VIR_DEBUG("Outdated capabilities for '%s': kvm kernel nested "
@@ -5387,7 +5394,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
                                 gid_t runGid,
                                 const char *hostCPUSignature,
                                 unsigned int microcodeVersion,
-                                const char *kernelVersion)
+                                const char *kernelVersion,
+                                virCPUData* cpuData)
 {
     g_autoptr(virQEMUCaps) qemuCaps = NULL;
     struct stat sb;
@@ -5435,7 +5443,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
         qemuCaps->hostCPUSignature = g_strdup(hostCPUSignature);
         qemuCaps->microcodeVersion = microcodeVersion;
-        qemuCaps->cpuData = NULL;
+        qemuCaps->cpuData = virCPUDataNewCopy(cpuData);
 
         qemuCaps->kernelVersion = g_strdup(kernelVersion);
 
@@ -5460,7 +5468,8 @@ virQEMUCapsNewData(const char *binary,
                                            priv->runGid,
                                            priv->hostCPUSignature,
                                            virHostCPUGetMicrocodeVersion(priv->hostArch),
-                                           priv->kernelVersion);
+                                           priv->kernelVersion,
+                                           priv->cpuData);
 }
 
 
index a54a22685e0df251244ae90f6c1317467d3d5479..f4f4a99d32d4d871fdda4e300b8738e5a99c0fc4 100644 (file)
@@ -35,7 +35,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
                                 gid_t runGid,
                                 const char *hostCPUSignature,
                                 unsigned int microcodeVersion,
-                                const char *kernelVersion);
+                                const char *kernelVersion,
+                                virCPUData* cpuData);
 
 int virQEMUCapsLoadCache(virArch hostArch,
                          virQEMUCaps *qemuCaps,
index bfa8ae8db731e393f8f82c4791339d9b08b8e08b..76c18f0dcdd5b6ad7c71724f0d9dcbeecd43aa16 100644 (file)
@@ -79,7 +79,7 @@ main(int argc, char **argv)
         return EXIT_FAILURE;
 
     if (!(caps = virQEMUCapsNewForBinaryInternal(VIR_ARCH_NONE, argv[1], "/tmp",
-                                                 -1, -1, NULL, 0, NULL)))
+                                                 -1, -1, NULL, 0, NULL, NULL)))
         return EXIT_FAILURE;
 
     host = virArchFromHost();