* [PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove()
@ 2026-11-20 14:11 Nhat Tran
2026-12-03 15:39 ` Andrew Davis
0 siblings, 1 reply; 3+ messages in thread
From: Nhat Tran @ 2026-11-20 14:11 UTC (permalink / raw)
To: Nishanth Menon, Santosh Shilimkar
Cc: linux-arm-kernel, linux-omap, linux-kernel, Nhat Tran, stable
wkup_m3_ipc_remove() tears down the driver through the global
m3_ipc_state pointer. That pointer is only set by the rproc boot thread
once rproc_boot() succeeds, while probe returns success regardless of
the boot result. If the wkup_m3 firmware cannot be loaded, for example
because the driver is built in and probes before the root filesystem
holding am335x-pm-firmware.elf is mounted, m3_ipc_state stays NULL and
unbinding the driver dereferences it.
On a BeagleBone Black (AM335x):
wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed
# cd /sys/bus/platform/drivers/wkup_m3_ipc
# echo 44e11324.wkup_m3_ipc > unbind
Unable to handle kernel NULL pointer dereference at virtual address 00000064 when read
Internal error: Oops: 5 [#1] SMP ARM
PC is at wkup_m3_ipc_remove+0xc/0x48
LR is at device_release_driver_internal+0xbc/0x144
Call trace:
wkup_m3_ipc_remove from device_release_driver_internal+0xbc/0x144
device_release_driver_internal from unbind_store+0x50/0x74
unbind_store from kernfs_fop_write_iter+0x11c/0x1d4
kernfs_fop_write_iter from vfs_write+0x2a8/0x3f8
vfs_write from ksys_write+0x60/0xe0
ksys_write from ret_fast_syscall+0x0/0x54
The same happens when the mailbox the driver depends on is unbound.
Store the per-device state as driver data in probe and use it in
remove(), so the debugfs entries, the mailbox channel and the rproc
reference taken in probe are released whether or not the M3 was
booted. rproc_shutdown() already returns -EINVAL for a remote processor
that is not running.
Tested on a BeagleBone Black with the firmware not loaded at probe
time: unbinding the driver directly or through the mailbox no longer
oopses, and repeated unbind/bind cycles rebind and boot the M3 again.
Fixes: cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver")
Cc: stable@vger.kernel.org
Signed-off-by: Nhat Tran <nhat.tranminhk2@gmail.com>
---
drivers/soc/ti/wkup_m3_ipc.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
index eb6074a67ba3..224651955cda 100644
--- a/drivers/soc/ti/wkup_m3_ipc.c
+++ b/drivers/soc/ti/wkup_m3_ipc.c
@@ -695,6 +695,7 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
goto err_put_rproc;
}
+ platform_set_drvdata(pdev, m3_ipc);
wkup_m3_ipc_dbg_init(m3_ipc);
return 0;
@@ -708,12 +709,14 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
static void wkup_m3_ipc_remove(struct platform_device *pdev)
{
- wkup_m3_ipc_dbg_destroy(m3_ipc_state);
+ struct wkup_m3_ipc *m3_ipc = platform_get_drvdata(pdev);
- mbox_free_channel(m3_ipc_state->mbox);
+ wkup_m3_ipc_dbg_destroy(m3_ipc);
- rproc_shutdown(m3_ipc_state->rproc);
- rproc_put(m3_ipc_state->rproc);
+ mbox_free_channel(m3_ipc->mbox);
+
+ rproc_shutdown(m3_ipc->rproc);
+ rproc_put(m3_ipc->rproc);
m3_ipc_state = NULL;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove()
2026-11-20 14:11 [PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove() Nhat Tran
@ 2026-12-03 15:39 ` Andrew Davis
2026-12-03 17:52 ` Nhat Tran
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Davis @ 2026-12-03 15:39 UTC (permalink / raw)
To: Nhat Tran, Nishanth Menon, Santosh Shilimkar
Cc: linux-arm-kernel, linux-omap, linux-kernel, stable
On 11/20/26 8:11 AM, Nhat Tran wrote:
> wkup_m3_ipc_remove() tears down the driver through the global
> m3_ipc_state pointer. That pointer is only set by the rproc boot thread
> once rproc_boot() succeeds, while probe returns success regardless of
> the boot result. If the wkup_m3 firmware cannot be loaded, for example
> because the driver is built in and probes before the root filesystem
> holding am335x-pm-firmware.elf is mounted, m3_ipc_state stays NULL and
> unbinding the driver dereferences it.
>
> On a BeagleBone Black (AM335x):
>
> wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed
> # cd /sys/bus/platform/drivers/wkup_m3_ipc
> # echo 44e11324.wkup_m3_ipc > unbind
> Unable to handle kernel NULL pointer dereference at virtual address 00000064 when read
> Internal error: Oops: 5 [#1] SMP ARM
> PC is at wkup_m3_ipc_remove+0xc/0x48
> LR is at device_release_driver_internal+0xbc/0x144
> Call trace:
> wkup_m3_ipc_remove from device_release_driver_internal+0xbc/0x144
> device_release_driver_internal from unbind_store+0x50/0x74
> unbind_store from kernfs_fop_write_iter+0x11c/0x1d4
> kernfs_fop_write_iter from vfs_write+0x2a8/0x3f8
> vfs_write from ksys_write+0x60/0xe0
> ksys_write from ret_fast_syscall+0x0/0x54
>
> The same happens when the mailbox the driver depends on is unbound.
>
> Store the per-device state as driver data in probe and use it in
> remove(), so the debugfs entries, the mailbox channel and the rproc
> reference taken in probe are released whether or not the M3 was
> booted. rproc_shutdown() already returns -EINVAL for a remote processor
> that is not running.
>
> Tested on a BeagleBone Black with the firmware not loaded at probe
> time: unbinding the driver directly or through the mailbox no longer
> oopses, and repeated unbind/bind cycles rebind and boot the M3 again.
>
> Fixes: cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nhat Tran <nhat.tranminhk2@gmail.com>
> ---
Good find, but this fix is incomplete. You'll end up with the same NULL
dereference in `wkup_m3_ipc_resume()` should we go into suspend before
firmware is loaded, same for debugfs access before firmware.
The core issue is that `m3_ipc_state` being set is used both to signal
the core is available, and access the device structure in functions that
can't get it through other means. It would be betterto split these two
which also solves the issue here. Basically after probe `m3_ipc_state`
should always be set to prevent NULL dereference and a different signal
variable added/used for available check, something like:
> diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
> index eb6074a67ba3b..b351623079f16 100644
> --- a/drivers/soc/ti/wkup_m3_ipc.c
> +++ b/drivers/soc/ti/wkup_m3_ipc.c
> @@ -547,7 +547,7 @@ static const char *wkup_m3_request_wake_src(struct wkup_m3_ipc *m3_ipc)
> */
> static void wkup_m3_set_rtc_only(struct wkup_m3_ipc *m3_ipc)
> {
> - if (m3_ipc_state)
> + if (m3_ipc_state->available)
> m3_ipc_state->is_rtc_only = true;
> }
>
> @@ -569,7 +569,7 @@ static struct wkup_m3_ipc_ops ipc_ops = {
> */
> struct wkup_m3_ipc *wkup_m3_ipc_get(void)
> {
> - if (m3_ipc_state)
> + if (m3_ipc_state->available)
> get_device(m3_ipc_state->dev);
> else
> return NULL;
> @@ -584,7 +584,7 @@ EXPORT_SYMBOL_GPL(wkup_m3_ipc_get);
> */
> void wkup_m3_ipc_put(struct wkup_m3_ipc *m3_ipc)
> {
> - if (m3_ipc_state)
> + if (m3_ipc_state->available)
> put_device(m3_ipc_state->dev);
> }
> EXPORT_SYMBOL_GPL(wkup_m3_ipc_put);
> @@ -601,7 +601,7 @@ static int wkup_m3_rproc_boot_thread(void *arg)
> if (ret)
> dev_err(dev, "rproc_boot failed\n");
> else
> - m3_ipc_state = m3_ipc;
> + m3_ipc_state->available = true;
>
> return 0;
> }
> @@ -695,6 +695,8 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
> goto err_put_rproc;
> }
>
> + m3_ipc_state = m3_ipc;
> +
> wkup_m3_ipc_dbg_init(m3_ipc);
>
> return 0;
> @@ -708,6 +710,8 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
>
> static void wkup_m3_ipc_remove(struct platform_device *pdev)
> {
> + m3_ipc_state->available = false;
> +
> wkup_m3_ipc_dbg_destroy(m3_ipc_state);
>
> mbox_free_channel(m3_ipc_state->mbox);
> diff --git a/include/linux/wkup_m3_ipc.h b/include/linux/wkup_m3_ipc.h
> index 5e1b26f988e22..f4a8ab45ee306 100644
> --- a/include/linux/wkup_m3_ipc.h
> +++ b/include/linux/wkup_m3_ipc.h
> @@ -29,6 +29,7 @@ struct wkup_m3_ipc {
> int isolation_conf;
> int state;
> u32 halt;
> + bool available;
>
> unsigned long volt_scale_offsets;
> const char *sd_fw_name;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove()
2026-12-03 15:39 ` Andrew Davis
@ 2026-12-03 17:52 ` Nhat Tran
0 siblings, 0 replies; 3+ messages in thread
From: Nhat Tran @ 2026-12-03 17:52 UTC (permalink / raw)
To: afd; +Cc: nm, ssantosh, linux-arm-kernel, linux-omap, linux-kernel, stable
Dear Andrew,
> Good find, but this fix is incomplete. You'll end up with the same NULL
> dereference in `wkup_m3_ipc_resume()` should we go into suspend before
> firmware is loaded, same for debugfs access before firmware.
Thanks, you're right. I tested it on v1 and resume crashes too when
the firmware is missing.
> The core issue is that `m3_ipc_state` being set is used both to signal
> the core is available, and access the device structure in functions that
> can't get it through other means. It would be betterto split these two
> which also solves the issue here.
I sent v2 with this approach:
https://lore.kernel.org/r/20261203174139.55646-1-nhat.tranminhk2@gmail.com
I changed a few small things from your diff:
>> struct wkup_m3_ipc *wkup_m3_ipc_get(void)
>> {
>> - if (m3_ipc_state)
>> + if (m3_ipc_state->available)
>> get_device(m3_ipc_state->dev);
m3_ipc_state can still be NULL here, e.g. if pm33xx probes before
wkup_m3_ipc. So I kept the NULL check:
if (m3_ipc_state && m3_ipc_state->available)
>> void wkup_m3_ipc_put(struct wkup_m3_ipc *m3_ipc)
>> {
>> - if (m3_ipc_state)
>> + if (m3_ipc_state->available)
>> put_device(m3_ipc_state->dev);
>> }
I left put() as it was. It should drop the reference even if the M3 is
no longer available. Also m3_ipc_state is NULL again after remove(), so
this would crash if pm33xx is removed after wkup_m3_ipc.
>> @@ -601,7 +601,7 @@ static int wkup_m3_rproc_boot_thread(void *arg)
>> if (ret)
>> dev_err(dev, "rproc_boot failed\n");
>> else
>> - m3_ipc_state = m3_ipc;
>> + m3_ipc_state->available = true;
The thread starts before probe sets m3_ipc_state, so I used
m3_ipc->available here instead.
Best Regards,
Nhat Tran
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 17:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 14:11 [PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove() Nhat Tran
2026-12-03 15:39 ` Andrew Davis
2026-12-03 17:52 ` Nhat Tran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox