render / rpms / libvirt

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

3e5111
           
3e5111
+          
iotlb
3e5111
+          
3e5111
+            

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

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