6d3351
From 1e915e38d422df8b3cb4e049e932a5e6900735bc Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <1e915e38d422df8b3cb4e049e932a5e6900735bc@dist-git>
6d3351
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
6d3351
Date: Fri, 9 Jun 2017 12:48:56 +0200
6d3351
Subject: [PATCH] conf: add iotlb attribute 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 iotlb attribute to the iommu device
6d3351
to control the device IOTLB support for intel-iommu.
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1283251
6d3351
6d3351
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6d3351
(cherry picked from commit 27b187be3988c60cd26e08ab4bcab66bed5a3646)
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                          | 10 +++++++
6d3351
 docs/schemas/domaincommon.rng                      |  5 ++++
6d3351
 src/conf/domain_conf.c                             | 23 +++++++++++++++-
6d3351
 src/conf/domain_conf.h                             |  1 +
6d3351
 .../qemuxml2argv-intel-iommu-device-iotlb.xml      | 31 ++++++++++++++++++++++
6d3351
 .../qemuxml2xmlout-intel-iommu-device-iotlb.xml    |  1 +
6d3351
 tests/qemuxml2xmltest.c                            |  1 +
6d3351
 7 files changed, 71 insertions(+), 1 deletion(-)
6d3351
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-device-iotlb.xml
6d3351
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-device-iotlb.xml
6d3351
6d3351
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
6d3351
index e886e4e17e..e8a3367bac 100644
6d3351
--- a/docs/formatdomain.html.in
6d3351
+++ b/docs/formatdomain.html.in
6d3351
@@ -7446,6 +7446,16 @@ qemu-kvm -net nic,model=? /dev/null
6d3351
               Since 3.4.0 (QEMU/KVM only)
6d3351
             

6d3351
           
6d3351
+          
iotlb
6d3351
+          
6d3351
+            

6d3351
+              The iotlb attribute with possible values
6d3351
+              on and off can be used to
6d3351
+              turn on the IOTLB used to cache address translation
6d3351
+              requests from devices.
6d3351
+              Since 3.5.0 (QEMU/KVM only)
6d3351
+            

6d3351
+          
6d3351
         
6d3351
       
6d3351
     
6d3351
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
6d3351
index af7824aa02..1b66362f17 100644
6d3351
--- a/docs/schemas/domaincommon.rng
6d3351
+++ b/docs/schemas/domaincommon.rng
6d3351
@@ -3910,6 +3910,11 @@
6d3351
               <ref name="virOnOff"/>
6d3351
             </attribute>
6d3351
           </optional>
6d3351
+          <optional>
6d3351
+            <attribute name="iotlb">
6d3351
+              <ref name="virOnOff"/>
6d3351
+            </attribute>
6d3351
+          </optional>
6d3351
         </element>
6d3351
       </optional>
6d3351
     </element>
6d3351
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
6d3351
index 275145b1ec..701a6d2136 100644
6d3351
--- a/src/conf/domain_conf.c
6d3351
+++ b/src/conf/domain_conf.c
6d3351
@@ -14196,6 +14196,14 @@ virDomainIOMMUDefParseXML(xmlNodePtr node,
6d3351
         }
6d3351
         iommu->caching_mode = val;
6d3351
     }
6d3351
+    VIR_FREE(tmp);
6d3351
+    if ((tmp = virXPathString("string(./driver/@iotlb)", ctxt))) {
6d3351
+        if ((val = virTristateSwitchTypeFromString(tmp)) < 0) {
6d3351
+            virReportError(VIR_ERR_XML_ERROR, _("unknown iotlb value: %s"), tmp);
6d3351
+            goto cleanup;
6d3351
+        }
6d3351
+        iommu->iotlb = val;
6d3351
+    }
6d3351
 
6d3351
     VIR_FREE(tmp);
6d3351
     if ((tmp = virXPathString("string(./driver/@eim)", ctxt))) {
6d3351
@@ -19877,6 +19885,14 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDefPtr src,
6d3351
                        virTristateSwitchTypeToString(src->eim));
6d3351
         return false;
6d3351
     }
6d3351
+    if (src->iotlb != dst->iotlb) {
6d3351
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
6d3351
+                       _("Target domain IOMMU device iotlb value '%s' "
6d3351
+                         "does not match source '%s'"),
6d3351
+                       virTristateSwitchTypeToString(dst->iotlb),
6d3351
+                       virTristateSwitchTypeToString(src->iotlb));
6d3351
+        return false;
6d3351
+    }
6d3351
     return true;
6d3351
 }
6d3351
 
6d3351
@@ -24212,7 +24228,8 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
6d3351
     virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
6d3351
 
6d3351
     if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT ||
6d3351
-        iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT) {
6d3351
+        iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT ||
6d3351
+        iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT) {
6d3351
         virBufferAddLit(&childBuf, "
6d3351
         if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) {
6d3351
             virBufferAsprintf(&childBuf, " intremap='%s'",
6d3351
@@ -24226,6 +24243,10 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
6d3351
             virBufferAsprintf(&childBuf, " eim='%s'",
6d3351
                               virTristateSwitchTypeToString(iommu->eim));
6d3351
         }
6d3351
+        if (iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT) {
6d3351
+            virBufferAsprintf(&childBuf, " iotlb='%s'",
6d3351
+                              virTristateSwitchTypeToString(iommu->iotlb));
6d3351
+        }
6d3351
         virBufferAddLit(&childBuf, "/>\n");
6d3351
     }
6d3351
 
6d3351
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
6d3351
index 706d106ad9..e6c20a9e1e 100644
6d3351
--- a/src/conf/domain_conf.h
6d3351
+++ b/src/conf/domain_conf.h
6d3351
@@ -2213,6 +2213,7 @@ struct _virDomainIOMMUDef {
6d3351
     virTristateSwitch intremap;
6d3351
     virTristateSwitch caching_mode;
6d3351
     virTristateSwitch eim;
6d3351
+    virTristateSwitch iotlb;
6d3351
 };
6d3351
 /*
6d3351
  * Guest VM main configuration
6d3351
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-device-iotlb.xml b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-device-iotlb.xml
6d3351
new file mode 100644
6d3351
index 0000000000..3eb08ab9af
6d3351
--- /dev/null
6d3351
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-device-iotlb.xml
6d3351
@@ -0,0 +1,31 @@
6d3351
+<domain type='kvm'>
6d3351
+  <name>QEMUGuest1</name>
6d3351
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6d3351
+  <memory unit='KiB'>219100</memory>
6d3351
+  <currentMemory unit='KiB'>219100</currentMemory>
6d3351
+  <vcpu placement='static'>1</vcpu>
6d3351
+  <os>
6d3351
+    <type arch='x86_64' machine='q35'>hvm</type>
6d3351
+    <boot dev='hd'/>
6d3351
+  </os>
6d3351
+  <features>
6d3351
+    <ioapic driver='qemu'/>
6d3351
+  </features>
6d3351
+  <clock offset='utc'/>
6d3351
+  <on_poweroff>destroy</on_poweroff>
6d3351
+  <on_reboot>restart</on_reboot>
6d3351
+  <on_crash>destroy</on_crash>
6d3351
+  <devices>
6d3351
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
6d3351
+    <controller type='pci' index='0' model='pcie-root'/>
6d3351
+    <controller type='sata' index='0'>
6d3351
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
6d3351
+    </controller>
6d3351
+    <input type='mouse' bus='ps2'/>
6d3351
+    <input type='keyboard' bus='ps2'/>
6d3351
+    <memballoon model='none'/>
6d3351
+    <iommu model='intel'>
6d3351
+      <driver intremap='on' iotlb='on'/>
6d3351
+    </iommu>
6d3351
+  </devices>
6d3351
+</domain>
6d3351
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-device-iotlb.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-device-iotlb.xml
6d3351
new file mode 120000
6d3351
index 0000000000..3120d9f677
6d3351
--- /dev/null
6d3351
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-device-iotlb.xml
6d3351
@@ -0,0 +1 @@
6d3351
+../qemuxml2argvdata/qemuxml2argv-intel-iommu-device-iotlb.xml
6d3351
\ No newline at end of file
6d3351
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
6d3351
index 6283da4096..3f7c268e43 100644
6d3351
--- a/tests/qemuxml2xmltest.c
6d3351
+++ b/tests/qemuxml2xmltest.c
6d3351
@@ -1131,6 +1131,7 @@ mymain(void)
6d3351
     DO_TEST("intel-iommu-ioapic", NONE);
6d3351
     DO_TEST("intel-iommu-caching-mode", NONE);
6d3351
     DO_TEST("intel-iommu-eim", NONE);
6d3351
+    DO_TEST("intel-iommu-device-iotlb", NONE);
6d3351
 
6d3351
     DO_TEST("cpu-check-none", NONE);
6d3351
     DO_TEST("cpu-check-partial", NONE);
6d3351
-- 
6d3351
2.13.1
6d3351