iommu: Avoid races around device probe
authorRobin Murphy <robin.murphy@arm.com>
Fri, 4 Nov 2022 19:51:43 +0000 (19:51 +0000)
committerJoerg Roedel <jroedel@suse.de>
Sat, 19 Nov 2022 09:17:42 +0000 (10:17 +0100)
commit01657bc14a3990c665375f77978631fee77b1fce
tree3328773667b49e9c7b8ef9c84c474982c95ec50c
parent69e61edebea030f177de7a23b8d5d9b8c4a90bda
iommu: Avoid races around device probe

We currently have 3 different ways that __iommu_probe_device() may be
called, but no real guarantee that multiple callers can't tread on each
other, especially once asynchronous driver probe gets involved. It would
likely have taken a fair bit of luck to hit this previously, but commit
57365a04c921 ("iommu: Move bus setup to IOMMU device registration") ups
the odds since now it's not just omap-iommu that may trigger multiple
bus_iommu_probe() calls in parallel if probing asynchronously.

Add a lock to ensure we can't try to double-probe a device, and also
close some possible race windows to make sure we're truly robust against
trying to double-initialise a group via two different member devices.

Reported-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Tested-by: Brian Norris <briannorris@chromium.org>
Fixes: 57365a04c921 ("iommu: Move bus setup to IOMMU device registration")
Link: https://lore.kernel.org/r/1946ef9f774851732eed78760a78ec40dbc6d178.1667591503.git.robin.murphy@arm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c