mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Davis <afd@ti.com>
To: Nhat Tran <nhat.tranminhk2@gmail.com>, <nm@ti.com>,
	<ssantosh@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-omap@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH v2] soc: ti: wkup_m3_ipc: Fix NULL dereference when the M3 fails to boot
Date: Thu, 3 Dec 2026 13:17:34 -0600	[thread overview]
Message-ID: <80ed8a58-7c48-4374-8dfb-f931406c35c8@ti.com> (raw)
In-Reply-To: <20261203174139.55646-1-nhat.tranminhk2@gmail.com>

On 12/3/26 11:41 AM, Nhat Tran wrote:
> m3_ipc_state is set by the rproc boot thread only once rproc_boot()
> succeeds, while probe returns success regardless of the boot result.
> The pointer is used both to tell wkup_m3_ipc_get() that the M3 is
> available and as the only way remove() and the resume callback reach
> the driver state. 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
> both resuming from system sleep and unbinding the driver dereference it.
> 
> On a BeagleBone Black (AM335x) with the firmware missing:
> 
>    wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed
>    # echo devices > /sys/power/pm_test
>    # echo freeze > /sys/power/state
>    Unable to handle kernel NULL pointer dereference at virtual address 00000060 when read
>    Internal error: Oops: 5 [#1] SMP ARM
>    PC is at wkup_m3_ipc_resume+0xc/0x44 [wkup_m3_ipc]
>    LR is at dpm_run_callback+0x4c/0x208
>    Call trace:
>     wkup_m3_ipc_resume [wkup_m3_ipc] from dpm_run_callback+0x4c/0x208
>     dpm_run_callback from device_resume+0xf0/0x298
>     device_resume from dpm_resume+0x178/0x2dc
>     dpm_resume from dpm_resume_end+0xc/0x1c
>     dpm_resume_end from suspend_devices_and_enter+0x25c/0x9d4
>     suspend_devices_and_enter from pm_suspend+0x2f8/0x340
>     pm_suspend from state_store+0x68/0xc8
> 
> Unbinding the driver, directly or through the mailbox it depends on,
> oopses the same way in wkup_m3_ipc_remove().
> 
> Split the two uses. Set m3_ipc_state at the end of probe so it is valid
> for as long as the driver is bound, and add an 'available' flag that the
> boot thread sets once the M3 is running and remove() clears.
> wkup_m3_ipc_get() checks the flag, so pm33xx still defers its probe
> until the M3 has booted. The boot thread sets the flag through its own
> pointer because it is started before probe assigns m3_ipc_state.
> wkup_m3_ipc_put() keeps checking only the pointer, as it has to drop
> the reference taken by wkup_m3_ipc_get() whether or not the M3 is still
> running.
> 
> Tested on a BeagleBone Black:
>   - firmware missing: s2idle with pm_test=devices resumes without an
>     oops, and repeated unbind/bind cycles no longer oops
>   - firmware present: the M3 boots, pm33xx probes, and s2idle still
>     suspends and resumes
> 
> Fixes: cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver")
> Cc: stable@vger.kernel.org
> Suggested-by: Andrew Davis <afd@ti.com>
> Signed-off-by: Nhat Tran <nhat.tranminhk2@gmail.com>
> ---

Acked-by: Andrew Davis <afd@ti.com>

> v1 -> v2:
> - Instead of passing the state to remove() as driver data, keep
>    m3_ipc_state set from probe and track whether the M3 is running in a
>    separate flag, as suggested by Andrew Davis. This also fixes
>    the same NULL dereference in the resume callback, which v1 missed.
> - Retitled from "Use the device's own state in remove()".
> v1: https://lore.kernel.org/r/20261120141139.55783-1-nhat.tranminhk2@gmail.com
> ---
>   drivers/soc/ti/wkup_m3_ipc.c | 8 ++++++--
>   include/linux/wkup_m3_ipc.h  | 1 +
>   2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
> index eb6074a67ba3..7f9d67115ebf 100644
> --- a/drivers/soc/ti/wkup_m3_ipc.c
> +++ b/drivers/soc/ti/wkup_m3_ipc.c
> @@ -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 && m3_ipc_state->available)
>   		get_device(m3_ipc_state->dev);
>   	else
>   		return NULL;
> @@ -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->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 5e1b26f988e2..f4a8ab45ee30 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;


      reply	other threads:[~2026-12-03 19:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:41 Nhat Tran
2026-12-03 19:17 ` Andrew Davis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80ed8a58-7c48-4374-8dfb-f931406c35c8@ti.com \
    --to=afd@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=nhat.tranminhk2@gmail.com \
    --cc=nm@ti.com \
    --cc=ssantosh@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®