[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <98fc799d0cad52d6886ed1136e84a654b0065820.1751096303.git.nicolinc@nvidia.com>
Date: Sat, 28 Jun 2025 00:42:39 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: <jgg@...dia.com>, <joro@...tes.org>, <will@...nel.org>,
<robin.murphy@....com>, <rafael@...nel.org>, <lenb@...nel.org>,
<bhelgaas@...gle.com>
CC: <iommu@...ts.linux.dev>, <linux-kernel@...r.kernel.org>,
<linux-acpi@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<patches@...ts.linux.dev>, <pjaroszynski@...dia.com>, <vsethi@...dia.com>,
<helgaas@...nel.org>, <baolu.lu@...ux.intel.com>
Subject: [PATCH RFC v2 1/4] iommu: Lock group->mutex in iommu_deferred_attach
The iommu_deferred_attach() is a runtime asynchronous function called by
iommu-dma function, which will race against other attach functions if it
accesses something in the dev->iommu_group.
Grab the lock to protect it like others who call __iommu_attach_device()
as it will need to access dev->iommu_group.
Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
---
drivers/iommu/iommu.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index a4b606c591da..08ff7efa8925 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2151,10 +2151,14 @@ 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);
+ struct iommu_group *group = dev->iommu_group;
+ int ret = 0;
- return 0;
+ mutex_lock(&group->mutex);
+ if (dev->iommu && dev->iommu->attach_deferred)
+ ret = __iommu_attach_device(domain, dev);
+ mutex_unlock(&group->mutex);
+ return ret;
}
void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
--
2.43.0
Powered by blists - more mailing lists