The pt option only enables IOMMU translation for devices used in pass-thru ,doesn’t enable IOMMU translation for host used devices ,and this will improve performance for host PCIe devices (which are not pass-thru to a VM).
内核的注释:
1 2 3 4 5 6 7 8
/* * This variable becomes 1 if iommu=pt is passed on the kernel command line. * If this variable is 1, IOMMU implementations do no DMA translation for * devices and allow every device to access to whole physical memory. This is * useful if a user wants to use an IOMMU only for KVM device assignment to * guests and not for driver dma translation. */ int iommu_pass_through __read_mostly = 1;
/* * This domain is a statically identity mapping domain. * 1. This domain creats a static 1:1 mapping to all usable memory. * 2. It maps to each iommu if successful. * 3. Each iommu maps to this domain if successful. */ staticstructdmar_domain *si_domain; staticint hw_pass_through = 1;
staticint __init init_dmars(void) { ... if (!ecap_pass_through(iommu->ecap)) hw_pass_through = 0; ... if (iommu_pass_through) iommu_identity_mapping |= IDENTMAP_ALL; ... if (iommu_identity_mapping) { ret = si_domain_init(hw_pass_through); if (ret) goto free_iommu; } ... if (iommu_identity_mapping) { ret = iommu_prepare_static_identity_mapping(hw_pass_through); if (ret) { pr_crit("Failed to setup IOMMU pass-through\n"); goto free_iommu; } } ... }
// 下面代码可以看出pass through模式不会设置iova页表地址 if (translation != CONTEXT_TT_PASS_THROUGH) { ... // 非pass through模式下需要设置iova页表的基地址 context_set_address_root(context, virt_to_phys(pgd)); context_set_address_width(context, agaw); } else { /* * In pass through mode, AW must be programmed to * indicate the largest AGAW value supported by * hardware. And ASR is ignored by hardware. */ context_set_address_width(context, iommu->msagaw); } ... }