[PATCH] virtinst: add support for configuring the IOMMU

Menno Lageman menno.lageman at oracle.com
Tue Jul 7 07:55:53 UTC 2020


Add a --iommu option to configure IOMMU parameters as described in
https://libvirt.org/formatdomain.html#elementsIommu

E.g. 'virt-install --iommu model=intel,driver.aw_bits=48,driver.iotlb=on ...'
will generate the following domain XML:

  <devices>
    <iommu model="intel">
      <driver aw_bits="48" iotlb="on"/>
    </iommu>
  </devices>

Signed-off-by: Menno Lageman <menno.lageman at oracle.com>
---
 man/virt-install.pod                          |  6 ++++
 .../virt-install-singleton-config-2.xml       |  6 ++++
 tests/test_cli.py                             |  1 +
 virtinst/cli.py                               | 21 ++++++++++++++
 virtinst/devices/__init__.py                  |  1 +
 virtinst/devices/device.py                    |  1 +
 virtinst/devices/iommu.py                     | 29 +++++++++++++++++++
 virtinst/guest.py                             |  3 +-
 8 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 virtinst/devices/iommu.py

diff --git a/man/virt-install.pod b/man/virt-install.pod
index bc9f3e534940..058b9364103d 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1814,6 +1814,12 @@ Configure a vsock host/guest interface. A typical configuration would be
 
 Use --vsock=? to see a list of all available sub options. Complete details at L<https://libvirt.org/formatdomain.html#vsock>.
 
+=item B<--iommu> MODEL[,OPTS]
+
+Add an IOMMU device to the guest.
+
+Use --iommu=? to see a list of all available options. Complete details at L<https://libvirt.org/formatdomain.html#elementsIommu>.
+
 
 =back
 
diff --git a/tests/data/cli/compare/virt-install-singleton-config-2.xml b/tests/data/cli/compare/virt-install-singleton-config-2.xml
index 49be9d6607f4..de43ab076651 100644
--- a/tests/data/cli/compare/virt-install-singleton-config-2.xml
+++ b/tests/data/cli/compare/virt-install-singleton-config-2.xml
@@ -214,6 +214,9 @@
     <panic model="isa">
       <address type="isa" iobase="0x506"/>
     </panic>
+    <iommu model="intel">
+      <driver aw_bits="48" intremap="off" caching_mode="on" eim="off" iotlb="off"/>
+    </iommu>
   </devices>
   <seclabel type="static" model="selinux" relabel="yes">
     <label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
@@ -455,6 +458,9 @@
     <panic model="isa">
       <address type="isa" iobase="0x506"/>
     </panic>
+    <iommu model="intel">
+      <driver aw_bits="48" intremap="off" caching_mode="on" eim="off" iotlb="off"/>
+    </iommu>
   </devices>
   <seclabel type="static" model="selinux" relabel="yes">
     <label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
diff --git a/tests/test_cli.py b/tests/test_cli.py
index ad0f9e4097fb..c20295399cf4 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -556,6 +556,7 @@ memnode0.cellid=1,memnode0.mode=strict,memnode0.nodeset=2
 --tpm passthrough,model=tpm-crb,path=/dev/tpm0,backend.encryption.secret=11111111-2222-3333-4444-5555555555
 --rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=udp,backend_mode=bind,backend_connect_host=foo,backend_connect_service=708,rate.bytes=1234,rate.period=1000,model=virtio
 --panic iobase=0x506
+--iommu model=intel,driver.aw_bits=48,driver.caching_mode=on,driver.eim=off,driver.intremap=off,driver.iotlb=off
 """, "singleton-config-2")
 
 
diff --git a/virtinst/cli.py b/virtinst/cli.py
index bb21495abbed..9cea9815b499 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -808,6 +808,10 @@ def add_device_options(devg, sound_back_compat=False):
                     help=_("Configure guest vsock sockets. Ex:\n"
                            "--vsock cid.auto=yes\n"
                            "--vsock cid.address=7"))
+    ParserIommu.register()
+    devg.add_argument("--iommu", action="append",
+                    help=_("Configure an IOMMU device. Ex:\n"
+                           "--iommu model=intel,driver.aw_bits=48"))
 
 
 def add_guest_xml_options(geng):
@@ -3624,6 +3628,23 @@ class ParserInput(VirtCLIParser):
         cls.add_arg("bus", "bus", ignore_default=True)
 
 
+class ParserIommu(VirtCLIParser):
+    cli_arg_name = "iommu"
+    guest_propname = "devices.iommu"
+    remove_first = "model"
+
+    @classmethod
+    def _init_class(cls, **kwargs):
+        VirtCLIParser._init_class(**kwargs)
+
+        cls.add_arg("model", "model")
+        cls.add_arg("driver.aw_bits", "aw_bits")
+        cls.add_arg("driver.intremap", "intremap", is_onoff=True)
+        cls.add_arg("driver.caching_mode", "caching_mode", is_onoff=True)
+        cls.add_arg("driver.eim", "eim", is_onoff=True)
+        cls.add_arg("driver.iotlb", "iotlb", is_onoff=True)
+
+
 #######################
 # --smartcard parsing #
 #######################
diff --git a/virtinst/devices/__init__.py b/virtinst/devices/__init__.py
index 6120f5d05d90..eae4b29bd2c8 100644
--- a/virtinst/devices/__init__.py
+++ b/virtinst/devices/__init__.py
@@ -13,6 +13,7 @@ from .graphics import DeviceGraphics
 from .hostdev import DeviceHostdev
 from .input import DeviceInput
 from .interface import DeviceInterface
+from .iommu import DeviceIommu
 from .memballoon import DeviceMemballoon
 from .memory import DeviceMemory
 from .panic import DevicePanic
diff --git a/virtinst/devices/device.py b/virtinst/devices/device.py
index 382ce12f073f..cd69864b037b 100644
--- a/virtinst/devices/device.py
+++ b/virtinst/devices/device.py
@@ -149,6 +149,7 @@ class Device(XMLBuilder):
             "panic":         ["model", "xmlindex"],
             "vsock":         ["model", "xmlindex"],
             "memballoon":    ["model", "xmlindex"],
+            "iommu":         ["model", "xmlindex"],
         }
 
         if id(self) == id(newdev):
diff --git a/virtinst/devices/iommu.py b/virtinst/devices/iommu.py
new file mode 100644
index 000000000000..c7639c6ada6a
--- /dev/null
+++ b/virtinst/devices/iommu.py
@@ -0,0 +1,29 @@
+#
+# Copyright 2020 Oracle Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; If not, see <http://www.gnu.org/licenses/>.
+
+from .device import Device
+from ..xmlbuilder import XMLProperty
+
+
+class DeviceIommu(Device):
+    XML_NAME = "iommu"
+
+    model = XMLProperty("./@model")
+    aw_bits = XMLProperty("./driver/@aw_bits", is_int=True)
+    intremap = XMLProperty("./driver/@intremap", is_onoff=True)
+    caching_mode = XMLProperty("./driver/@caching_mode", is_onoff=True)
+    eim = XMLProperty("./driver/@eim", is_onoff=True)
+    iotlb = XMLProperty("./driver/@iotlb", is_onoff=True)
diff --git a/virtinst/guest.py b/virtinst/guest.py
index 76dab8b40c08..6fdb67a13484 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -27,7 +27,7 @@ class _DomainDevices(XMLBuilder):
             'smartcard', 'serial', 'parallel', 'console', 'channel',
             'input', 'tpm', 'graphics', 'sound', 'video', 'hostdev',
             'redirdev', 'watchdog', 'memballoon', 'rng', 'panic',
-            'memory', 'vsock']
+            'memory', 'vsock', 'iommu']
 
 
     disk = XMLChildProperty(DeviceDisk)
@@ -52,6 +52,7 @@ class _DomainDevices(XMLBuilder):
     panic = XMLChildProperty(DevicePanic)
     memory = XMLChildProperty(DeviceMemory)
     vsock = XMLChildProperty(DeviceVsock)
+    iommu = XMLChildProperty(DeviceIommu)
 
     def get_all(self):
         retlist = []
-- 
2.26.2




More information about the virt-tools-list mailing list