]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Do not set default CPU for archs without CPU driver
authorJiri Denemark <jdenemar@redhat.com>
Tue, 25 Feb 2020 15:05:06 +0000 (16:05 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 26 Feb 2020 11:16:32 +0000 (12:16 +0100)
Whenever there is a guest CPU configured in domain XML, we will call
some CPU driver APIs to validate the CPU definition and check its
compatibility with the hypervisor. Thus domains with guest CPU
specification can only be started if the guest architecture is supported
by the CPU driver. But we would add a default CPU to any domain as long
as QEMU reports it causing failures to start any domain on affected
architectures.

https://bugzilla.redhat.com/show_bug.cgi?id=1805755

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/cpu/cpu.c
src/cpu/cpu.h
src/libvirt_private.syms
src/qemu/qemu_domain.c

index ae3a0acc10e0d2b39f939522249521cd9b5af227..6d6191fe4e5fd8f65a42701e39a7a22a42d42c5b 100644 (file)
@@ -1096,3 +1096,27 @@ virCPUDataAddFeature(virCPUDataPtr cpuData,
 
     return driver->dataAddFeature(cpuData, name);
 }
+
+
+/**
+ * virCPUArchIsSupported:
+ *
+ * @arch: CPU architecture
+ *
+ * Returns true if the architecture is supported by any CPU driver.
+ */
+bool
+virCPUArchIsSupported(virArch arch)
+{
+    size_t i;
+    size_t j;
+
+    for (i = 0; i < G_N_ELEMENTS(drivers); i++) {
+        for (j = 0; j < drivers[i]->narch; j++) {
+            if (arch == drivers[i]->arch[j])
+                return true;
+        }
+    }
+
+    return false;
+}
index 2e8b8923ae23784b900c372c59c67847c974802a..f779d2be176e10feca3e2442d44d91a59913d729 100644 (file)
@@ -265,6 +265,9 @@ int
 virCPUDataAddFeature(virCPUDataPtr cpuData,
                      const char *name);
 
+bool
+virCPUArchIsSupported(virArch arch);
+
 /* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
  * have no real-life usage
  */
index 3fc8d7de3fcf1a8cf85e94d9010f83c1856d5028..de0c7a313386c16d252071b7c010f20fd0cf8f13 100644 (file)
@@ -1310,6 +1310,7 @@ virStoragePoolObjVolumeListExport;
 # cpu/cpu.h
 cpuDecode;
 cpuEncode;
+virCPUArchIsSupported;
 virCPUBaseline;
 virCPUCheckFeature;
 virCPUCompare;
index a28b51c10e354b896f49b765e119af24a11f716c..3dfa71650db1a1e5f5b91d62e29a3e55dd77ee23 100644 (file)
@@ -4576,6 +4576,9 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
          def->cpu->model))
         return 0;
 
+    if (!virCPUArchIsSupported(def->os.arch))
+        return 0;
+
     /* Default CPU model info from QEMU is usable for TCG only except for
      * x86, s390, and ppc64. */
     if (!ARCH_IS_X86(def->os.arch) &&