3e5111
From 3b7b827deb9eb7f43f548aabd27c300ae24c7db3 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <3b7b827deb9eb7f43f548aabd27c300ae24c7db3@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Tue, 16 May 2017 10:44:56 +0200
3e5111
Subject: [PATCH] conf: add caching_mode attribute to iommu device
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 the caching mode.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1427005
3e5111
(cherry picked from commit d12781b47eb0c9f3a498d88b632c327aa08aaf8a)
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                          |  9 ++++
3e5111
 docs/schemas/domaincommon.rng                      |  5 +++
3e5111
 src/conf/domain_conf.c                             | 24 +++++++++--
3e5111
 src/conf/domain_conf.h                             |  1 +
3e5111
 .../qemuxml2argv-intel-iommu-caching-mode.xml      | 50 ++++++++++++++++++++++
3e5111
 .../qemuxml2xmlout-intel-iommu-caching-mode.xml    |  1 +
3e5111
 tests/qemuxml2xmltest.c                            |  1 +
3e5111
 7 files changed, 88 insertions(+), 3 deletions(-)
3e5111
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-caching-mode.xml
3e5111
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-caching-mode.xml
3e5111
3e5111
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
3e5111
index 41b8bfb50..43a75c1ee 100644
3e5111
--- a/docs/formatdomain.html.in
3e5111
+++ b/docs/formatdomain.html.in
3e5111
@@ -7424,6 +7424,15 @@ qemu-kvm -net nic,model=? /dev/null
3e5111
               Since 3.4.0 (QEMU/KVM only)
3e5111
             

3e5111
           
3e5111
+          
caching_mode
3e5111
+          
3e5111
+            

3e5111
+              The caching_mode attribute with possible values
3e5111
+              on and off can be used to
3e5111
+              turn on the VT-d caching mode (useful for assigned devices).
3e5111
+              Since 3.4.0 (QEMU/KVM only)
3e5111
+            

3e5111
+          
3e5111
         
3e5111
       
3e5111
     
3e5111
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
3e5111
index a400d961b..12ccbd4e2 100644
3e5111
--- a/docs/schemas/domaincommon.rng
3e5111
+++ b/docs/schemas/domaincommon.rng
3e5111
@@ -3900,6 +3900,11 @@
3e5111
               <ref name="virOnOff"/>
3e5111
             </attribute>
3e5111
           </optional>
3e5111
+          <optional>
3e5111
+            <attribute name="caching_mode">
3e5111
+              <ref name="virOnOff"/>
3e5111
+            </attribute>
3e5111
+          </optional>
3e5111
         </element>
3e5111
       </optional>
3e5111
     </element>
3e5111
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
3e5111
index 45473f65b..e77b542f3 100644
3e5111
--- a/src/conf/domain_conf.c
3e5111
+++ b/src/conf/domain_conf.c
3e5111
@@ -14167,6 +14167,15 @@ virDomainIOMMUDefParseXML(xmlNodePtr node,
3e5111
         iommu->intremap = val;
3e5111
     }
3e5111
 
3e5111
+    VIR_FREE(tmp);
3e5111
+    if ((tmp = virXPathString("string(./driver/@caching_mode)", ctxt))) {
3e5111
+        if ((val = virTristateSwitchTypeFromString(tmp)) < 0) {
3e5111
+            virReportError(VIR_ERR_XML_ERROR, _("unknown caching_mode value: %s"), tmp);
3e5111
+            goto cleanup;
3e5111
+        }
3e5111
+        iommu->caching_mode = val;
3e5111
+    }
3e5111
+
3e5111
     ret = iommu;
3e5111
     iommu = NULL;
3e5111
 
3e5111
@@ -24114,9 +24123,18 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
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
+    if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT ||
3e5111
+        iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT) {
3e5111
+        virBufferAddLit(&childBuf, "
3e5111
+        if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) {
3e5111
+            virBufferAsprintf(&childBuf, " intremap='%s'",
3e5111
+                              virTristateSwitchTypeToString(iommu->intremap));
3e5111
+        }
3e5111
+        if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT) {
3e5111
+            virBufferAsprintf(&childBuf, " caching_mode='%s'",
3e5111
+                              virTristateSwitchTypeToString(iommu->caching_mode));
3e5111
+        }
3e5111
+        virBufferAddLit(&childBuf, "/>\n");
3e5111
     }
3e5111
 
3e5111
     virBufferAsprintf(buf, "
3e5111
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
3e5111
index 8eb422a57..825158a7d 100644
3e5111
--- a/src/conf/domain_conf.h
3e5111
+++ b/src/conf/domain_conf.h
3e5111
@@ -2210,6 +2210,7 @@ typedef enum {
3e5111
 struct _virDomainIOMMUDef {
3e5111
     virDomainIOMMUModel model;
3e5111
     virTristateSwitch intremap;
3e5111
+    virTristateSwitch caching_mode;
3e5111
 };
3e5111
 /*
3e5111
  * Guest VM main configuration
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-caching-mode.xml b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-caching-mode.xml
3e5111
new file mode 100644
3e5111
index 000000000..5f3384da7
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-caching-mode.xml
3e5111
@@ -0,0 +1,50 @@
3e5111
+<domain type='qemu'>
3e5111
+  <name>QEMUGuest1</name>
3e5111
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
3e5111
+  <memory unit='KiB'>219100</memory>
3e5111
+  <currentMemory unit='KiB'>219100</currentMemory>
3e5111
+  <vcpu placement='static'>1</vcpu>
3e5111
+  <os>
3e5111
+    <type arch='x86_64' machine='q35'>hvm</type>
3e5111
+    <boot dev='hd'/>
3e5111
+  </os>
3e5111
+  <clock offset='utc'/>
3e5111
+  <on_poweroff>destroy</on_poweroff>
3e5111
+  <on_reboot>restart</on_reboot>
3e5111
+  <on_crash>destroy</on_crash>
3e5111
+  <devices>
3e5111
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
3e5111
+    <controller type='pci' index='0' model='pcie-root'/>
3e5111
+    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
3e5111
+      <model name='i82801b11-bridge'/>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
3e5111
+    </controller>
3e5111
+    <controller type='pci' index='2' model='pci-bridge'>
3e5111
+      <model name='pci-bridge'/>
3e5111
+      <target chassisNr='2'/>
3e5111
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
3e5111
+    </controller>
3e5111
+    <controller type='pci' index='3' model='pcie-root-port'>
3e5111
+      <model name='ioh3420'/>
3e5111
+      <target chassis='3' port='0x10'/>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
3e5111
+    </controller>
3e5111
+    <controller type='sata' index='0'>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
3e5111
+    </controller>
3e5111
+    <controller type='usb' index='0' model='ich9-ehci1'>
3e5111
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x7'/>
3e5111
+    </controller>
3e5111
+    <interface type='user'>
3e5111
+      <mac address='52:54:00:ab:0c:5c'/>
3e5111
+      <model type='rtl8139'/>
3e5111
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/>
3e5111
+    </interface>
3e5111
+    <input type='mouse' bus='ps2'/>
3e5111
+    <input type='keyboard' bus='ps2'/>
3e5111
+    <memballoon model='none'/>
3e5111
+    <iommu model='intel'>
3e5111
+      <driver intremap='on' caching_mode='on'/>
3e5111
+    </iommu>
3e5111
+  </devices>
3e5111
+</domain>
3e5111
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-caching-mode.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-caching-mode.xml
3e5111
new file mode 120000
3e5111
index 000000000..d971a35dc
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-caching-mode.xml
3e5111
@@ -0,0 +1 @@
3e5111
+../qemuxml2argvdata/qemuxml2argv-intel-iommu-caching-mode.xml
3e5111
\ No newline at end of file
3e5111
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
3e5111
index 0482ad9cb..e1938421a 100644
3e5111
--- a/tests/qemuxml2xmltest.c
3e5111
+++ b/tests/qemuxml2xmltest.c
3e5111
@@ -1129,6 +1129,7 @@ mymain(void)
3e5111
             QEMU_CAPS_MACHINE_OPT,
3e5111
             QEMU_CAPS_MACHINE_IOMMU);
3e5111
     DO_TEST("intel-iommu-ioapic", NONE);
3e5111
+    DO_TEST("intel-iommu-caching-mode", NONE);
3e5111
 
3e5111
     DO_TEST("cpu-check-none", NONE);
3e5111
     DO_TEST("cpu-check-partial", NONE);
3e5111
-- 
3e5111
2.13.0
3e5111