1bbbd9b6eSWillian Rampazzo# INTEL_IOMMU Functional tests 2bbbd9b6eSWillian Rampazzo# 3bbbd9b6eSWillian Rampazzo# Copyright (c) 2021 Red Hat, Inc. 4bbbd9b6eSWillian Rampazzo# 5bbbd9b6eSWillian Rampazzo# Author: 6bbbd9b6eSWillian Rampazzo# Eric Auger <eric.auger@redhat.com> 7bbbd9b6eSWillian Rampazzo# 8bbbd9b6eSWillian Rampazzo# This work is licensed under the terms of the GNU GPL, version 2 or 9bbbd9b6eSWillian Rampazzo# later. See the COPYING file in the top-level directory. 10bbbd9b6eSWillian Rampazzoimport os 11bbbd9b6eSWillian Rampazzo 129b45cc99SAlex Bennéefrom avocado import skipUnless 13*816d4201SThomas Huthfrom avocado_qemu.linuxtest import LinuxTest 14bbbd9b6eSWillian Rampazzo 159b45cc99SAlex Bennée@skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab') 16bbbd9b6eSWillian Rampazzoclass IntelIOMMU(LinuxTest): 17bbbd9b6eSWillian Rampazzo """ 18bbbd9b6eSWillian Rampazzo :avocado: tags=arch:x86_64 19bbbd9b6eSWillian Rampazzo :avocado: tags=distro:fedora 20bbbd9b6eSWillian Rampazzo :avocado: tags=distro_version:31 21bbbd9b6eSWillian Rampazzo :avocado: tags=machine:q35 22bbbd9b6eSWillian Rampazzo :avocado: tags=accel:kvm 23bbbd9b6eSWillian Rampazzo :avocado: tags=intel_iommu 245d25fcb7SAlex Bennée :avocado: tags=flaky 25bbbd9b6eSWillian Rampazzo """ 26bbbd9b6eSWillian Rampazzo 27bbbd9b6eSWillian Rampazzo IOMMU_ADDON = ',iommu_platform=on,disable-modern=off,disable-legacy=on' 28bbbd9b6eSWillian Rampazzo kernel_path = None 29bbbd9b6eSWillian Rampazzo initrd_path = None 30bbbd9b6eSWillian Rampazzo kernel_params = None 31bbbd9b6eSWillian Rampazzo 32bbbd9b6eSWillian Rampazzo def set_up_boot(self): 33bbbd9b6eSWillian Rampazzo path = self.download_boot() 34993e3802SPaolo Bonzini self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,' + 35bbbd9b6eSWillian Rampazzo 'drive=drv0,id=virtio-disk0,bootindex=1,' 36bbbd9b6eSWillian Rampazzo 'werror=stop,rerror=stop' + self.IOMMU_ADDON) 37bbbd9b6eSWillian Rampazzo self.vm.add_args('-device', 'virtio-gpu-pci' + self.IOMMU_ADDON) 38bbbd9b6eSWillian Rampazzo self.vm.add_args('-drive', 39bbbd9b6eSWillian Rampazzo 'file=%s,if=none,cache=writethrough,id=drv0' % path) 40bbbd9b6eSWillian Rampazzo 41bbbd9b6eSWillian Rampazzo def setUp(self): 42bbbd9b6eSWillian Rampazzo super(IntelIOMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON) 43bbbd9b6eSWillian Rampazzo 44bbbd9b6eSWillian Rampazzo def add_common_args(self): 45bbbd9b6eSWillian Rampazzo self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0') 46bbbd9b6eSWillian Rampazzo self.vm.add_args('-object', 47bbbd9b6eSWillian Rampazzo 'rng-random,id=rng0,filename=/dev/urandom') 48bbbd9b6eSWillian Rampazzo 49bbbd9b6eSWillian Rampazzo def common_vm_setup(self, custom_kernel=None): 50bbbd9b6eSWillian Rampazzo self.require_accelerator("kvm") 51bbbd9b6eSWillian Rampazzo self.add_common_args() 52bbbd9b6eSWillian Rampazzo self.vm.add_args("-accel", "kvm") 53bbbd9b6eSWillian Rampazzo 54bbbd9b6eSWillian Rampazzo if custom_kernel is None: 55bbbd9b6eSWillian Rampazzo return 56bbbd9b6eSWillian Rampazzo 57bbbd9b6eSWillian Rampazzo kernel_url = self.distro.pxeboot_url + 'vmlinuz' 589cdafe3bSThomas Huth kernel_hash = '5b6f6876e1b5bda314f93893271da0d5777b1f3c' 59bbbd9b6eSWillian Rampazzo initrd_url = self.distro.pxeboot_url + 'initrd.img' 609cdafe3bSThomas Huth initrd_hash = 'dd0340a1b39bd28f88532babd4581c67649ec5b1' 619cdafe3bSThomas Huth self.kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 629cdafe3bSThomas Huth self.initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 63bbbd9b6eSWillian Rampazzo 64bbbd9b6eSWillian Rampazzo def run_and_check(self): 65bbbd9b6eSWillian Rampazzo if self.kernel_path: 66bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', self.kernel_path, 67bbbd9b6eSWillian Rampazzo '-append', self.kernel_params, 68bbbd9b6eSWillian Rampazzo '-initrd', self.initrd_path) 69bbbd9b6eSWillian Rampazzo self.launch_and_wait() 70bbbd9b6eSWillian Rampazzo self.ssh_command('cat /proc/cmdline') 71bbbd9b6eSWillian Rampazzo self.ssh_command('dmesg | grep -e DMAR -e IOMMU') 72bbbd9b6eSWillian Rampazzo self.ssh_command('find /sys/kernel/iommu_groups/ -type l') 73bbbd9b6eSWillian Rampazzo self.ssh_command('dnf -y install numactl-devel') 74bbbd9b6eSWillian Rampazzo 75bbbd9b6eSWillian Rampazzo def test_intel_iommu(self): 76bbbd9b6eSWillian Rampazzo """ 77bbbd9b6eSWillian Rampazzo :avocado: tags=intel_iommu_intremap 78bbbd9b6eSWillian Rampazzo """ 79bbbd9b6eSWillian Rampazzo 80bbbd9b6eSWillian Rampazzo self.common_vm_setup(True) 81bbbd9b6eSWillian Rampazzo self.vm.add_args('-device', 'intel-iommu,intremap=on') 82bbbd9b6eSWillian Rampazzo self.vm.add_args('-machine', 'kernel_irqchip=split') 83bbbd9b6eSWillian Rampazzo 84bbbd9b6eSWillian Rampazzo self.kernel_params = (self.distro.default_kernel_params + 85bbbd9b6eSWillian Rampazzo ' quiet intel_iommu=on') 86bbbd9b6eSWillian Rampazzo self.run_and_check() 87bbbd9b6eSWillian Rampazzo 88bbbd9b6eSWillian Rampazzo def test_intel_iommu_strict(self): 89bbbd9b6eSWillian Rampazzo """ 90bbbd9b6eSWillian Rampazzo :avocado: tags=intel_iommu_strict 91bbbd9b6eSWillian Rampazzo """ 92bbbd9b6eSWillian Rampazzo 93bbbd9b6eSWillian Rampazzo self.common_vm_setup(True) 94bbbd9b6eSWillian Rampazzo self.vm.add_args('-device', 'intel-iommu,intremap=on') 95bbbd9b6eSWillian Rampazzo self.vm.add_args('-machine', 'kernel_irqchip=split') 96bbbd9b6eSWillian Rampazzo self.kernel_params = (self.distro.default_kernel_params + 97bbbd9b6eSWillian Rampazzo ' quiet intel_iommu=on,strict') 98bbbd9b6eSWillian Rampazzo self.run_and_check() 99bbbd9b6eSWillian Rampazzo 100bbbd9b6eSWillian Rampazzo def test_intel_iommu_strict_cm(self): 101bbbd9b6eSWillian Rampazzo """ 102bbbd9b6eSWillian Rampazzo :avocado: tags=intel_iommu_strict_cm 103bbbd9b6eSWillian Rampazzo """ 104bbbd9b6eSWillian Rampazzo 105bbbd9b6eSWillian Rampazzo self.common_vm_setup(True) 106bbbd9b6eSWillian Rampazzo self.vm.add_args('-device', 'intel-iommu,intremap=on,caching-mode=on') 107bbbd9b6eSWillian Rampazzo self.vm.add_args('-machine', 'kernel_irqchip=split') 108bbbd9b6eSWillian Rampazzo self.kernel_params = (self.distro.default_kernel_params + 109bbbd9b6eSWillian Rampazzo ' quiet intel_iommu=on,strict') 110bbbd9b6eSWillian Rampazzo self.run_and_check() 111bbbd9b6eSWillian Rampazzo 112bbbd9b6eSWillian Rampazzo def test_intel_iommu_pt(self): 113bbbd9b6eSWillian Rampazzo """ 114bbbd9b6eSWillian Rampazzo :avocado: tags=intel_iommu_pt 115bbbd9b6eSWillian Rampazzo """ 116bbbd9b6eSWillian Rampazzo 117bbbd9b6eSWillian Rampazzo self.common_vm_setup(True) 118bbbd9b6eSWillian Rampazzo self.vm.add_args('-device', 'intel-iommu,intremap=on') 119bbbd9b6eSWillian Rampazzo self.vm.add_args('-machine', 'kernel_irqchip=split') 120bbbd9b6eSWillian Rampazzo self.kernel_params = (self.distro.default_kernel_params + 121bbbd9b6eSWillian Rampazzo ' quiet intel_iommu=on iommu=pt') 122bbbd9b6eSWillian Rampazzo self.run_and_check() 123