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