1# SMMUv3 Functional tests 2# 3# Copyright (c) 2021 Red Hat, Inc. 4# 5# Author: 6# Eric Auger <eric.auger@redhat.com> 7# 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. 10import os 11 12from avocado import skipUnless 13from avocado_qemu import BUILD_DIR 14from avocado_qemu.linuxtest import LinuxTest 15 16@skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab') 17 18class SMMU(LinuxTest): 19 """ 20 :avocado: tags=accel:kvm 21 :avocado: tags=cpu:host 22 :avocado: tags=arch:aarch64 23 :avocado: tags=machine:virt 24 :avocado: tags=distro:fedora 25 :avocado: tags=smmu 26 :avocado: tags=flaky 27 """ 28 29 IOMMU_ADDON = ',iommu_platform=on,disable-modern=off,disable-legacy=on' 30 kernel_path = None 31 initrd_path = None 32 kernel_params = None 33 34 def set_up_boot(self): 35 path = self.download_boot() 36 self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,' + 37 'drive=drv0,id=virtio-disk0,bootindex=1,' 38 'werror=stop,rerror=stop' + self.IOMMU_ADDON) 39 self.vm.add_args('-drive', 40 'file=%s,if=none,cache=writethrough,id=drv0' % path) 41 42 def setUp(self): 43 super(SMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON) 44 45 def common_vm_setup(self, custom_kernel=False): 46 self.require_accelerator("kvm") 47 self.vm.add_args("-accel", "kvm") 48 self.vm.add_args("-cpu", "host") 49 self.vm.add_args("-machine", "iommu=smmuv3") 50 self.vm.add_args("-d", "guest_errors") 51 self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios', 52 'edk2-aarch64-code.fd')) 53 self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0') 54 self.vm.add_args('-object', 55 'rng-random,id=rng0,filename=/dev/urandom') 56 57 if custom_kernel is False: 58 return 59 60 kernel_url = self.distro.pxeboot_url + 'vmlinuz' 61 initrd_url = self.distro.pxeboot_url + 'initrd.img' 62 self.kernel_path = self.fetch_asset(kernel_url) 63 self.initrd_path = self.fetch_asset(initrd_url) 64 65 def run_and_check(self): 66 if self.kernel_path: 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('dnf -y install numactl-devel') 73 74 75 # 5.3 kernel without RIL # 76 77 def test_smmu_noril(self): 78 """ 79 :avocado: tags=smmu_noril 80 :avocado: tags=smmu_noril_tests 81 :avocado: tags=distro_version:31 82 """ 83 self.common_vm_setup() 84 self.run_and_check() 85 86 def test_smmu_noril_passthrough(self): 87 """ 88 :avocado: tags=smmu_noril_passthrough 89 :avocado: tags=smmu_noril_tests 90 :avocado: tags=distro_version:31 91 """ 92 self.common_vm_setup(True) 93 self.kernel_params = (self.distro.default_kernel_params + 94 ' iommu.passthrough=on') 95 self.run_and_check() 96 97 def test_smmu_noril_nostrict(self): 98 """ 99 :avocado: tags=smmu_noril_nostrict 100 :avocado: tags=smmu_noril_tests 101 :avocado: tags=distro_version:31 102 """ 103 self.common_vm_setup(True) 104 self.kernel_params = (self.distro.default_kernel_params + 105 ' iommu.strict=0') 106 self.run_and_check() 107 108 # 5.8 kernel featuring range invalidation 109 # >= v5.7 kernel 110 111 def test_smmu_ril(self): 112 """ 113 :avocado: tags=smmu_ril 114 :avocado: tags=smmu_ril_tests 115 :avocado: tags=distro_version:33 116 """ 117 self.common_vm_setup() 118 self.run_and_check() 119 120 def test_smmu_ril_passthrough(self): 121 """ 122 :avocado: tags=smmu_ril_passthrough 123 :avocado: tags=smmu_ril_tests 124 :avocado: tags=distro_version:33 125 """ 126 self.common_vm_setup(True) 127 self.kernel_params = (self.distro.default_kernel_params + 128 ' iommu.passthrough=on') 129 self.run_and_check() 130 131 def test_smmu_ril_nostrict(self): 132 """ 133 :avocado: tags=smmu_ril_nostrict 134 :avocado: tags=smmu_ril_tests 135 :avocado: tags=distro_version:33 136 """ 137 self.common_vm_setup(True) 138 self.kernel_params = (self.distro.default_kernel_params + 139 ' iommu.strict=0') 140 self.run_and_check() 141