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:

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

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Menno Lageman <menno.lageman@oracle.com>
This commit is contained in:
Menno Lageman 2020-07-07 09:55:53 +02:00 committed by Cole Robinson
parent 4eb7834c6e
commit 25419db9ca
8 changed files with 67 additions and 1 deletions

View File

@ -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

View File

@ -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>

View File

@ -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")

View File

@ -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 #
#######################

View File

@ -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

View File

@ -149,6 +149,7 @@ class Device(XMLBuilder):
"panic": ["model", "xmlindex"],
"vsock": ["model", "xmlindex"],
"memballoon": ["model", "xmlindex"],
"iommu": ["model", "xmlindex"],
}
if id(self) == id(newdev):

29
virtinst/devices/iommu.py Normal file
View File

@ -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)

View File

@ -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 = []