zoukankan      html  css  js  c++  java
  • 如何判断iommu/smmu 是否能用

    /sys/class/iommu   ??

    /sys/kernel/iommu_groups  ??   

    vfio API ??

    转自  https://blog.csdn.net/tiantao2012/article/details/60756851        ?????

    https://stackoverflow.com/questions/44286683/check-for-iommu-support-on-linux

    我认为不能单单从 /sys/kernel/iommu_groups 下面是否为空来判断,因为在没有iommu的时候,若使用vfio+noiommu模式(echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode),  vfio 也会在 iommu_groups下面添加设备,此时该目录下非空,但其实iommu不能用。

    struct iommu_group *vfio_iommu_group_get(struct device *dev)
    {
     struct iommu_group *group;
     int __maybe_unused ret;
     group = iommu_group_get(dev);
    #ifdef CONFIG_VFIO_NOIOMMU
     /*
      * With noiommu enabled, an IOMMU group will be created for a device
      * that doesn't already have one and doesn't have an iommu_ops on their
      * bus.  We set iommudata simply to be able to identify these groups
      * as special use and for reclamation later.
      */
     if (group || !noiommu || iommu_present(dev->bus))
      return group;
     group = iommu_group_alloc();
     if (IS_ERR(group))
      return NULL;
     iommu_group_set_name(group, "vfio-noiommu");
     iommu_group_set_iommudata(group, &noiommu, NULL);
     ret = iommu_group_add_device(group, dev);
     if (ret) {
      iommu_group_put(group);
      return NULL;
     }
     /*
      * Where to taint?  At this point we've added an IOMMU group for a
      * device that is not backed by iommu_ops, therefore any iommu_
      * callback using iommu_ops can legitimately Oops.  So, while we may
      * be about to give a DMA capable device to a user without IOMMU
      * protection, which is clearly taint-worthy, let's go ahead and do
      * it here.
      */
     add_taint(TAINT_USER, LOCKDEP_STILL_OK);
     dev_warn(dev, "Adding kernel taint for vfio-noiommu group on device ");
    #endif
     return group;
    }
  • 相关阅读:
    219. Contains Duplicate II
    189. Rotate Array
    169. Majority Element
    122. Best Time to Buy and Sell Stock II
    121. Best Time to Buy and Sell Stock
    119. Pascal's Triangle II
    118. Pascal's Triangle
    88. Merge Sorted Array
    53. Maximum Subarray
    CodeForces 359D Pair of Numbers (暴力)
  • 原文地址:https://www.cnblogs.com/yi-mu-xi/p/12355584.html
Copyright © 2011-2022 走看看