Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2 8/9] mailbox: imx: Don't force-thread the primary handler
Date: Wed, 03 Jun 2026 14:31:08 +0000	[thread overview]
Message-ID: <20260603143109.19A6F1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603-imx_mbox_rproc-v2-8-a0059dc3b69a@linutronix.de>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [Medium] Double disable of priv->clk on devm_mbox_controller_register() failure.

Pre-existing issues:
- [High] Unchecked return value of pm_runtime_get_sync() leads to kernel panic.
- [High] Silent transmission failure due to ignored timeout error in imx_mu_generic_tx().
- [High] Polling jiffies and using time APIs with local interrupts disabled leads to hard lockups.
--

commit 91fcad059338175baa26f9a301cda6d0b62ba3ee
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

mailbox: imx: Don't force-thread the primary handler

This commit avoids force-threading the primary interrupt handler in the
IMX mailbox driver. It converts the xcr_lock to a raw_spinlock_t so the
primary handler can safely run in hardirq context, and marks the interrupt
with IRQF_NO_THREAD.

> diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c
> index f0a14449652f1..f3de47908e00f 100644
> --- a/drivers/mailbox/imx-mailbox.c
> +++ b/drivers/mailbox/imx-mailbox.c

[ ... ]

> @@ -649,7 +644,7 @@ static int imx_mu_startup(struct mbox_chan *chan)
>  {
>  	struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox);
>  	struct imx_mu_con_priv *cp = chan->con_priv;
> -	unsigned long irq_flag = 0;
> +	unsigned long irq_flag = IRQF_NO_THREAD;
>  	int ret;
>  
>  	pm_runtime_get_sync(priv->dev);

[Severity: High]
This is a pre-existing issue, but does this missing check for the return
value of pm_runtime_get_sync() risk a kernel panic?

If the device fails to resume (e.g., due to a clock enablement failure),
it remains in a suspended/unpowered state.

The function immediately proceeds to configure the device and access its
I/O registers. Accessing unpowered hardware registers can cause system
crashes, such as synchronous external aborts or bus hangs, on ARM platforms.

[ ... ]

While reviewing the driver, I noticed a few other potential regressions outside
the diff hunks above:

[Severity: High]
This is a pre-existing issue, but can the timeout loop in imx_mu_generic_tx()
lead to silent transmission failures?

When processing IMX_MU_TYPE_TXDB_V2, the code loops up to 10 times waiting
for the readl_poll_timeout() condition:

drivers/mailbox/imx-mailbox.c:imx_mu_generic_tx() {
    ...
    while (ret && (count < 10)) {
        ret = readl_poll_timeout(priv->base + priv->dcfg->xCR[IMX_MU_GCR], val,
                                 !(val & IMX_MU_xCR_GIRn(priv->dcfg->type, cp->idx)),
                                 0, 10000);
        if (ret) {
            dev_warn_ratelimited(...);
        }
    }
    break;
    ...
}

If all 10 attempts time out, ret is left as -ETIMEDOUT and the while loop
exits. The code then breaks from the switch block and unconditionally hits
return 0 at the end of the function instead of returning ret.

Falsely returning success causes the mailbox framework to drop the message,
leading to silent data loss. Should this return the error code instead?

[Severity: Medium]
Is there a double disable of priv->clk if devm_mbox_controller_register()
fails?

In imx_mu_probe(), the clock is manually disabled via clk_disable_unprepare()
after successfully syncing the PM runtime state:

drivers/mailbox/imx-mailbox.c:imx_mu_probe() {
    ...
    clk_disable_unprepare(priv->clk);

    ret = devm_mbox_controller_register(dev, &priv->mbox);
    if (ret)
        goto disable_clk;
    ...
disable_clk:
    clk_disable_unprepare(priv->clk);
    return ret;
}

If devm_mbox_controller_register() fails, the code branches to disable_clk,
which executes clk_disable_unprepare(priv->clk) a second time. This double
disable unbalances the clock reference count and triggers a kernel warning.

[Severity: High]
This is a pre-existing issue, but does the use of time APIs and polling
with local interrupts disabled lead to hard lockups?

Mailbox transmission (priv->dcfg->tx) is invoked via mbox_send_message()
with the channel lock (spin_lock_irqsave) held, meaning local interrupts
are disabled.

Inside imx_mu_tx_waiting_write(), the code polls a hardware register while
checking time_is_after_jiffies64():

drivers/mailbox/imx-mailbox.c:imx_mu_tx_waiting_write() {
    ...
    do {
        status = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_TSR]);
        can_write = status & IMX_MU_xSR_TEn(priv->dcfg->type, idx % 4);
    } while (!can_write && time_is_after_jiffies64(timeout_time));
    ...
}

Because interrupts are disabled, jiffies will not advance on UP systems,
causing an infinite loop (deadlock).

Additionally, imx_mu_specific_tx() uses readl_poll_timeout() with a
5-second timeout in this atomic context:

drivers/mailbox/imx-mailbox.c:imx_mu_specific_tx() {
    ...
    ret = readl_poll_timeout(priv->base + priv->dcfg->xSR[IMX_MU_TSR],
                             xsr,
                             xsr & IMX_MU_xSR_TEn(priv->dcfg->type, i % num_tr),
                             0, 5 * USEC_PER_SEC);
    ...
}

Spinning for up to 5 seconds with IRQs disabled violates core kernel
locking rules and can trigger NMI watchdogs and RCU stalls.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260603-imx_mbox_rproc-v2-0-a0059dc3b69a@linutronix.de?part=8

  reply	other threads:[~2026-06-03 14:31 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 13:05 [PATCH v2 0/9] mailbox: imx: Use threaded handler to avoid kworker in imx's remoteproc Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 1/9] mailbox: imx: Add a channel shutdown field Sebastian Andrzej Siewior
2026-06-03 13:20   ` sashiko-bot
2026-06-03 14:59     ` Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 2/9] mailbox: imx: Use devm_pm_runtime_enable() Sebastian Andrzej Siewior
2026-06-03 13:27   ` sashiko-bot
2026-06-03 15:00     ` Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 3/9] mailbox: imx: use devm_of_platform_populate() Sebastian Andrzej Siewior
2026-06-03 13:37   ` sashiko-bot
2026-06-03 15:01     ` Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 4/9] mailbox: imx: Use channel index instead of zero in imx_mu_specific_rx() Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 5/9] mailbox: imx: Start splitting the IRQ handler in primary and threaded handler Sebastian Andrzej Siewior
2026-06-03 13:58   ` sashiko-bot
2026-06-03 15:07     ` Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 6/9] mailbox: imx: Move the RX part of the mailbox into the " Sebastian Andrzej Siewior
2026-06-03 13:18   ` Daniel Baluta
2026-06-03 13:20     ` Sebastian Andrzej Siewior
2026-06-03 13:45       ` Daniel Baluta
2026-06-03 15:26         ` Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 7/9] mailbox: imx: Move the RXDB " Sebastian Andrzej Siewior
2026-06-03 14:19   ` sashiko-bot
2026-06-03 13:05 ` [PATCH v2 8/9] mailbox: imx: Don't force-thread the primary handler Sebastian Andrzej Siewior
2026-06-03 14:31   ` sashiko-bot [this message]
2026-06-03 15:20     ` Sebastian Andrzej Siewior
2026-06-03 13:05 ` [PATCH v2 9/9] remoteproc: imx_rproc: Invoke the callback directly Sebastian Andrzej Siewior
2026-06-03 14:45   ` sashiko-bot
2026-06-03 15:21     ` Sebastian Andrzej Siewior

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=20260603143109.19A6F1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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