diff --git a/libvirt/tests/cfg/sriov/vIOMMU/intel_iommu_with_dma_translation.cfg b/libvirt/tests/cfg/sriov/vIOMMU/intel_iommu_with_dma_translation.cfg new file mode 100644 index 0000000000..842285418b --- /dev/null +++ b/libvirt/tests/cfg/sriov/vIOMMU/intel_iommu_with_dma_translation.cfg @@ -0,0 +1,17 @@ +- vIOMMU.intel_iommu_with_dma_translation: + type = intel_iommu_with_dma_translation + start_vm = "yes" + enable_guest_iommu = "yes" + iommu_dict = {'model': 'intel', 'driver': {'intremap': 'on', 'caching_mode': 'on', 'iotlb': 'on', 'dma_translation': '%s'}} + func_supported_since_libvirt_ver = (10, 7, 0) + only q35 + variants: + - enable_dma_translation: + dma_translation = "on" + - disable_dma_translation: + dma_translation = "off" + - disable_dma_translation_with_more_vcpus: + with_more_vcpus = "yes" + dma_translation = "off" + eim_dict = {'eim': 'on'} + guest_vcpus = 256 diff --git a/libvirt/tests/src/sriov/vIOMMU/intel_iommu_with_dma_translation.py b/libvirt/tests/src/sriov/vIOMMU/intel_iommu_with_dma_translation.py new file mode 100644 index 0000000000..f64f8ecfe6 --- /dev/null +++ b/libvirt/tests/src/sriov/vIOMMU/intel_iommu_with_dma_translation.py @@ -0,0 +1,49 @@ +from virttest import virsh +from virttest import libvirt_version +from virttest.libvirt_xml import vm_xml + +from provider.viommu import viommu_base + + +def run(test, params, env): + """ + Start vm with Intel iommu and dma_translation attribute. + """ + vm_name = params.get("main_vm", "avocado-vt-vm1") + vm = env.get_vm(vm_name) + dma_translation = params.get("dma_translation") + guest_vcpus = params.get("guest_vcpus") + eim_dict = eval(params.get("eim_dict", "{}")) + iommu_dict = eval(params.get("iommu_dict", "{}") % dma_translation) + with_more_vcpus = "yes" == params.get("with_more_vcpus", "no") + test_obj = viommu_base.VIOMMUTest(vm, test, params) + libvirt_version.is_libvirt_feature_supported(params) + + try: + iommu_dict['driver'].update(eim_dict) + test.log.info("TEST STEP1: Prepare guest xml with intel iommu device.") + test_obj.setup_iommu_test(iommu_dict=iommu_dict) + vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) + if with_more_vcpus: + vmxml.vcpu = int(guest_vcpus) + vmxml.sync() + test.log.info("TEST STEP2: Start the guest.") + virsh.start(vm_name, debug=True) + test.log.debug("The current guest xml ls: %s", + virsh.dumpxml(vm_name).stdout_text) + test.log.info("TEST STEP3: Check the message for iommu group and DMA.") + vm.cleanup_serial_console() + vm.create_serial_console() + vm_session = vm.wait_for_serial_login(timeout=6000) + dma_status, _ = vm_session.cmd_status_output("dmesg | grep -i 'Not attempting DMA translation'") + iommu_status, _ = vm_session.cmd_status_output("dmesg | grep -i 'Adding to iommu group'") + if dma_translation == "on" and (not dma_status or iommu_status): + test.fail("Can't get expected message result when enabling dma_translation.") + if dma_translation == "off" and (dma_status or not iommu_status): + test.fail("Can't get expected message result when disabling dma_translation.") + if with_more_vcpus: + s, o = vm_session.cmd_status_output("cat /proc/cpuinfo | grep processor| wc -l") + if int(o) != int(guest_vcpus): + test.fail("Can't get expected vCPU number, the actual number is %s" % type(o)) + finally: + test_obj.teardown_iommu_test()