Re: [PATCH] ARM: 9220/1: amba: Add sanity check for dev->periphid in amba_probe()

From: Linus Walleij
Date: Mon Aug 29 2022 - 17:01:17 EST


On Sat, Aug 27, 2022 at 12:22 PM Zhen Lei <thunder.leizhen@xxxxxxxxxx> wrote:

> Commit f2d3b9a46e0e ("ARM: 9220/1: amba: Remove deferred device addition")
> forcibly invokes device_add() even if dev->periphid is not ready. Although
> it will be remedied in amba_match(): dev->periphid will be initialized
> if everything is in place; Otherwise, return -EPROBE_DEFER to block
> __driver_attach() from further execution. But not all drivers have .match
> hook, such as pl031, the dev->bus->probe will be called directly in
> __driver_attach(). Unfortunately, if dev->periphid is still not
> initialized, the following exception will be triggered.
>
> 8<--- cut here ---
> Unable to handle kernel NULL pointer dereference at virtual address 00000008
> [00000008] *pgd=00000000
> Internal error: Oops: 5 [#1] SMP ARM
> Modules linked in:
> CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc2+ #7
> Hardware name: ARM-Versatile Express
> PC is at pl031_probe+0x8/0x208
> LR is at amba_probe+0xf0/0x160
> pc : 80698df8 lr : 8050eb54 psr: 80000013
> sp : c0825df8 ip : 00000000 fp : 811fda38
> r10: 00000000 r9 : 80d72470 r8 : fffffdfb
> r7 : 811fd800 r6 : be7eb330 r5 : 00000000 r4 : 811fd900
> r3 : 80698df0 r2 : 37000000 r1 : 00000000 r0 : 811fd800
> Flags: Nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
> Control: 10c5387d Table: 6000406a DAC: 00000051
> ... ...
> pl031_probe from amba_probe+0xf0/0x160
> amba_probe from really_probe+0x118/0x290
> really_probe from __driver_probe_device+0x84/0xe4
> __driver_probe_device from driver_probe_device+0x30/0xd0
> driver_probe_device from __driver_attach+0x8c/0xfc
> __driver_attach from bus_for_each_dev+0x70/0xb0
> bus_for_each_dev from bus_add_driver+0x168/0x1f4
> bus_add_driver from driver_register+0x7c/0x118
> driver_register from do_one_initcall+0x44/0x1ec
> do_one_initcall from kernel_init_freeable+0x238/0x288
> kernel_init_freeable from kernel_init+0x18/0x12c
> kernel_init from ret_from_fork+0x14/0x2c
> ... ...
> ---[ end trace 0000000000000000 ]---
>
> Therefore, take the same action as in amba_match(): return -EPROBE_DEFER
> if dev->periphid is not ready in amba_probe().
>
> Fixes: f2d3b9a46e0e ("ARM: 9220/1: amba: Remove deferred device addition")
> Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>

For the record, this makes Vexpress QEMU boot again for me, so
Tested-by: Linus Walleij <linus.walleij@xxxxxxxxxx>

The problem on QEMU is however not that the device is "not ready"
the device is simply not there, the implementation in QEMU
is incomplete. What platform are you getting this on? If it's QEMU
you probably need to alter the commit message. I made this similar patch: