]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Filter CPU features returned by qemuConnectBaselineCPU
authorJiri Denemark <jdenemar@redhat.com>
Wed, 13 Sep 2017 15:28:48 +0000 (17:28 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 18 Sep 2017 08:40:12 +0000 (10:40 +0200)
The host CPU definitions reported in the capabilities XML may contain
CPU features unknown to QEMU, but the result of virConnectBaselineCPU is
supposed to be directly usable as a guest CPU definition and thus it
should only contain features QEMU knows about.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_driver.c

index e92c114f3ed1bd65edaba10b0dd60ad15889a65c..e1a0dd553ef60f59fc0011b6a002744843ddaedf 100644 (file)
@@ -12990,6 +12990,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
                        unsigned int flags)
 {
     virCPUDefPtr *cpus = NULL;
+    virCPUDefPtr baseline = NULL;
     virCPUDefPtr cpu = NULL;
     char *cpustr = NULL;
 
@@ -13002,8 +13003,16 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
         goto cleanup;
 
-    if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0,
-                            !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
+    if (!(baseline = cpuBaseline(cpus, ncpus, NULL, 0,
+                                 !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
+        goto cleanup;
+
+    if (!(cpu = virCPUDefCopyWithoutModel(baseline)))
+        goto cleanup;
+
+    if (virCPUDefCopyModelFilter(cpu, baseline, false,
+                                 virQEMUCapsCPUFilterFeatures,
+                                 &cpus[0]->arch) < 0)
         goto cleanup;
 
     if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
@@ -13014,6 +13023,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
 
  cleanup:
     virCPUDefListFree(cpus);
+    virCPUDefFree(baseline);
     virCPUDefFree(cpu);
 
     return cpustr;