首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查linux上是否支持IOMMU

检查linux上是否支持IOMMU
EN

Stack Overflow用户
提问于 2017-05-31 21:53:06
回答 1查看 42.6K关注 0票数 9

我想在任何给定的Linux机器上验证是否支持PCI passthrough。在谷歌了一下之后,我发现我应该检查IOMMU是否支持,我通过运行以下命令来实现:

代码语言:javascript
复制
dmesg | grep IOMMU   

如果它支持IOMMU (而不是IOMMUv2),我会得到:

代码语言:javascript
复制
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

...where DMAR: IOMMU enabled就是我要找的。

现在,如果机器已经运行了几天而没有重新启动,那么使用前面的命令,第一条消息[ 0.000000] DMAR: IOMMU enabled可能不会再出现在日志中。

当该消息从日志中消失时,有没有办法检查IOMMU支持?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-31 21:58:55

自2014年起,启用的iommu在/sys ( sysfs )特殊文件系统中注册为iommu类(在ABI/testing/sysfs-class-iommu中记录):https://patchwork.kernel.org/patch/4345491/ "2/3 IOMMU /英特尔:利用IOMMU sysfs支持“- 2014年6月12日

注册我们的DRHD IOMMU,交叉链接设备,并为IOMMU提供一组基本属性。..。在典型的桌面系统上,这提供了以下(修剪后的)功能:

$ 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)。

代码语言:javascript
复制
/*
 * 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:

代码语言:javascript
复制
if (intel_iommu_enabled) {
    iommu->iommu_dev = iommu_device_create(NULL, iommu,
                           intel_iommu_groups,
                           "%s", iommu->name);

AMD IOMMU:

代码语言:javascript
复制
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);

英特尔:

代码语言:javascript
复制
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.11Linux内核版本中,类是referenced in many IOMMU drivers,所以检查/sys/ iommu_device_sysfs_add / IOMMU比解析dmesg输出或在/var/log/kern.log/var/log/messages中搜索驱动程序特定的启用消息更好(更通用)地通过编程检测已启用的IOMMU:

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,line 797
  • drivers/iommu/mtk_iommu.c,line 581
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44286683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档