]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Introduce migratable attribute for the <cpu> element
authorJiri Denemark <jdenemar@redhat.com>
Tue, 2 Jun 2020 10:29:57 +0000 (12:29 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 9 Jun 2020 18:32:50 +0000 (20:32 +0200)
The attribute is only allowed for host-passthrough CPUs and it can be
used to request only migratable or all supported features to be enabled
in the virtual CPU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/cpu_conf.c
src/conf/cpu_conf.h

index 33cec1e6dd9f75e187ff7e08e306949a42b18e9c..6ebf19ae57f16895eb4893f1d89aee55851da15c 100644 (file)
 ...</pre>
 
 <pre>
-&lt;cpu mode='host-passthrough'&gt;
+&lt;cpu mode='host-passthrough' migratable='off'&gt;
   &lt;cache mode='passthrough'/&gt;
   &lt;feature policy='disable' name='lahf_lm'/&gt;
 ...</pre>
           using host-passthrough is dangerous if the source and destination hosts
           are not identical in both hardware, QEMU version, microcode version
           and configuration. If such a migration is attempted then the guest may
-          hang or crash upon resuming execution on the destination host.</dd>
+          hang or crash upon resuming execution on the destination host.
+          Depending on hypervisor version the virtual CPU may or may not
+          contain features which may block migration even to an identical host.
+          <span class="since">Since 6.5.0</span> optional
+          <code>migratable</code> attribute may be used to explicitly request
+          such features to be removed from (<code>on</code>) or kept in
+          (<code>off</code>) the virtual CPU. This attribute does not make
+          migration to another host safer: even with
+          <code>migratable='on'</code> migration will be dangerous unless both
+          hosts are identical as described above.
+        </dd>
         </dl>
 
         Both <code>host-model</code> and <code>host-passthrough</code> modes
index 6727cd743b7eb13177627d75955a591264a424c5..19242a9a32bf9a2c95562f4eb1063b6b260ba525 100644 (file)
       <optional>
         <ref name="cpuCheck"/>
       </optional>
+      <optional>
+        <attribute name="migratable">
+          <ref name="virOnOff"/>
+        </attribute>
+      </optional>
       <interleave>
         <optional>
           <ref name="cpuModel"/>
index 25648a946c3099b6434d5df814ffc8fa31846b62..b40737e407563f0968e69ce1839bb75bc642a38c 100644 (file)
@@ -243,6 +243,7 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu)
     copy->cores = cpu->cores;
     copy->threads = cpu->threads;
     copy->arch = cpu->arch;
+    copy->migratable = cpu->migratable;
 
     if (cpu->cache) {
         if (VIR_ALLOC(copy->cache) < 0)
@@ -333,6 +334,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
     g_autofree char *fallback = NULL;
     g_autofree char *vendor_id = NULL;
     g_autofree char *tscScaling = NULL;
+    g_autofree char *migratable = NULL;
     virHostCPUTscInfoPtr tsc = NULL;
 
     *cpu = NULL;
@@ -386,6 +388,26 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
             def->mode = VIR_CPU_MODE_CUSTOM;
     }
 
+    if ((migratable = virXMLPropString(ctxt->node, "migratable"))) {
+        int val;
+
+        if (def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Attribute migratable is only allowed for "
+                             "host-passthrough CPU"));
+            return -1;
+        }
+
+        if ((val = virTristateSwitchTypeFromString(migratable)) < 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Invalid value in migratable attribute: '%s'"),
+                           migratable);
+            return -1;
+        }
+
+        def->migratable = val;
+    }
+
     if (def->type == VIR_CPU_TYPE_GUEST) {
         g_autofree char *match = virXMLPropString(ctxt->node, "match");
         g_autofree char *check = NULL;
@@ -698,6 +720,11 @@ virCPUDefFormatBufFull(virBufferPtr buf,
             virBufferAsprintf(&attributeBuf, " check='%s'",
                               virCPUCheckTypeToString(def->check));
         }
+
+        if (def->mode == VIR_CPU_MODE_HOST_PASSTHROUGH && def->migratable) {
+            virBufferAsprintf(&attributeBuf, " migratable='%s'",
+                              virTristateSwitchTypeToString(def->migratable));
+        }
     }
 
     /* Format children */
index a95d56d017f45e642441628d7360f578f9c26f07..24c51e3a639cdd1c685a48556da2e5c82f06ef84 100644 (file)
@@ -141,6 +141,7 @@ struct _virCPUDef {
     virCPUFeatureDefPtr features;
     virCPUCacheDefPtr cache;
     virHostCPUTscInfoPtr tsc;
+    virTristateSwitch migratable; /* for host-passthrough mode */
 };
 
 virCPUDefPtr virCPUDefNew(void);