From 25419db9caf0e45578e98d85af096fab52a3c7cc Mon Sep 17 00:00:00 2001 From: Menno Lageman Date: Tue, 7 Jul 2020 09:55:53 +0200 Subject: [PATCH] virtinst: add support for configuring the IOMMU 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: Reviewed-by: Cole Robinson Signed-off-by: Menno Lageman --- 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 bc9f3e53..058b9364 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. +=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. + =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 49be9d66..de43ab07 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 @@
+ + + @@ -455,6 +458,9 @@
+ + + diff --git a/tests/test_cli.py b/tests/test_cli.py index e108d946..f68d5189 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 14f5f56f..38dfbcc7 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -811,6 +811,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): @@ -3629,6 +3633,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 6120f5d0..eae4b29b 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 c976870d..bb91d33b 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 00000000..c7639c6a --- /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 . + +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 76dab8b4..6fdb67a1 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 = []