All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iommu: Fix iommu_sva_bind_device to the same domain
@ 2024-02-21 11:06 Zhangfei Gao
  2024-02-21 13:17 ` Jason Gunthorpe
  0 siblings, 1 reply; 4+ messages in thread
From: Zhangfei Gao @ 2024-02-21 11:06 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, jean-philippe, Jason Gunthorpe,
	baolu.lu, Zhang, Tina, kevin.tian
  Cc: iommu, linux-kernel, Zhangfei Gao

The accelerator device can provide multi-queue and bind to
the same domain in multi-thread for better performance,
and domain refcount takes care of it.

'commit 092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")'
removes the possibility, so fix it

Fixs: '092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")'
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
v2: Instead of checking ret == -EBUSY, 
    change iommu_attach_device_pasid return value from -EBUSY to 0
    when pasid entry is found, and refcount++ when return

 drivers/iommu/iommu-sva.c | 2 +-
 drivers/iommu/iommu.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index c3fc9201d0be..20b232c7675d 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -141,8 +141,8 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
 	struct device *dev = handle->dev;
 
 	mutex_lock(&iommu_sva_lock);
-	iommu_detach_device_pasid(domain, dev, iommu_mm->pasid);
 	if (--domain->users == 0) {
+		iommu_detach_device_pasid(domain, dev, iommu_mm->pasid);
 		list_del(&domain->next);
 		iommu_domain_free(domain);
 	}
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index d14413916f93..a16ade93db25 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3551,7 +3551,7 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
 	mutex_lock(&group->mutex);
 	curr = xa_cmpxchg(&group->pasid_array, pasid, NULL, domain, GFP_KERNEL);
 	if (curr) {
-		ret = xa_err(curr) ? : -EBUSY;
+		ret = xa_err(curr) ? : 0;
 		goto out_unlock;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-22  4:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-21 11:06 [PATCH v2] iommu: Fix iommu_sva_bind_device to the same domain Zhangfei Gao
2024-02-21 13:17 ` Jason Gunthorpe
2024-02-21 16:17   ` Zhangfei Gao
2024-02-22  4:11     ` Zhangfei Gao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.