[PATCH] amba: Don't probe devices without valid match ID

From: Linus Walleij
Date: Mon Aug 29 2022 - 16:26:11 EST


After the recent changes to the AMBA bus core, QEMU Versatile
Express (and probably other machines) refuse to boot properly
in the v6.0-rc1 thru -rc3 kernels.

After enabling earlydebug this kind of stuff comes out:

Unable to handle kernel NULL pointer dereference at virtual address 00000008
[00000008] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc1+ #474
Hardware name: ARM-Versatile Express
PC is at pl031_probe+0x18/0x224
LR is at amba_probe+0xf0/0x174

This is because the AMBA driver probe call is called with an id
argument that is NULL while drivers often directly dereference
this ID to get to the match data.

This happens when an AMBA device exist in the device tree, but
it is lacking any PrimceCell ID in hardware so there is no match
data.

This happens most typically in QEMU which tries to mimic e.g.
Versatile Express, but several PrimeCells that exist in the
physical platform are not implemented or incomplete in the
QEMU model so only zeroes are returned when reading the PrimeCell
ID and thus there is no match data.

Fix this by not probing the device if there is no ID.

This print from QEMU after applying the patch shows clearly
what blocks are missing from QEMU:

1c0f0000.watchdog: no ID for device, skipping probe
(QEMU incomplete device?)
2b0a0000.memory-controller: no ID for device, skipping probe
(QEMU incomplete device?)
7ffd0000.memory-controller: no ID for device, skipping probe
(QEMU incomplete device?)
7ffb0000.dma: no ID for device, skipping probe
(QEMU incomplete device?)

Fixes: f2d3b9a46e0e ("ARM: 9220/1: amba: Remove deferred device addition")
Cc: Saravana Kannan <saravanak@xxxxxxxxxx>
Cc: Sudeep Holla <sudeep.holla@xxxxxxx>
Cc: qemu-devel@xxxxxxxxxx
Cc: Peter Maydell <peter.maydell@xxxxxxxxxx>
Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
---
drivers/amba/bus.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 32b0e0b930c1..6a1bffc60169 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -300,9 +300,14 @@ static int amba_probe(struct device *dev)
pm_runtime_set_active(dev);
pm_runtime_enable(dev);

- ret = pcdrv->probe(pcdev, id);
- if (ret == 0)
- break;
+ if (!id) {
+ pr_err("%s: no ID for device, skipping probe (QEMU
incomplete device?)\n",
+ dev_name(dev));
+ } else {
+ ret = pcdrv->probe(pcdev, id);
+ if (ret == 0)
+ break;
+ }

pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
--
2.37.2

Yours,
Linus Walleij