Re: [PATCH 1/2] iommu/vt-d: Use rbtree to track iommu probed devices

From: Ethan Zhao
Date: Mon Feb 19 2024 - 00:33:42 EST


On 2/19/2024 12:04 PM, Baolu Lu wrote:
On 2024/2/19 10:45, Ethan Zhao wrote:
@@ -4264,25 +4313,34 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
      }
      dev_iommu_priv_set(dev, info);
+    ret = device_rbtree_insert(iommu, info);
+    if (ret)
+        goto free;
      if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
          ret = intel_pasid_alloc_table(dev);
          if (ret) {
              dev_err(dev, "PASID table allocation failed\n");
-            kfree(info);
-            return ERR_PTR(ret);
+            goto clear_rbtree;
          }
      }
      intel_iommu_debugfs_create_dev(info);
      return &iommu->iommu;
+clear_rbtree:
+    device_rbtree_remove(info);
+free:
+    kfree(info);
+
+    return ERR_PTR(ret);
  }
  static void intel_iommu_release_device(struct device *dev)
  {
      struct device_domain_info *info = dev_iommu_priv_get(dev);
+    device_rbtree_remove(info);

Perhpas too early here to remove dev from the rbtree, if it is wanted in
devTLB invalidation steps in intel_pasid_tear_down_entry().

Perhaps the caller of device_rbtree_find() should not depend on the

I didn't catch up here. seems have to maintain the lifecycle as PCI subsystem
does, or there would be mutli instances for the same BDF(e.g. the device is
removed then plugged, again and again.....in the same slot) in the rbtree ?

order in the release_device callback. For the device TLB invalidation
timed-out case, probably it could be checked in this way:

    struct device *dev = device_rbtree_find(iommu, ite_sid);
    if (!dev || !pci_device_is_present(to_pci_dev(dev)))
        return -ETIMEDOUT;

looks much advanced with such infrastructure !

Thanks,
Ethan


Best regards,
baolu