1 # INTEL_IOMMU Functional tests
3 # Copyright (c) 2021 Red Hat, Inc.
6 # Eric Auger <eric.auger@redhat.com>
8 # This work is licensed under the terms of the GNU GPL, version 2 or
9 # later. See the COPYING file in the top-level directory.
12 from avocado
import skipUnless
13 from avocado_qemu
import LinuxTest
15 @skipUnless(os
.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
17 class IntelIOMMU(LinuxTest
):
19 :avocado: tags=arch:x86_64
20 :avocado: tags=distro:fedora
21 :avocado: tags=distro_version:31
22 :avocado: tags=machine:q35
23 :avocado: tags=accel:kvm
24 :avocado: tags=intel_iommu
28 IOMMU_ADDON
= ',iommu_platform=on,disable-modern=off,disable-legacy=on'
33 def set_up_boot(self
):
34 path
= self
.download_boot()
35 self
.vm
.add_args('-device', 'virtio-blk-pci,bus=pcie.0,scsi=off,' +
36 'drive=drv0,id=virtio-disk0,bootindex=1,'
37 'werror=stop,rerror=stop' + self
.IOMMU_ADDON
)
38 self
.vm
.add_args('-device', 'virtio-gpu-pci' + self
.IOMMU_ADDON
)
39 self
.vm
.add_args('-drive',
40 'file=%s,if=none,cache=writethrough,id=drv0' % path
)
43 super(IntelIOMMU
, self
).setUp(None, 'virtio-net-pci' + self
.IOMMU_ADDON
)
45 def add_common_args(self
):
46 self
.vm
.add_args('-device', 'virtio-rng-pci,rng=rng0')
47 self
.vm
.add_args('-object',
48 'rng-random,id=rng0,filename=/dev/urandom')
50 def common_vm_setup(self
, custom_kernel
=None):
51 self
.require_accelerator("kvm")
52 self
.add_common_args()
53 self
.vm
.add_args("-accel", "kvm")
55 if custom_kernel
is None:
58 kernel_url
= self
.distro
.pxeboot_url
+ 'vmlinuz'
59 kernel_hash
= '5b6f6876e1b5bda314f93893271da0d5777b1f3c'
60 initrd_url
= self
.distro
.pxeboot_url
+ 'initrd.img'
61 initrd_hash
= 'dd0340a1b39bd28f88532babd4581c67649ec5b1'
62 self
.kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
63 self
.initrd_path
= self
.fetch_asset(initrd_url
, asset_hash
=initrd_hash
)
65 def run_and_check(self
):
67 self
.vm
.add_args('-kernel', self
.kernel_path
,
68 '-append', self
.kernel_params
,
69 '-initrd', self
.initrd_path
)
70 self
.launch_and_wait()
71 self
.ssh_command('cat /proc/cmdline')
72 self
.ssh_command('dmesg | grep -e DMAR -e IOMMU')
73 self
.ssh_command('find /sys/kernel/iommu_groups/ -type l')
74 self
.ssh_command('dnf -y install numactl-devel')
76 def test_intel_iommu(self
):
78 :avocado: tags=intel_iommu_intremap
81 self
.common_vm_setup(True)
82 self
.vm
.add_args('-device', 'intel-iommu,intremap=on')
83 self
.vm
.add_args('-machine', 'kernel_irqchip=split')
85 self
.kernel_params
= (self
.distro
.default_kernel_params
+
86 ' quiet intel_iommu=on')
89 def test_intel_iommu_strict(self
):
91 :avocado: tags=intel_iommu_strict
94 self
.common_vm_setup(True)
95 self
.vm
.add_args('-device', 'intel-iommu,intremap=on')
96 self
.vm
.add_args('-machine', 'kernel_irqchip=split')
97 self
.kernel_params
= (self
.distro
.default_kernel_params
+
98 ' quiet intel_iommu=on,strict')
101 def test_intel_iommu_strict_cm(self
):
103 :avocado: tags=intel_iommu_strict_cm
106 self
.common_vm_setup(True)
107 self
.vm
.add_args('-device', 'intel-iommu,intremap=on,caching-mode=on')
108 self
.vm
.add_args('-machine', 'kernel_irqchip=split')
109 self
.kernel_params
= (self
.distro
.default_kernel_params
+
110 ' quiet intel_iommu=on,strict')
113 def test_intel_iommu_pt(self
):
115 :avocado: tags=intel_iommu_pt
118 self
.common_vm_setup(True)
119 self
.vm
.add_args('-device', 'intel-iommu,intremap=on')
120 self
.vm
.add_args('-machine', 'kernel_irqchip=split')
121 self
.kernel_params
= (self
.distro
.default_kernel_params
+
122 ' quiet intel_iommu=on iommu=pt')