render / rpms / libvirt

Forked from rpms/libvirt a year ago
Clone
6d3351
From 2bb15d3f041ec2506012aa701547334af429b915 Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <2bb15d3f041ec2506012aa701547334af429b915@dist-git>
6d3351
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
6d3351
Date: Tue, 16 May 2017 10:44:54 +0200
6d3351
Subject: [PATCH] conf: add <driver intremap> to <iommu>
6d3351
MIME-Version: 1.0
6d3351
Content-Type: text/plain; charset=UTF-8
6d3351
Content-Transfer-Encoding: 8bit
6d3351
6d3351
Add a new attribute to control interrupt remapping.
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1427005
6d3351
(cherry picked from commit 2020e2c6f2656ca1aa9032859ccde76185c37c39)
6d3351
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 docs/formatdomain.html.in                          | 24 +++++++++++++-
6d3351
 docs/schemas/domaincommon.rng                      |  9 +++++
6d3351
 src/conf/domain_conf.c                             | 38 +++++++++++++++++++---
6d3351
 src/conf/domain_conf.h                             |  1 +
6d3351
 .../qemuxml2argv-intel-iommu-ioapic.xml            |  4 ++-
6d3351
 5 files changed, 70 insertions(+), 6 deletions(-)
6d3351
6d3351
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
6d3351
index 869c1f73e..41b8bfb50 100644
6d3351
--- a/docs/formatdomain.html.in
6d3351
+++ b/docs/formatdomain.html.in
6d3351
@@ -7393,7 +7393,9 @@ qemu-kvm -net nic,model=? /dev/null
6d3351
 
6d3351
 ...
6d3351
 <devices>
6d3351
-  <iommu model='intel'/>
6d3351
+  <iommu model='intel'>
6d3351
+    <driver intremap='on'/>
6d3351
+  </iommu>
6d3351
 </devices>
6d3351
 ...
6d3351
 
6d3351
@@ -7404,6 +7406,26 @@ qemu-kvm -net nic,model=? /dev/null
6d3351
           Currently only the intel model is supported.
6d3351
         

6d3351
       
6d3351
+      
driver
6d3351
+      
6d3351
+        

6d3351
+          The driver subelement can be used to configure
6d3351
+          additional options:
6d3351
+        

6d3351
+        
6d3351
+          
intremap
6d3351
+          
6d3351
+            

6d3351
+              The intremap attribute with possible values
6d3351
+              on and off can be used to
6d3351
+              turn on interrupt remapping, a part of the VT-d functionality.
6d3351
+              Currently this requires split I/O APIC
6d3351
+              (<ioapic driver='qemu'/>).
6d3351
+              Since 3.4.0 (QEMU/KVM only)
6d3351
+            

6d3351
+          
6d3351
+        
6d3351
+      
6d3351
     
6d3351
 
6d3351
     

Security label

6d3351
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
6d3351
index c72ba7e97..a400d961b 100644
6d3351
--- a/docs/schemas/domaincommon.rng
6d3351
+++ b/docs/schemas/domaincommon.rng
6d3351
@@ -3893,6 +3893,15 @@
6d3351
       <attribute name="model">
6d3351
         <value>intel</value>
6d3351
       </attribute>
6d3351
+      <optional>
6d3351
+        <element name="driver">
6d3351
+          <optional>
6d3351
+            <attribute name="intremap">
6d3351
+              <ref name="virOnOff"/>
6d3351
+            </attribute>
6d3351
+          </optional>
6d3351
+        </element>
6d3351
+      </optional>
6d3351
     </element>
6d3351
   </define>
6d3351
 
6d3351
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
6d3351
index d5c4f6ddd..45473f65b 100644
6d3351
--- a/src/conf/domain_conf.c
6d3351
+++ b/src/conf/domain_conf.c
6d3351
@@ -14132,12 +14132,16 @@ virDomainMemoryDefParseXML(xmlNodePtr memdevNode,
6d3351
 
6d3351
 
6d3351
 static virDomainIOMMUDefPtr
6d3351
-virDomainIOMMUDefParseXML(xmlNodePtr node)
6d3351
+virDomainIOMMUDefParseXML(xmlNodePtr node,
6d3351
+                          xmlXPathContextPtr ctxt)
6d3351
 {
6d3351
     virDomainIOMMUDefPtr iommu = NULL, ret = NULL;
6d3351
+    xmlNodePtr save = ctxt->node;
6d3351
     char *tmp = NULL;
6d3351
     int val;
6d3351
 
6d3351
+    ctxt->node = node;
6d3351
+
6d3351
     if (VIR_ALLOC(iommu) < 0)
6d3351
         goto cleanup;
6d3351
 
6d3351
@@ -14154,10 +14158,20 @@ virDomainIOMMUDefParseXML(xmlNodePtr node)
6d3351
 
6d3351
     iommu->model = val;
6d3351
 
6d3351
+    VIR_FREE(tmp);
6d3351
+    if ((tmp = virXPathString("string(./driver/@intremap)", ctxt))) {
6d3351
+        if ((val = virTristateSwitchTypeFromString(tmp)) < 0) {
6d3351
+            virReportError(VIR_ERR_XML_ERROR, _("unknown intremap value: %s"), tmp);
6d3351
+            goto cleanup;
6d3351
+        }
6d3351
+        iommu->intremap = val;
6d3351
+    }
6d3351
+
6d3351
     ret = iommu;
6d3351
     iommu = NULL;
6d3351
 
6d3351
  cleanup:
6d3351
+    ctxt->node = save;
6d3351
     VIR_FREE(iommu);
6d3351
     VIR_FREE(tmp);
6d3351
     return ret;
6d3351
@@ -14310,7 +14324,7 @@ virDomainDeviceDefParse(const char *xmlStr,
6d3351
             goto error;
6d3351
         break;
6d3351
     case VIR_DOMAIN_DEVICE_IOMMU:
6d3351
-        if (!(dev->data.iommu = virDomainIOMMUDefParseXML(node)))
6d3351
+        if (!(dev->data.iommu = virDomainIOMMUDefParseXML(node, ctxt)))
6d3351
             goto error;
6d3351
         break;
6d3351
     case VIR_DOMAIN_DEVICE_NONE:
6d3351
@@ -18440,7 +18454,7 @@ virDomainDefParseXML(xmlDocPtr xml,
6d3351
     }
6d3351
 
6d3351
     if (n > 0) {
6d3351
-        if (!(def->iommu = virDomainIOMMUDefParseXML(nodes[0])))
6d3351
+        if (!(def->iommu = virDomainIOMMUDefParseXML(nodes[0], ctxt)))
6d3351
             goto error;
6d3351
     }
6d3351
     VIR_FREE(nodes);
6d3351
@@ -24096,8 +24110,24 @@ static void
6d3351
 virDomainIOMMUDefFormat(virBufferPtr buf,
6d3351
                         const virDomainIOMMUDef *iommu)
6d3351
 {
6d3351
-    virBufferAsprintf(buf, "<iommu model='%s'/>\n",
6d3351
+    virBuffer childBuf = VIR_BUFFER_INITIALIZER;
6d3351
+
6d3351
+    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
6d3351
+
6d3351
+    if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) {
6d3351
+        virBufferAsprintf(&childBuf, "<driver intremap='%s'/>\n",
6d3351
+                          virTristateSwitchTypeToString(iommu->intremap));
6d3351
+    }
6d3351
+
6d3351
+    virBufferAsprintf(buf, "
6d3351
                       virDomainIOMMUModelTypeToString(iommu->model));
6d3351
+    if (virBufferUse(&childBuf)) {
6d3351
+        virBufferAddLit(buf, ">\n");
6d3351
+        virBufferAddBuffer(buf, &childBuf);
6d3351
+        virBufferAddLit(buf, "</iommu>\n");
6d3351
+    } else {
6d3351
+        virBufferAddLit(buf, "/>\n");
6d3351
+    }
6d3351
 }
6d3351
 
6d3351
 
6d3351
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
6d3351
index 4cb37b1fc..8eb422a57 100644
6d3351
--- a/src/conf/domain_conf.h
6d3351
+++ b/src/conf/domain_conf.h
6d3351
@@ -2209,6 +2209,7 @@ typedef enum {
6d3351
 
6d3351
 struct _virDomainIOMMUDef {
6d3351
     virDomainIOMMUModel model;
6d3351
+    virTristateSwitch intremap;
6d3351
 };
6d3351
 /*
6d3351
  * Guest VM main configuration
6d3351
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
6d3351
index 284d63a30..bfe714ad8 100644
6d3351
--- a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
6d3351
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
6d3351
@@ -24,6 +24,8 @@
6d3351
     <input type='mouse' bus='ps2'/>
6d3351
     <input type='keyboard' bus='ps2'/>
6d3351
     <memballoon model='none'/>
6d3351
-    <iommu model='intel'/>
6d3351
+    <iommu model='intel'>
6d3351
+      <driver intremap='on'/>
6d3351
+    </iommu>
6d3351
   </devices>
6d3351
 </domain>
6d3351
-- 
6d3351
2.13.0
6d3351