]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_capabilities: Translate CPU blockers
authorJiri Denemark <jdenemar@redhat.com>
Fri, 30 Sep 2022 15:59:06 +0000 (17:59 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 10 Oct 2022 12:31:43 +0000 (14:31 +0200)
Since commit "cpu_x86: Disable blockers from unusable CPU models"
(v3.8.0-99-g9c9620af1d) we explicitly disable CPU features reported by
QEMU as usability blockers for a particular CPU model when creating
baseline or host-model CPU definition. When QEMU changed canonical names
for some features (mostly those with '_' in their names), we forgot to
translate the blocker lists to names used by libvirt and the renamed
features would no longer be explicitly disabled in the created CPU model
even if they were reported as blockers by QEMU.

For example, on a host where EPYC CPU model has the following blockers

    <blocker name='sha-ni'/>
    <blocker name='mmxext'/>
    <blocker name='fxsr-opt'/>
    <blocker name='cr8legacy'/>
    <blocker name='sse4a'/>
    <blocker name='misalignsse'/>
    <blocker name='osvw'/>

we would fail to disable 'fxsr-opt':

    <cpu mode='custom' match='exact'>
      <model fallback='forbid'>EPYC</model>
      <feature policy='disable' name='sha-ni'/>
      <feature policy='disable' name='mmxext'/>
      <feature policy='disable' name='cr8legacy'/>
      <feature policy='disable' name='sse4a'/>
      <feature policy='disable' name='misalignsse'/>
      <feature policy='disable' name='osvw'/>
      <feature policy='disable' name='monitor'/>
    </cpu>

The 'monitor' feature is disabled even though it is not reported as a
blocker by QEMU because libvirt's definition of EPYC includes the
feature while it is missing in EPYC definition in QEMU.

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

index ccd274b80dea38b723ca51910c8326a1e56da240..6f3ff7f43f67f5bda85cbc15138ba139e6cc626b 100644 (file)
@@ -2936,6 +2936,17 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitor *mon,
         }
     }
 
+    for (i = 0; i < defs->ncpus; i++) {
+        qemuMonitorCPUDefInfo *cpu = &defs->cpus[i];
+        char **blocker;
+
+        if (!cpu->blockers)
+            continue;
+
+        for (blocker = cpu->blockers; *blocker; blocker++)
+            virQEMUCapsCPUFeatureFromQEMUInPlace(arch, blocker);
+    }
+
     *cpuDefs = g_steal_pointer(&defs);
     return 0;
 }
@@ -3483,6 +3494,19 @@ virQEMUCapsCPUFeatureFromQEMU(virArch arch,
 }
 
 
+void
+virQEMUCapsCPUFeatureFromQEMUInPlace(virArch arch,
+                                     char **feature)
+{
+    const char *tmp = virQEMUCapsCPUFeatureFromQEMU(arch, *feature);
+
+    if (tmp != *feature) {
+        VIR_FREE(*feature);
+        *feature = g_strdup(tmp);
+    }
+}
+
+
 /**
  * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
  *          1 when the caller should fall back to using virCaps *->host.cpu,
@@ -3907,7 +3931,8 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
 
 
 static int
-virQEMUCapsLoadCPUModels(virQEMUCapsAccel *caps,
+virQEMUCapsLoadCPUModels(virArch arch,
+                         virQEMUCapsAccel *caps,
                          xmlXPathContextPtr ctxt,
                          const char *typeStr)
 {
@@ -3978,6 +4003,8 @@ virQEMUCapsLoadCPUModels(virQEMUCapsAccel *caps,
                                      "capabilities cache"));
                     return -1;
                 }
+
+                virQEMUCapsCPUFeatureFromQEMUInPlace(arch, &cpu->blockers[j]);
             }
         }
 
@@ -4072,7 +4099,7 @@ virQEMUCapsLoadAccel(virQEMUCaps *qemuCaps,
     if (virQEMUCapsLoadHostCPUModelInfo(caps, ctxt, typeStr) < 0)
         return -1;
 
-    if (virQEMUCapsLoadCPUModels(caps, ctxt, typeStr) < 0)
+    if (virQEMUCapsLoadCPUModels(qemuCaps->arch, caps, ctxt, typeStr) < 0)
         return -1;
 
     if (virQEMUCapsLoadMachines(caps, ctxt, typeStr) < 0)
@@ -4534,7 +4561,8 @@ virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsAccel *caps,
 
 
 static void
-virQEMUCapsFormatCPUModels(virQEMUCapsAccel *caps,
+virQEMUCapsFormatCPUModels(virArch arch,
+                           virQEMUCapsAccel *caps,
                            virBuffer *buf,
                            const char *typeStr)
 {
@@ -4563,8 +4591,10 @@ virQEMUCapsFormatCPUModels(virQEMUCapsAccel *caps,
             virBufferAddLit(buf, ">\n");
             virBufferAdjustIndent(buf, 2);
 
-            for (j = 0; cpu->blockers[j]; j++)
-                virBufferAsprintf(buf, "<blocker name='%s'/>\n", cpu->blockers[j]);
+            for (j = 0; cpu->blockers[j]; j++) {
+                virBufferAsprintf(buf, "<blocker name='%s'/>\n",
+                                  virQEMUCapsCPUFeatureToQEMU(arch, cpu->blockers[j]));
+            }
 
             virBufferAdjustIndent(buf, -2);
             virBufferAddLit(buf, "</cpu>\n");
@@ -4616,7 +4646,7 @@ virQEMUCapsFormatAccel(virQEMUCaps *qemuCaps,
     const char *typeStr = virQEMUCapsAccelStr(type);
 
     virQEMUCapsFormatHostCPUModelInfo(caps, buf, typeStr);
-    virQEMUCapsFormatCPUModels(caps, buf, typeStr);
+    virQEMUCapsFormatCPUModels(qemuCaps->arch, caps, buf, typeStr);
     virQEMUCapsFormatMachines(caps, buf, typeStr);
 
 }
index 904ee54f60f634ede5cc21cbe69c75c7fbb97836..4b2782c4622ee6dfb30197ed0f88d16a47271f97 100644 (file)
@@ -845,6 +845,10 @@ const char *
 virQEMUCapsCPUFeatureFromQEMU(virArch arch,
                               const char *feature);
 
+void
+virQEMUCapsCPUFeatureFromQEMUInPlace(virArch arch,
+                                     char **feature);
+
 virSEVCapability *
 virQEMUCapsGetSEVCapabilities(virQEMUCaps *qemuCaps);