Notes about iommu=pt kernel parameter
文章目录
当使用KVM pass-thru设备时,通常会设置intel_iommu=on iommu=pt
内核参数,其中intel_iommu=on
就是使能intel iommu,本文将介绍iommu=pt
。
本文参考的内核版本是v5.0。
identity mapping指的是iova与hpa 1:1映射。
1. Motivation
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;
2. 源码解析
2.1 pt
option解析
1 | static __init int iommu_setup(char *p) |
2.2 init_dmars
1 |
|
#define ecap_pass_through(e) ((e >> 6) & 0x1)
ecap_pass_through(iommu->ecap)
的含义是检查Extended Capability Register的PT
field。
如果Hardware supports pass-through translation type,那么hw_pass_through
为1;否则hw_pass_through
为0。
当iommu_pass_through
被设置时,iommu_identity_mapping
也会被设置。接着会依次调用si_domain_init
与iommu_prepare_static_identity_mapping
。
2.3 si_domain_init
1 | static int __init si_domain_init(int hw) |
从上述代码可知,当hw_pass_through
为1时,无需建立iova与hpa 1:1映射的iommu页表;否则需要对all usable memory建立iova与hpa 1:1映射的iommu页表。
2.4 iommu_prepare_static_identity_mapping
1 | iommu_prepare_static_identity_mapping |
1 | static int domain_context_mapping_one(struct dmar_domain *domain, |
#define CONTEXT_TT_PASS_THROUGH 2
因此CONTEXT_TT_PASS_THROUGH
为10b,即是2。
3. 总结
配置了iommu=pt
就会实现identity mapping:
- 如果Hardware supports pass-through translation type,则配置pass-through translation type即可实现identity mapping,此时无需配置iommu页表;
- 如果Hardware doesn’t support pass-through translation type,则需要配置iommu页表,使得iova与hpa 1:1映射。
当hw_pass_through
=0时,依然要走iommu页表,因此性能是不如hw_pass_through
=1的。
参考资料: