Commit 034d4731 authored by Jacob Pan's avatar Jacob Pan Committed by Joerg Roedel

iommu/vt-d: Misc macro clean up for SVM

Use combined macros for_each_svm_dev() to simplify SVM device iteration
and error checking.
Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarJacob Pan <jacob.jun.pan@linux.intel.com>
Reviewed-by: default avatarEric Auger <eric.auger@redhat.com>
Signed-off-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 5f75585e
...@@ -222,6 +222,10 @@ static const struct mmu_notifier_ops intel_mmuops = { ...@@ -222,6 +222,10 @@ static const struct mmu_notifier_ops intel_mmuops = {
static DEFINE_MUTEX(pasid_mutex); static DEFINE_MUTEX(pasid_mutex);
static LIST_HEAD(global_svm_list); static LIST_HEAD(global_svm_list);
#define for_each_svm_dev(sdev, svm, d) \
list_for_each_entry((sdev), &(svm)->devs, list) \
if ((d) != (sdev)->dev) {} else
int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ops *ops) int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ops *ops)
{ {
struct intel_iommu *iommu = intel_svm_device_to_iommu(dev); struct intel_iommu *iommu = intel_svm_device_to_iommu(dev);
...@@ -270,8 +274,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ ...@@ -270,8 +274,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
goto out; goto out;
} }
list_for_each_entry(sdev, &svm->devs, list) { /* Find the matching device in svm list */
if (dev == sdev->dev) { for_each_svm_dev(sdev, svm, dev) {
if (sdev->ops != ops) { if (sdev->ops != ops) {
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
...@@ -279,7 +283,6 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ ...@@ -279,7 +283,6 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
sdev->users++; sdev->users++;
goto success; goto success;
} }
}
break; break;
} }
...@@ -423,8 +426,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) ...@@ -423,8 +426,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)
goto out; goto out;
} }
list_for_each_entry(sdev, &svm->devs, list) { for_each_svm_dev(sdev, svm, dev) {
if (dev == sdev->dev) {
ret = 0; ret = 0;
sdev->users--; sdev->users--;
if (!sdev->users) { if (!sdev->users) {
...@@ -444,9 +446,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) ...@@ -444,9 +446,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)
ioasid_free(svm->pasid); ioasid_free(svm->pasid);
if (svm->mm) if (svm->mm)
mmu_notifier_unregister(&svm->notifier, svm->mm); mmu_notifier_unregister(&svm->notifier, svm->mm);
list_del(&svm->list); list_del(&svm->list);
/* We mandate that no page faults may be outstanding /* We mandate that no page faults may be outstanding
* for the PASID when intel_svm_unbind_mm() is called. * for the PASID when intel_svm_unbind_mm() is called.
* If that is not obeyed, subtle errors will happen. * If that is not obeyed, subtle errors will happen.
...@@ -457,7 +457,6 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) ...@@ -457,7 +457,6 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)
} }
break; break;
} }
}
out: out:
mutex_unlock(&pasid_mutex); mutex_unlock(&pasid_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment