iommu/vt-d: Remove users from intel_svm_dev
authorLu Baolu <baolu.lu@linux.intel.com>
Tue, 31 Jan 2023 07:37:31 +0000 (15:37 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 3 Feb 2023 10:06:02 +0000 (11:06 +0100)
It was used as a reference counter of an existing bond between device
and user application memory address. Commit be51b1d6bbff ("iommu/sva:
Refactoring iommu_sva_bind/unbind_device()") has added this in iommu
core. Remove it to avoid duplicate code.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20230109014955.147068-4-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/intel/iommu.h
drivers/iommu/intel/svm.c

index e7c732979364a6774da724952bc98a4f65c07511..2a1619ff0d798f118eff6365f3110e40e459fb77 100644 (file)
@@ -762,7 +762,6 @@ struct intel_svm_dev {
        struct device *dev;
        struct intel_iommu *iommu;
        struct iommu_sva sva;
-       int users;
        u16 did;
        u16 sid, qdep;
 };
index d1e445f03aa66d725627df47cad557fa3944ef99..c7dc53e40c26c490001aa7e942b37635857d3877 100644 (file)
@@ -333,13 +333,6 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
                }
        }
 
-       /* Find the matching device in svm list */
-       sdev = svm_lookup_device_by_dev(svm, dev);
-       if (sdev) {
-               sdev->users++;
-               goto success;
-       }
-
        sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
        if (!sdev) {
                ret = -ENOMEM;
@@ -350,7 +343,6 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
        sdev->iommu = iommu;
        sdev->did = FLPT_DEFAULT_DID;
        sdev->sid = PCI_DEVID(info->bus, info->devfn);
-       sdev->users = 1;
        sdev->sva.dev = dev;
        init_rcu_head(&sdev->rcu);
        if (info->ats_enabled) {
@@ -367,7 +359,7 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
                goto free_sdev;
 
        list_add_rcu(&sdev->list, &svm->devs);
-success:
+
        return &sdev->sva;
 
 free_sdev:
@@ -401,32 +393,32 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
        mm = svm->mm;
 
        if (sdev) {
-               sdev->users--;
-               if (!sdev->users) {
-                       list_del_rcu(&sdev->list);
-                       /* Flush the PASID cache and IOTLB for this device.
-                        * Note that we do depend on the hardware *not* using
-                        * the PASID any more. Just as we depend on other
-                        * devices never using PASIDs that they have no right
-                        * to use. We have a *shared* PASID table, because it's
-                        * large and has to be physically contiguous. So it's
-                        * hard to be as defensive as we might like. */
-                       intel_pasid_tear_down_entry(iommu, dev,
-                                                   svm->pasid, false);
-                       intel_svm_drain_prq(dev, svm->pasid);
-                       kfree_rcu(sdev, rcu);
-
-                       if (list_empty(&svm->devs)) {
-                               if (svm->notifier.ops)
-                                       mmu_notifier_unregister(&svm->notifier, mm);
-                               pasid_private_remove(svm->pasid);
-                               /* We mandate that no page faults may be outstanding
-                                * for the PASID when intel_svm_unbind_mm() is called.
-                                * If that is not obeyed, subtle errors will happen.
-                                * Let's make them less subtle... */
-                               memset(svm, 0x6b, sizeof(*svm));
-                               kfree(svm);
-                       }
+               list_del_rcu(&sdev->list);
+               /*
+                * Flush the PASID cache and IOTLB for this device.
+                * Note that we do depend on the hardware *not* using
+                * the PASID any more. Just as we depend on other
+                * devices never using PASIDs that they have no right
+                * to use. We have a *shared* PASID table, because it's
+                * large and has to be physically contiguous. So it's
+                * hard to be as defensive as we might like.
+                */
+               intel_pasid_tear_down_entry(iommu, dev, svm->pasid, false);
+               intel_svm_drain_prq(dev, svm->pasid);
+               kfree_rcu(sdev, rcu);
+
+               if (list_empty(&svm->devs)) {
+                       if (svm->notifier.ops)
+                               mmu_notifier_unregister(&svm->notifier, mm);
+                       pasid_private_remove(svm->pasid);
+                       /*
+                        * We mandate that no page faults may be outstanding
+                        * for the PASID when intel_svm_unbind_mm() is called.
+                        * If that is not obeyed, subtle errors will happen.
+                        * Let's make them less subtle...
+                        */
+                       memset(svm, 0x6b, sizeof(*svm));
+                       kfree(svm);
                }
        }
 out: