在Linux上检查IOMMU支持 [英] check for IOMMU support on linux
问题描述
我想在任何给定的Linux机器上验证是否支持PCI直通.经过一番谷歌搜索后,我发现我宁愿检查是否支持IOMMU,我通过运行以下命令来做到这一点:
I'd like to verify on any given Linux machine if PCI passthrough is supported. After a bit of googling, I found that I should rather check if IOMMU is supported, and I did so by running:
dmesg | grep IOMMU
如果它支持IOMMU(而不是IOMMUv2),我会得到:
If it supports IOMMU (and not IOMMUv2), I would get:
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
...我要寻找的是DMAR: IOMMU enabled
.
...where DMAR: IOMMU enabled
is what I'm looking for.
现在,如果计算机已经运行了数天而没有重新启动,则使用先前的命令,第一条消息[ 0.000000] DMAR: IOMMU enabled
可能不再显示在日志中.
Now, if the machine has been running for days without a reboot, that first message [ 0.000000] DMAR: IOMMU enabled
might not appear any more in the log with the previous command.
当该消息从日志中消失时,是否有任何方法可以检查IOMMU支持?
Is there any way to check for IOMMU support when that message disappears from the log?
推荐答案
自2014年以来,启用的iommu在/sys(sysfs)特殊文件系统中注册为类iommu
(在 https://patchwork.kernel.org/patch/4345491/"[2/3] iommu/intel:利用IOMMU sysfs支持"-2014年6月12日
Since 2014 enabled iommu are registered in /sys (sysfs) special file system as class iommu
(documented at ABI/testing/sysfs-class-iommu):
https://patchwork.kernel.org/patch/4345491/ "[2/3] iommu/intel: Make use of IOMMU sysfs support" - June 12, 2014
注册我们的DRHD IOMMU,交叉链接设备,并提供基本设置 IOMMU的属性集. ... 在典型的桌面系统上,它提供以下内容(修剪):
Register our DRHD IOMMUs, cross link devices, and provide a base set of attributes for the IOMMU. ... On a typical desktop system, this provides the following (pruned):
$ 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
(
The code is iommu_device_create
(http://elixir.free-electrons.com/linux/v4.5/ident/iommu_device_create, around 4.5) or iommu_device_sysfs_add
(http://elixir.free-electrons.com/linux/v4.11/ident/iommu_device_sysfs_add) in more recent kernels.
/*
* 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, ...)
仅对已启用的IOMMU进行注册. DMAR:
Registration is done only for enabled IOMMU. DMAR:
if (intel_iommu_enabled) {
iommu->iommu_dev = iommu_device_create(NULL, iommu,
intel_iommu_groups,
"%s", iommu->name);
AMD IOMMU:
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);
英特尔:
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);
在4.11 linux内核版本中,iommu_device_sysfs_add
在许多IOMMU驱动程序中被引用 ,因此与解析dmesg
输出或在/var/log/kern.log
或/var/log/messages
中搜索特定于驱动程序的启用消息相比,检查/sys/class/iommu更好(更通用)来以编程方式检测已启用的IOMMU:>
With 4.11 linux kernel version iommu_device_sysfs_add
is referenced in many IOMMU drivers, so checking /sys/class/iommu is better (more universal) way to programmatically detect enabled IOMMU than parsing dmesg
output or searching in /var/log/kern.log
or /var/log/messages
for driver-specific enable messages:
引用10个文件:
Referenced in 10 files:
- 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行
- drivers/iommu/amd_iommu_init.c, line 1640
- drivers/iommu/arm-smmu-v3.c, line 2709
- drivers/iommu/arm-smmu.c, line 2163
- drivers/iommu/dmar.c, line 1083
- drivers/iommu/exynos-iommu.c, line 623
- drivers/iommu/intel-iommu.c, line 4878
- drivers/iommu/iommu-sysfs.c, line 57
- drivers/iommu/msm_iommu.c, line 797
- drivers/iommu/mtk_iommu.c, line 581
这篇关于在Linux上检查IOMMU支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!