]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Separate partial CPU check into a function
authorJiri Denemark <jdenemar@redhat.com>
Thu, 10 Oct 2024 08:11:25 +0000 (10:11 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 23 Oct 2024 14:00:44 +0000 (16:00 +0200)
The new qemuDomainCheckCPU function is used as a replacement for
virCPUCompare to make sure all callers use the same comparison
algorithm. As a side effect qemuConnectCompareHypervisorCPU now properly
reports CPU compatibility for CPU model that are considered runnable by
QEMU even if our definition of the model disagrees.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c
src/qemu/qemu_process.c

index fda4439b0bd5469f5eb7ae917a3da712502c7e75..8ada3db115fe4fdf95497b8341343a8178a7df5a 100644 (file)
@@ -13223,3 +13223,43 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg,
 
     return ret;
 }
+
+
+/**
+ * qemuDomainCheckCPU:
+ * @arch: CPU architecture
+ * @virtType: domain type (KVM vs. TCG)
+ * @qemuCaps: QEMU capabilities
+ * @cpu: CPU definition to check against "host CPU"
+ * @compatCPU: type of CPU used for old style check
+ * @failIncompatible: return an error instead of VIR_CPU_COMPARE_INCOMPATIBLE
+ *
+ * Perform a "partial" check of the @cpu against a "host CPU". Old style check
+ * used with all existing CPU models uses cpu_map definition of the model in
+ * @cpu and compares it to the host CPU fetched @qemuCaps according to
+ * @compatCPU.
+ *
+ * Returns VIR_CPU_COMPARE_ERROR on error, VIR_CPU_COMPARE_INCOMPATIBLE when
+ * the two CPUs are incompatible, VIR_CPU_COMPARE_IDENTICAL when the two CPUs
+ * are identical, VIR_CPU_COMPARE_SUPERSET when the @cpu CPU is a superset of
+ * the @host CPU. If @failIncompatible is true, the function will return
+ * VIR_CPU_COMPARE_ERROR (and set VIR_ERR_CPU_INCOMPATIBLE error) when the
+ * two CPUs are incompatible.
+ */
+virCPUCompareResult
+qemuDomainCheckCPU(virArch arch,
+                   virDomainVirtType virtType,
+                   virQEMUCaps *qemuCaps,
+                   virCPUDef *cpu,
+                   virQEMUCapsHostCPUType compatCPU,
+                   bool failIncompatible)
+{
+    virCPUDef *host;
+
+    if (virQEMUCapsIsCPUUsable(qemuCaps, virtType, cpu))
+        return VIR_CPU_COMPARE_SUPERSET;
+
+    host = virQEMUCapsGetHostModel(qemuCaps, virtType, compatCPU);
+
+    return virCPUCompare(arch, host, cpu, failIncompatible);
+}
index c29ecdf23858d6528fbce48e6473c9c20cd89a12..a19314b48b0305a4ee381e9556ba89e7ad400094 100644 (file)
@@ -1176,3 +1176,10 @@ int
 qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg,
                                 virDomainObj *vm,
                                 virStorageSource *src);
+virCPUCompareResult
+qemuDomainCheckCPU(virArch arch,
+                   virDomainVirtType virtType,
+                   virQEMUCaps *qemuCaps,
+                   virCPUDef *cpu,
+                   virQEMUCapsHostCPUType compatCPU,
+                   bool failIncompatible);
index 36ec0c05905f8db2dd046ceae11a68d6e367cc4b..72211da137df4007d8142cf11730f3054a3979cc 100644 (file)
@@ -11641,8 +11641,11 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
                                 validateXML) < 0)
         return VIR_CPU_COMPARE_ERROR;
 
-    if (ARCH_IS_X86(arch))
-        return virCPUCompare(arch, hvCPU, cpu, failIncompatible);
+    if (ARCH_IS_X86(arch)) {
+        return qemuDomainCheckCPU(arch, virttype, qemuCaps, cpu,
+                                  VIR_QEMU_CAPS_HOST_CPU_REPORTED,
+                                  failIncompatible);
+    }
 
     if (ARCH_IS_S390(arch) &&
         virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON)) {
index 72fc750d282f5b67f633a9144552e47fadec27a5..0815bffe3c1c6d879ca67c0dae8069ce50feb3e9 100644 (file)
@@ -6268,11 +6268,8 @@ qemuProcessUpdateGuestCPU(virDomainDef *def,
         virCPUFeaturePolicy removedPolicy = VIR_CPU_FEATURE_DISABLE;
 
         if (def->cpu->check == VIR_CPU_CHECK_PARTIAL &&
-            !virQEMUCapsIsCPUUsable(qemuCaps, def->virtType, def->cpu) &&
-            virCPUCompare(hostarch,
-                          virQEMUCapsGetHostModel(qemuCaps, def->virtType,
-                                                  VIR_QEMU_CAPS_HOST_CPU_FULL),
-                          def->cpu, true) < 0)
+            qemuDomainCheckCPU(hostarch, def->virtType, qemuCaps, def->cpu,
+                               VIR_QEMU_CAPS_HOST_CPU_FULL, true) < 0)
             return -1;
 
         /* When starting a fresh domain we disable all features removed from