File b7d6648d-conf-add-e820-host.patch of Package libvirt.22292

commit b7d6648d436fe0a99d4faf0f99c88a27a7bfea33
Author: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Date:   Tue Apr 14 04:37:04 2020 +0200

    conf: add xen specific feature: e820_host
    
    e820_host is a Xen-specific option, only available for PV domains, that
    provides the domain a virtual e820 memory map based on the host one. It
    is enabled with a new Xen hypervisor feature, e.g.
    
      <features>
        <xen>
          <e820_host state='on'/>
        </xen>
      </features>
    
    e820_host is required when using PCI passthrough and is generally
    considered safe for any PV kernel. e820_host is silently ignored if set
    in HVM domain configuration. See xl.cfg(5) man page in the Xen
    documentation for more details.
    
    Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
    Reviewed-by: Jim Fehlig <jfehlig@suse.com>

Index: libvirt-5.1.0/docs/formatdomain.html.in
===================================================================
--- libvirt-5.1.0.orig/docs/formatdomain.html.in
+++ libvirt-5.1.0/docs/formatdomain.html.in
@@ -2015,6 +2015,9 @@
   &lt;kvm&gt;
     &lt;hidden state='on'/&gt;
   &lt;/kvm&gt;
+  &lt;xen&gt;
+    &lt;e820_host state='on'/&gt;
+  &lt;/xen&gt;
   &lt;pvspinlock state='on'/&gt;
   &lt;gic version='2'/&gt;
   &lt;ioapic driver='qemu'/&gt;
@@ -2188,6 +2191,23 @@
         </tr>
       </table>
       </dd>
+      <dt><code>xen</code></dt>
+      <dd>Various features to change the behavior of the Xen hypervisor.
+      <table class="top_table">
+        <tr>
+          <th>Feature</th>
+          <th>Description</th>
+          <th>Value</th>
+          <th>Since</th>
+        </tr>
+        <tr>
+          <td>e820_host</td>
+          <td>Expose the host e820 to the guest (PV only)</td>
+          <td>on, off</td>
+          <td><span class="since">6.3.0</span></td>
+        </tr>
+      </table>
+      </dd>
       <dt><code>pmu</code></dt>
       <dd>Depending on the <code>state</code> attribute (values <code>on</code>,
         <code>off</code>, default <code>on</code>) enable or disable the
Index: libvirt-5.1.0/docs/schemas/domaincommon.rng
===================================================================
--- libvirt-5.1.0.orig/docs/schemas/domaincommon.rng
+++ libvirt-5.1.0/docs/schemas/domaincommon.rng
@@ -4935,6 +4935,9 @@
             <ref name="kvm"/>
           </optional>
           <optional>
+            <ref name="xen"/>
+          </optional>
+          <optional>
             <element name="privnet">
               <empty/>
             </element>
@@ -5869,6 +5872,19 @@
             <ref name="featurestate"/>
           </element>
         </optional>
+      </interleave>
+    </element>
+  </define>
+
+  <!-- Optional Xen features -->
+  <define name="xen">
+    <element name="xen">
+      <interleave>
+        <optional>
+          <element name="e820_host">
+            <ref name="featurestate"/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
Index: libvirt-5.1.0/src/conf/domain_conf.c
===================================================================
--- libvirt-5.1.0.orig/src/conf/domain_conf.c
+++ libvirt-5.1.0/src/conf/domain_conf.c
@@ -158,6 +158,7 @@ VIR_ENUM_IMPL(virDomainFeature, VIR_DOMA
               "htm",
               "nested-hv",
               "msrs",
+              "xen",
 );
 
 VIR_ENUM_IMPL(virDomainCapabilitiesPolicy, VIR_DOMAIN_CAPABILITIES_POLICY_LAST,
@@ -187,6 +188,10 @@ VIR_ENUM_IMPL(virDomainKVM, VIR_DOMAIN_K
               "hidden",
 );
 
+VIR_ENUM_IMPL(virDomainXen, VIR_DOMAIN_XEN_LAST,
+              "e820_host"
+);
+
 VIR_ENUM_IMPL(virDomainMsrsUnknown, VIR_DOMAIN_MSRS_UNKNOWN_LAST,
               "ignore",
               "fault",
@@ -20383,6 +20388,7 @@ virDomainDefParseXML(xmlDocPtr xml,
         case VIR_DOMAIN_FEATURE_HYPERV:
         case VIR_DOMAIN_FEATURE_KVM:
         case VIR_DOMAIN_FEATURE_MSRS:
+        case VIR_DOMAIN_FEATURE_XEN:
             def->features[val] = VIR_TRISTATE_SWITCH_ON;
             break;
 
@@ -20658,6 +20664,51 @@ virDomainDefParseXML(xmlDocPtr xml,
         VIR_FREE(nodes);
     }
 
+    if (def->features[VIR_DOMAIN_FEATURE_XEN] == VIR_TRISTATE_SWITCH_ON) {
+        int feature;
+        int value;
+        if ((n = virXPathNodeSet("./features/xen/*", ctxt, &nodes)) < 0)
+            goto error;
+
+        for (i = 0; i < n; i++) {
+            feature = virDomainXenTypeFromString((const char *)nodes[i]->name);
+            if (feature < 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unsupported Xen feature: %s"),
+                               nodes[i]->name);
+                goto error;
+            }
+
+            switch ((virDomainXen) feature) {
+                case VIR_DOMAIN_XEN_E820_HOST:
+                    if (!(tmp = virXMLPropString(nodes[i], "state"))) {
+                        virReportError(VIR_ERR_XML_ERROR,
+                                       _("missing 'state' attribute for "
+                                         "Xen feature '%s'"),
+                                       nodes[i]->name);
+                        goto error;
+                    }
+
+                    if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
+                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                       _("invalid value of state argument "
+                                         "for Xen feature '%s'"),
+                                       nodes[i]->name);
+                        goto error;
+                    }
+
+                    VIR_FREE(tmp);
+                    def->xen_features[feature] = value;
+                    break;
+
+                /* coverity[dead_error_begin] */
+                case VIR_DOMAIN_XEN_LAST:
+                    break;
+            }
+        }
+        VIR_FREE(nodes);
+    }
+
     if (def->features[VIR_DOMAIN_FEATURE_SMM] == VIR_TRISTATE_SWITCH_ON) {
         int rv = virDomainParseScaledValue("string(./features/smm/tseg)",
                                            "string(./features/smm/tseg/@unit)",
@@ -22659,6 +22710,7 @@ virDomainDefFeaturesCheckABIStability(vi
         case VIR_DOMAIN_FEATURE_PRIVNET:
         case VIR_DOMAIN_FEATURE_HYPERV:
         case VIR_DOMAIN_FEATURE_KVM:
+        case VIR_DOMAIN_FEATURE_XEN:
         case VIR_DOMAIN_FEATURE_PVSPINLOCK:
         case VIR_DOMAIN_FEATURE_PMU:
         case VIR_DOMAIN_FEATURE_VMPORT:
@@ -22818,6 +22870,30 @@ virDomainDefFeaturesCheckABIStability(vi
         }
     }
 
+    /* xen */
+    if (src->features[VIR_DOMAIN_FEATURE_XEN] == VIR_TRISTATE_SWITCH_ON) {
+        for (i = 0; i < VIR_DOMAIN_XEN_LAST; i++) {
+            switch ((virDomainXen) i) {
+            case VIR_DOMAIN_XEN_E820_HOST:
+                if (src->xen_features[i] != dst->xen_features[i]) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("State of Xen feature '%s' differs: "
+                                     "source: '%s', destination: '%s'"),
+                                   virDomainXenTypeToString(i),
+                                   virTristateSwitchTypeToString(src->xen_features[i]),
+                                   virTristateSwitchTypeToString(dst->xen_features[i]));
+                    return false;
+                }
+
+                break;
+
+            /* coverity[dead_error_begin] */
+            case VIR_DOMAIN_XEN_LAST:
+                break;
+            }
+        }
+    }
+
     /* kvm */
     if (src->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) {
         for (i = 0; i < VIR_DOMAIN_KVM_LAST; i++) {
@@ -28753,6 +28829,31 @@ virDomainDefFormatInternal(virDomainDefP
                 virBufferAddLit(buf, "</kvm>\n");
                 break;
 
+            case VIR_DOMAIN_FEATURE_XEN:
+                if (def->features[i] != VIR_TRISTATE_SWITCH_ON)
+                    break;
+
+                virBufferAddLit(buf, "<xen>\n");
+                virBufferAdjustIndent(buf, 2);
+                for (j = 0; j < VIR_DOMAIN_XEN_LAST; j++) {
+                    switch ((virDomainXen) j) {
+                        case VIR_DOMAIN_XEN_E820_HOST:
+                            if (def->xen_features[j])
+                                virBufferAsprintf(buf, "<%s state='%s'/>\n",
+                                                  virDomainXenTypeToString(j),
+                                                  virTristateSwitchTypeToString(
+                                                      def->xen_features[j]));
+                            break;
+
+                        /* coverity[dead_error_begin] */
+                        case VIR_DOMAIN_XEN_LAST:
+                            break;
+                    }
+                }
+                virBufferAdjustIndent(buf, -2);
+                virBufferAddLit(buf, "</xen>\n");
+                break;
+
             case VIR_DOMAIN_FEATURE_CAPABILITIES:
                 if (def->features[i] == VIR_DOMAIN_CAPABILITIES_POLICY_DEFAULT &&
                     !virDomainDefHasCapabilitiesFeatures(def)) {
Index: libvirt-5.1.0/src/conf/domain_conf.h
===================================================================
--- libvirt-5.1.0.orig/src/conf/domain_conf.h
+++ libvirt-5.1.0/src/conf/domain_conf.h
@@ -1791,6 +1791,7 @@ typedef enum {
     VIR_DOMAIN_FEATURE_HTM,
     VIR_DOMAIN_FEATURE_NESTED_HV,
     VIR_DOMAIN_FEATURE_MSRS,
+    VIR_DOMAIN_FEATURE_XEN,
 
     VIR_DOMAIN_FEATURE_LAST
 } virDomainFeature;
@@ -1836,6 +1837,12 @@ typedef enum {
 } virDomainMsrsUnknown;
 
 typedef enum {
+    VIR_DOMAIN_XEN_E820_HOST = 0,
+
+    VIR_DOMAIN_XEN_LAST
+} virDomainXen;
+
+typedef enum {
     VIR_DOMAIN_CAPABILITIES_POLICY_DEFAULT = 0,
     VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW,
     VIR_DOMAIN_CAPABILITIES_POLICY_DENY,
@@ -2489,6 +2496,7 @@ struct _virDomainDef {
     int hyperv_features[VIR_DOMAIN_HYPERV_LAST];
     int kvm_features[VIR_DOMAIN_KVM_LAST];
     int msrs_features[VIR_DOMAIN_MSRS_LAST];
+    int xen_features[VIR_DOMAIN_XEN_LAST];
     unsigned int hyperv_spinlocks;
     virGICVersion gic_version;
     virDomainHPTResizing hpt_resizing;
@@ -3499,6 +3507,7 @@ VIR_ENUM_DECL(virDomainGraphicsSpiceMous
 VIR_ENUM_DECL(virDomainGraphicsVNCSharePolicy);
 VIR_ENUM_DECL(virDomainHyperv);
 VIR_ENUM_DECL(virDomainKVM);
+VIR_ENUM_DECL(virDomainXen);
 VIR_ENUM_DECL(virDomainMsrsUnknown);
 VIR_ENUM_DECL(virDomainRNGModel);
 VIR_ENUM_DECL(virDomainRNGBackend);
openSUSE Build Service is sponsored by