cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

intel_iommu.py (4167B)


      1# INTEL_IOMMU 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
     14
     15@skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
     16class IntelIOMMU(LinuxTest):
     17    """
     18    :avocado: tags=arch:x86_64
     19    :avocado: tags=distro:fedora
     20    :avocado: tags=distro_version:31
     21    :avocado: tags=machine:q35
     22    :avocado: tags=accel:kvm
     23    :avocado: tags=intel_iommu
     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('-device', 'virtio-gpu-pci' + self.IOMMU_ADDON)
     37        self.vm.add_args('-drive',
     38                         'file=%s,if=none,cache=writethrough,id=drv0' % path)
     39
     40    def setUp(self):
     41        super(IntelIOMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON)
     42
     43    def add_common_args(self):
     44        self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
     45        self.vm.add_args('-object',
     46                         'rng-random,id=rng0,filename=/dev/urandom')
     47
     48    def common_vm_setup(self, custom_kernel=None):
     49        self.require_accelerator("kvm")
     50        self.add_common_args()
     51        self.vm.add_args("-accel", "kvm")
     52
     53        if custom_kernel is None:
     54            return
     55
     56        kernel_url = self.distro.pxeboot_url + 'vmlinuz'
     57        initrd_url = self.distro.pxeboot_url + 'initrd.img'
     58        self.kernel_path = self.fetch_asset(kernel_url)
     59        self.initrd_path = self.fetch_asset(initrd_url)
     60
     61    def run_and_check(self):
     62        if self.kernel_path:
     63            self.vm.add_args('-kernel', self.kernel_path,
     64                             '-append', self.kernel_params,
     65                             '-initrd', self.initrd_path)
     66        self.launch_and_wait()
     67        self.ssh_command('cat /proc/cmdline')
     68        self.ssh_command('dmesg | grep -e DMAR -e IOMMU')
     69        self.ssh_command('find /sys/kernel/iommu_groups/ -type l')
     70        self.ssh_command('dnf -y install numactl-devel')
     71
     72    def test_intel_iommu(self):
     73        """
     74        :avocado: tags=intel_iommu_intremap
     75        """
     76
     77        self.common_vm_setup(True)
     78        self.vm.add_args('-device', 'intel-iommu,intremap=on')
     79        self.vm.add_args('-machine', 'kernel_irqchip=split')
     80
     81        self.kernel_params = (self.distro.default_kernel_params +
     82                              ' quiet intel_iommu=on')
     83        self.run_and_check()
     84
     85    def test_intel_iommu_strict(self):
     86        """
     87        :avocado: tags=intel_iommu_strict
     88        """
     89
     90        self.common_vm_setup(True)
     91        self.vm.add_args('-device', 'intel-iommu,intremap=on')
     92        self.vm.add_args('-machine', 'kernel_irqchip=split')
     93        self.kernel_params = (self.distro.default_kernel_params +
     94                              ' quiet intel_iommu=on,strict')
     95        self.run_and_check()
     96
     97    def test_intel_iommu_strict_cm(self):
     98        """
     99        :avocado: tags=intel_iommu_strict_cm
    100        """
    101
    102        self.common_vm_setup(True)
    103        self.vm.add_args('-device', 'intel-iommu,intremap=on,caching-mode=on')
    104        self.vm.add_args('-machine', 'kernel_irqchip=split')
    105        self.kernel_params = (self.distro.default_kernel_params +
    106                              ' quiet intel_iommu=on,strict')
    107        self.run_and_check()
    108
    109    def test_intel_iommu_pt(self):
    110        """
    111        :avocado: tags=intel_iommu_pt
    112        """
    113
    114        self.common_vm_setup(True)
    115        self.vm.add_args('-device', 'intel-iommu,intremap=on')
    116        self.vm.add_args('-machine', 'kernel_irqchip=split')
    117        self.kernel_params = (self.distro.default_kernel_params +
    118                              ' quiet intel_iommu=on iommu=pt')
    119        self.run_and_check()