我想在任何给定的Linux机器上验证是否支持PCI passthrough.经过一段谷歌搜索后,我发现我应该检查是否支持IOMMU,我这样做是通过运行:
dmesg | grep IOMMU
Run Code Online (Sandbox Code Playgroud)
如果它支持IOMMU(而不是IOMMUv2),我会得到:
IOMMU
[ 0.000000] DMAR: IOMMU enabled
[ 0.049734] DMAR-IR: IOAPIC id 8 under DRHD base 0xfbffc000 IOMMU 0
[ 0.049735] DMAR-IR: IOAPIC id 9 under DRHD base 0xfbffc000 IOMMU 0
[ 1.286567] AMD IOMMUv2 driver by Joerg Roedel <jroedel@suse.de>
[ 1.286568] AMD IOMMUv2 functionality not available on this system
Run Code Online (Sandbox Code Playgroud)
...... DMAR: IOMMU enabled我正在寻找的地方.
现在,如果计算机在没有重新启动的情况下运行了几天,那么[ 0.000000] DMAR: IOMMU enabled 使用上一个命令在日志中可能不再出现该第一条消息.
当该消息从日志中消失时,有没有办法检查IOMMU支持?
自2014年启用以来,iommu在/ sys(sysfs)特殊文件系统中注册为类iommu(在ABI/testing/sysfs-class-iommu中记录):https:
//patchwork.kernel.org/patch/4345491/ "[2/3 ] iommu/intel:利用IOMMU sysfs支持" - 2014年6月12日
注册我们的DRHD IOMMU,交叉链接设备,并为IOMMU提供一组基本属性....在典型的桌面系统上,这提供了以下(修剪):
Run Code Online (Sandbox Code Playgroud)$ find /sys | grep dmar /sys/devices/virtual/iommu/dmar0 ... /sys/class/iommu/dmar0 /sys/class/iommu/dmar1
代码是iommu_device_create(http://elixir.free-electrons.com/linux/v4.5/ident/iommu_device_create,大约4.5)或iommu_device_sysfs_add(http://elixir.free-electrons.com/linux/v4.11/ident/iommu_device_sysfs_add)在更新的内核中.
/*
* Create an IOMMU device and return a pointer to it. IOMMU specific
* attributes can be provided as an attribute group, allowing a unique
* namespace per IOMMU type.
*/
struct device *iommu_device_create(struct device *parent, void *drvdata,
const struct attribute_group **groups,
const char *fmt, ...)
Run Code Online (Sandbox Code Playgroud)
仅对启用的IOMMU进行注册.DMAR:
if (intel_iommu_enabled) {
iommu->iommu_dev = iommu_device_create(NULL, iommu,
intel_iommu_groups,
"%s", iommu->name);
Run Code Online (Sandbox Code Playgroud)
AMD IOMMU:
static int iommu_init_pci(struct amd_iommu *iommu)
{ ...
if (!iommu->dev)
return -ENODEV;
...
iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu,
amd_iommu_groups, "ivhd%d",
iommu->index);
Run Code Online (Sandbox Code Playgroud)
英特尔:
int __init intel_iommu_init(void)
{ ...
pr_info("Intel(R) Virtualization Technology for Directed I/O\n");
...
for_each_active_iommu(iommu, drhd)
iommu->iommu_dev = iommu_device_create(NULL, iommu,
intel_iommu_groups,
"%s", iommu->name);
Run Code Online (Sandbox Code Playgroud)
4.11 Linux内核版本在许多IOMMU驱动程序中iommu_device_sysfs_add被引用,因此检查/ sys/class/iommu是以编程方式检测启用的IOMMU比解析dmesg输出或搜索/var/log/kern.log或/var/log/messages驱动程序特定的启用消息更好(更通用)的方式:
引用10个文件:
- drivers/iommu/amd_iommu_init.c,第1640行
- drivers/iommu/arm-smmu-v3.c,第2709行
- drivers/iommu/arm-smmu.c,第2163行
- drivers/iommu/dmar.c,1083行
- drivers/iommu/exynos-iommu.c,第623行
- drivers/iommu/intel-iommu.c,第4878行
- drivers/iommu/iommu-sysfs.c,第57行
- drivers/iommu/msm_iommu.c,第797行
- drivers/iommu/mtk_iommu.c,第581行
| 归档时间: |
|
| 查看次数: |
17901 次 |
| 最近记录: |