intel_iommu.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.
  10. import os
  11. from avocado import skipUnless
  12. from avocado_qemu import LinuxTest
  13. @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
  14. class IntelIOMMU(LinuxTest):
  15. """
  16. :avocado: tags=arch:x86_64
  17. :avocado: tags=distro:fedora
  18. :avocado: tags=distro_version:31
  19. :avocado: tags=machine:q35
  20. :avocado: tags=accel:kvm
  21. :avocado: tags=intel_iommu
  22. :avocado: tags=flaky
  23. """
  24. IOMMU_ADDON = ',iommu_platform=on,disable-modern=off,disable-legacy=on'
  25. kernel_path = None
  26. initrd_path = None
  27. kernel_params = None
  28. def set_up_boot(self):
  29. path = self.download_boot()
  30. self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,' +
  31. 'drive=drv0,id=virtio-disk0,bootindex=1,'
  32. 'werror=stop,rerror=stop' + self.IOMMU_ADDON)
  33. self.vm.add_args('-device', 'virtio-gpu-pci' + self.IOMMU_ADDON)
  34. self.vm.add_args('-drive',
  35. 'file=%s,if=none,cache=writethrough,id=drv0' % path)
  36. def setUp(self):
  37. super(IntelIOMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON)
  38. def add_common_args(self):
  39. self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
  40. self.vm.add_args('-object',
  41. 'rng-random,id=rng0,filename=/dev/urandom')
  42. def common_vm_setup(self, custom_kernel=None):
  43. self.require_accelerator("kvm")
  44. self.add_common_args()
  45. self.vm.add_args("-accel", "kvm")
  46. if custom_kernel is None:
  47. return
  48. kernel_url = self.distro.pxeboot_url + 'vmlinuz'
  49. kernel_hash = '5b6f6876e1b5bda314f93893271da0d5777b1f3c'
  50. initrd_url = self.distro.pxeboot_url + 'initrd.img'
  51. initrd_hash = 'dd0340a1b39bd28f88532babd4581c67649ec5b1'
  52. self.kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
  53. self.initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
  54. def run_and_check(self):
  55. if self.kernel_path:
  56. self.vm.add_args('-kernel', self.kernel_path,
  57. '-append', self.kernel_params,
  58. '-initrd', self.initrd_path)
  59. self.launch_and_wait()
  60. self.ssh_command('cat /proc/cmdline')
  61. self.ssh_command('dmesg | grep -e DMAR -e IOMMU')
  62. self.ssh_command('find /sys/kernel/iommu_groups/ -type l')
  63. self.ssh_command('dnf -y install numactl-devel')
  64. def test_intel_iommu(self):
  65. """
  66. :avocado: tags=intel_iommu_intremap
  67. """
  68. self.common_vm_setup(True)
  69. self.vm.add_args('-device', 'intel-iommu,intremap=on')
  70. self.vm.add_args('-machine', 'kernel_irqchip=split')
  71. self.kernel_params = (self.distro.default_kernel_params +
  72. ' quiet intel_iommu=on')
  73. self.run_and_check()
  74. def test_intel_iommu_strict(self):
  75. """
  76. :avocado: tags=intel_iommu_strict
  77. """
  78. self.common_vm_setup(True)
  79. self.vm.add_args('-device', 'intel-iommu,intremap=on')
  80. self.vm.add_args('-machine', 'kernel_irqchip=split')
  81. self.kernel_params = (self.distro.default_kernel_params +
  82. ' quiet intel_iommu=on,strict')
  83. self.run_and_check()
  84. def test_intel_iommu_strict_cm(self):
  85. """
  86. :avocado: tags=intel_iommu_strict_cm
  87. """
  88. self.common_vm_setup(True)
  89. self.vm.add_args('-device', 'intel-iommu,intremap=on,caching-mode=on')
  90. self.vm.add_args('-machine', 'kernel_irqchip=split')
  91. self.kernel_params = (self.distro.default_kernel_params +
  92. ' quiet intel_iommu=on,strict')
  93. self.run_and_check()
  94. def test_intel_iommu_pt(self):
  95. """
  96. :avocado: tags=intel_iommu_pt
  97. """
  98. self.common_vm_setup(True)
  99. self.vm.add_args('-device', 'intel-iommu,intremap=on')
  100. self.vm.add_args('-machine', 'kernel_irqchip=split')
  101. self.kernel_params = (self.distro.default_kernel_params +
  102. ' quiet intel_iommu=on iommu=pt')
  103. self.run_and_check()