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

3e5111
       
3e5111
+      
driver
3e5111
+      
3e5111
+        

3e5111
+          The driver subelement can be used to configure
3e5111
+          additional options:
3e5111
+        

3e5111
+        
3e5111
+          
intremap
3e5111
+          
3e5111
+            

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

3e5111
+          
3e5111
+        
3e5111
+      
3e5111
     
3e5111
 
3e5111
     

Security label

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