[PATCH] amba: Fix race condition during DMA configure at IOMMU probe time

From: Marek Szyprowski

Date: Mon Nov 16 2026 - 04:51:53 EST


amba_dma_configure() can be called from the IOMMU layer via
iommu_init_device() with iommu_probe_device_lock dropped, while the
driver core is concurrently binding a driver to the same device.
In that case dev->driver may change between the moment @drv is
computed at the function entry and the moment dev->driver is checked
again before dereferencing @drv:

Unable to handle kernel NULL pointer dereference at virtual address 00000000000000b8
...
pc : amba_dma_configure+0x3c/0x74
lr : amba_dma_configure+0x2c/0x74
...
Call trace:
amba_dma_configure+0x3c/0x74 (P)
__iommu_probe_device+0x408/0x4bc
probe_iommu_group+0x3c/0x64
bus_for_each_dev+0x7c/0xe0
iommu_device_register+0xd4/0x248
arm_smmu_device_probe+0xc08/0xea8
platform_probe+0x5c/0x9c
...

This has been observed on the Thundercomm RUBIK Pi 3 board, where the
deferred probe of the GPU SMMU raced with the probe of the CoreSight
AMBA devices.

Fix this the same way as it has been done for the platform bus in
commit 95deee37a123 ("platform: Fix race condition during DMA configure
at IOMMU probe time"): read dev->driver only once with READ_ONCE() and
use that local copy both for the NULL check and for accessing the
driver_managed_dma flag.

Fixes: bcb81ac6ae3c ("iommu: Get DT/ACPI parsing into the proper probe path")
Signed-off-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
---
The issue was observed on the real Thundercomm RubikPi3 board, then
analyzed with LLM assistance.

Best regards
Marek Szyprowski, PhD
Samsung R&D Institute Poland
---
drivers/amba/bus.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index d721d64a9858..bf0bc4f70134 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -324,7 +324,7 @@ static void amba_shutdown(struct device *dev)

static int amba_dma_configure(struct device *dev)
{
- struct amba_driver *drv = to_amba_driver(dev->driver);
+ struct device_driver *drv = READ_ONCE(dev->driver);
enum dev_dma_attr attr;
int ret = 0;

@@ -335,8 +335,8 @@ static int amba_dma_configure(struct device *dev)
ret = acpi_dma_configure(dev, attr);
}

- /* @drv may not be valid when we're called from the IOMMU layer */
- if (!ret && dev->driver && !drv->driver_managed_dma) {
+ /* @dev->driver may not be valid when we're called from the IOMMU layer */
+ if (!ret && drv && !to_amba_driver(drv)->driver_managed_dma) {
ret = iommu_device_use_default_domain(dev);
if (ret)
arch_teardown_dma_ops(dev);
--
2.43.0