]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_command.c: move CPU mode check to qemu_validate.c
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Sat, 10 Oct 2020 14:39:20 +0000 (11:39 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Thu, 15 Oct 2020 13:54:33 +0000 (10:54 -0300)
All but VIR_CPU_MODE_HOST_MODEL were moved. 'host_model' mode
has nuances that forbid the verification to be moved to parse
time.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_command.c
src/qemu/qemu_validate.c
tests/qemuxml2argvtest.c

index 87d76827e8ff14a018f1dd984cb5bcd57c7fffea..34d57606f0150920d87b9cdc7349010c2d990628 100644 (file)
@@ -6243,13 +6243,6 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
 
         if (def->os.arch == VIR_ARCH_ARMV7L &&
             driver->hostarch == VIR_ARCH_AARCH64) {
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("QEMU binary does not support CPU "
-                                 "host-passthrough for armv7l on "
-                                 "aarch64 host"));
-                return -1;
-            }
             virBufferAddLit(buf, ",aarch64=off");
         }
 
@@ -6257,19 +6250,16 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MIGRATABLE)) {
                 virBufferAsprintf(buf, ",migratable=%s",
                                   virTristateSwitchTypeToString(cpu->migratable));
-            } else if (ARCH_IS_X86(def->os.arch) &&
-                       cpu->migratable == VIR_TRISTATE_SWITCH_OFF) {
-                /* This is the default on x86 */
-            } else {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("Migratable attribute for host-passthrough "
-                                 "CPU is not supported by QEMU binary"));
-                return -1;
             }
         }
         break;
 
     case VIR_CPU_MODE_HOST_MODEL:
+        /* HOST_MODEL is a valid CPU mode for domain XMLs of all archs, meaning
+         * that we can't move this validation to parse time. By the time we reach
+         * this point, all non-PPC64 archs must have translated the CPU model to
+         * something else and set the CPU mode to MODE_CUSTOM.
+         */
         if (ARCH_IS_PPC64(def->os.arch)) {
             virBufferAddLit(buf, "host");
             if (cpu->model &&
index 4a7a25ae8e5c20b9da9a9f92c6a5385bc27ac0b9..dafef84bd7a9aaee2858ec947cb768fd8809fed3 100644 (file)
@@ -352,6 +352,59 @@ qemuValidateDomainDefFeatures(const virDomainDef *def,
 }
 
 
+static int
+qemuValidateDomainDefCpu(virQEMUDriverPtr driver,
+                         const virDomainDef *def,
+                         virQEMUCapsPtr qemuCaps)
+{
+    virCPUDefPtr cpu = def->cpu;
+
+    if (!cpu)
+        return 0;
+
+    if (!cpu->model && cpu->mode == VIR_CPU_MODE_CUSTOM)
+        return 0;
+
+    switch ((virCPUMode) cpu->mode) {
+    case VIR_CPU_MODE_HOST_PASSTHROUGH:
+        if (def->os.arch == VIR_ARCH_ARMV7L &&
+            driver->hostarch == VIR_ARCH_AARCH64) {
+            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("QEMU binary does not support CPU "
+                                 "host-passthrough for armv7l on "
+                                 "aarch64 host"));
+                return -1;
+            }
+        }
+
+        if (cpu->migratable &&
+            cpu->migratable != VIR_TRISTATE_SWITCH_OFF &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MIGRATABLE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Migratable attribute for host-passthrough "
+                             "CPU is not supported by QEMU binary"));
+            return -1;
+        }
+        break;
+
+    case VIR_CPU_MODE_HOST_MODEL:
+        /* qemu_command.c will error out if cpu->mode is HOST_MODEL for
+         * every arch but PPC64. However, we can't move this validation
+         * here because non-PPC64 archs will translate HOST_MODEL to
+         * something else during domain start, changing cpu->mode to
+         * CUSTOM.
+         */
+        break;
+    case VIR_CPU_MODE_CUSTOM:
+    case VIR_CPU_MODE_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
 static int
 qemuValidateDomainDefClockTimers(const virDomainDef *def,
                                  virQEMUCapsPtr qemuCaps)
@@ -935,6 +988,9 @@ qemuValidateDomainDef(const virDomainDef *def,
         }
     }
 
+    if (qemuValidateDomainDefCpu(driver, def, qemuCaps) < 0)
+        return -1;
+
     if (qemuDomainDefValidateMemoryHotplug(def, qemuCaps, NULL) < 0)
         return -1;
 
index 40ce346a73b55769a4cacc10fe37762182c0215f..67e29ba08575bb6cea8461fec37853a627fdf23d 100644 (file)
@@ -2892,9 +2892,9 @@ mymain(void)
             QEMU_CAPS_DEVICE_VIRTIO_MMIO,
             QEMU_CAPS_DEVICE_PL011,
             QEMU_CAPS_KVM, QEMU_CAPS_CPU_AARCH64_OFF);
-    DO_TEST_FAILURE("aarch64-kvm-32-on-64",
-            QEMU_CAPS_DEVICE_VIRTIO_MMIO,
-            QEMU_CAPS_KVM);
+    DO_TEST_PARSE_ERROR("aarch64-kvm-32-on-64",
+                        QEMU_CAPS_DEVICE_VIRTIO_MMIO,
+                        QEMU_CAPS_KVM);
     DO_TEST("aarch64-pci-serial",
             QEMU_CAPS_DEVICE_PCI_SERIAL,
             QEMU_CAPS_CHARDEV_LOGFILE,