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>, Nishanth Menon <nm@ti.com>,
	"Santosh Shilimkar" <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] soc: ti: wkup_m3_ipc: Use the device's own state in remove()
Date: Thu, 3 Dec 2026 09:39:48 -0600	[thread overview]
Message-ID: <cb290ad3-b88b-4917-9561-57948f3ee1da@ti.com> (raw)
In-Reply-To: <20261120141139.55783-1-nhat.tranminhk2@gmail.com>

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;


  reply	other threads:[~2026-12-03 15:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 14:11 Nhat Tran
2026-12-03 15:39 ` Andrew Davis [this message]
2026-12-03 17:52   ` Nhat Tran
2026-12-03 19:21     ` Andrew Davis

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=cb290ad3-b88b-4917-9561-57948f3ee1da@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®