Skip to content

Commit 0c8e9c1

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Avoid introducing more races
Although the lock-juggling is only a temporary workaround, we don't want it to make things avoidably worse. Jason was right to be nervous, since bus_iommu_probe() doesn't care *which* IOMMU instance it's probing for, so it probably is possible for one walk to finish a probe which a different walk started, thus we do want to check for that. Also there's no need to drop the lock just to have of_iommu_configure() do nothing when a fwspec already exists; check that directly and avoid opening a window at all in that (still somewhat likely) case. Suggested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/09d901ad11b3a410fbb6e27f7d04ad4609c3fe4a.1741706365.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent 249d332 commit 0c8e9c1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/iommu/iommu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,15 @@ static int iommu_init_device(struct device *dev)
422422
* is buried in the bus dma_configure path. Properly unpicking that is
423423
* still a big job, so for now just invoke the whole thing. The device
424424
* already having a driver bound means dma_configure has already run and
425-
* either found no IOMMU to wait for, or we're in its replay call right
426-
* now, so either way there's no point calling it again.
425+
* found no IOMMU to wait for, so there's no point calling it again.
427426
*/
428-
if (!dev->driver && dev->bus->dma_configure) {
427+
if (!dev->iommu->fwspec && !dev->driver && dev->bus->dma_configure) {
429428
mutex_unlock(&iommu_probe_device_lock);
430429
dev->bus->dma_configure(dev);
431430
mutex_lock(&iommu_probe_device_lock);
431+
/* If another instance finished the job for us, skip it */
432+
if (!dev->iommu || dev->iommu_group)
433+
return -ENODEV;
432434
}
433435
/*
434436
* At this point, relevant devices either now have a fwspec which will

0 commit comments

Comments
 (0)