Skip to content

Commit b617018

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Remove pasid_mutex
The pasid_mutex was used to protect the paths of set/remove_dev_pasid(). It's duplicate with iommu_sva_lock. Remove it to avoid duplicate code. Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Jacob Pan <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent ac1a348 commit b617018

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

drivers/iommu/intel/svm.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,13 @@ static const struct mmu_notifier_ops intel_mmuops = {
259259
.invalidate_range = intel_invalidate_range,
260260
};
261261

262-
static DEFINE_MUTEX(pasid_mutex);
263-
264262
static int pasid_to_svm_sdev(struct device *dev, unsigned int pasid,
265263
struct intel_svm **rsvm,
266264
struct intel_svm_dev **rsdev)
267265
{
268266
struct intel_svm_dev *sdev = NULL;
269267
struct intel_svm *svm;
270268

271-
/* The caller should hold the pasid_mutex lock */
272-
if (WARN_ON(!mutex_is_locked(&pasid_mutex)))
273-
return -EINVAL;
274-
275269
if (pasid == IOMMU_PASID_INVALID || pasid >= PASID_MAX)
276270
return -EINVAL;
277271

@@ -371,22 +365,19 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev,
371365
return ret;
372366
}
373367

374-
/* Caller must hold pasid_mutex */
375-
static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
368+
void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid)
376369
{
377370
struct intel_svm_dev *sdev;
378371
struct intel_iommu *iommu;
379372
struct intel_svm *svm;
380373
struct mm_struct *mm;
381-
int ret = -EINVAL;
382374

383375
iommu = device_to_iommu(dev, NULL, NULL);
384376
if (!iommu)
385-
goto out;
377+
return;
386378

387-
ret = pasid_to_svm_sdev(dev, pasid, &svm, &sdev);
388-
if (ret)
389-
goto out;
379+
if (pasid_to_svm_sdev(dev, pasid, &svm, &sdev))
380+
return;
390381
mm = svm->mm;
391382

392383
if (sdev) {
@@ -418,8 +409,6 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
418409
kfree(svm);
419410
}
420411
}
421-
out:
422-
return ret;
423412
}
424413

425414
/* Page request queue descriptor */
@@ -520,19 +509,7 @@ static void intel_svm_drain_prq(struct device *dev, u32 pasid)
520509
goto prq_retry;
521510
}
522511

523-
/*
524-
* A work in IO page fault workqueue may try to lock pasid_mutex now.
525-
* Holding pasid_mutex while waiting in iopf_queue_flush_dev() for
526-
* all works in the workqueue to finish may cause deadlock.
527-
*
528-
* It's unnecessary to hold pasid_mutex in iopf_queue_flush_dev().
529-
* Unlock it to allow the works to be handled while waiting for
530-
* them to finish.
531-
*/
532-
lockdep_assert_held(&pasid_mutex);
533-
mutex_unlock(&pasid_mutex);
534512
iopf_queue_flush_dev(dev);
535-
mutex_lock(&pasid_mutex);
536513

537514
/*
538515
* Perform steps described in VT-d spec CH7.10 to drain page
@@ -827,26 +804,14 @@ int intel_svm_page_response(struct device *dev,
827804
return ret;
828805
}
829806

830-
void intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid)
831-
{
832-
mutex_lock(&pasid_mutex);
833-
intel_svm_unbind_mm(dev, pasid);
834-
mutex_unlock(&pasid_mutex);
835-
}
836-
837807
static int intel_svm_set_dev_pasid(struct iommu_domain *domain,
838808
struct device *dev, ioasid_t pasid)
839809
{
840810
struct device_domain_info *info = dev_iommu_priv_get(dev);
841811
struct intel_iommu *iommu = info->iommu;
842812
struct mm_struct *mm = domain->mm;
843-
int ret;
844813

845-
mutex_lock(&pasid_mutex);
846-
ret = intel_svm_bind_mm(iommu, dev, mm);
847-
mutex_unlock(&pasid_mutex);
848-
849-
return ret;
814+
return intel_svm_bind_mm(iommu, dev, mm);
850815
}
851816

852817
static void intel_svm_domain_free(struct iommu_domain *domain)

0 commit comments

Comments
 (0)