Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH 1/2] iommu: Take group lock before attaching device in iommu_deferred_attach()
@ 2024-05-28 16:39 Vasant Hegde
  2024-05-28 16:39 ` [PATCH 2/2] iommu/amd: Fix Invalid wait context issue Vasant Hegde
  2024-05-28 18:06 ` [PATCH 1/2] iommu: Take group lock before attaching device in iommu_deferred_attach() Robin Murphy
  0 siblings, 2 replies; 10+ messages in thread
From: Vasant Hegde @ 2024-05-28 16:39 UTC (permalink / raw)
  To: iommu, joro
  Cc: suravee.suthikulpanit, Vasant Hegde, Lianbo Jiang, Robin Murphy

Commit 3ab657291638 ("iommu: use the __iommu_attach_device() directly for deferred attach")
replaced iommu_attach_device() call with __iommu_attach_device(). But
missed to take group lock. Take lock before attaching device to domain.

Fixes: 3ab657291638 ("iommu: use the __iommu_attach_device() directly for deferred attach")
Cc: Lianbo Jiang <lijiang@redhat.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/iommu.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9df7cc75c1bc..1743dba023b6 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2114,10 +2114,19 @@ EXPORT_SYMBOL_GPL(iommu_attach_device);
 
 int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)
 {
-	if (dev->iommu && dev->iommu->attach_deferred)
-		return __iommu_attach_device(domain, dev);
+	int ret = 0;
+	struct iommu_group *group = dev->iommu_group;
 
-	return 0;
+	if (!group)
+		return -EINVAL;
+
+	if (dev->iommu && dev->iommu->attach_deferred) {
+		mutex_lock(&group->mutex);
+		ret = __iommu_attach_device(domain, dev);
+		mutex_unlock(&group->mutex);
+	}
+
+	return ret;
 }
 
 void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
-- 
2.31.1


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

end of thread, other threads:[~2024-06-24 16:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-28 16:39 [PATCH 1/2] iommu: Take group lock before attaching device in iommu_deferred_attach() Vasant Hegde
2024-05-28 16:39 ` [PATCH 2/2] iommu/amd: Fix Invalid wait context issue Vasant Hegde
2024-05-28 20:43   ` Chris Bainbridge
2024-05-29  6:35   ` Mikhail Gavrilov
2024-05-28 18:06 ` [PATCH 1/2] iommu: Take group lock before attaching device in iommu_deferred_attach() Robin Murphy
2024-05-29  7:24   ` Vasant Hegde
2024-06-10 17:44     ` Jason Gunthorpe
2024-06-24 14:20       ` Vasant Hegde
2024-06-24 15:25         ` Jason Gunthorpe
2024-06-24 16:02           ` Vasant Hegde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox