From: sashiko-bot@kernel.org
To: "Francesco Valla" <francesco@valla.it>
Cc: devicetree@vger.kernel.org, imx@lists.linux.dev, robh@kernel.org,
conor+dt@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH RFC v2 09/11] remoteproc: imx_rproc: always use non-blocking mailboxes
Date: Mon, 02 Nov 2026 00:03:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-192789@kernel.org> (raw)
In-Reply-To: <20261102-remoteproc_virtio_map-v2-9-26b300e01c62@valla.it>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] remoteproc: imx_rproc: memory leak of mmsg in imx_rproc_kick() on mbox abort
--
commit 059fe2437ad2cd1bd7152b14297e2a685bc5d803
Author: Francesco Valla <francesco@valla.it>
remoteproc: imx_rproc: always use non-blocking mailboxes
This commit switches the i.MX remoteproc mailbox client to non-blocking
mode, dynamically allocating and freeing kick messages via the tx_done
callback, and removes the sys_off handler that previously reopened the
mailbox in non-blocking mode during system shutdown and restart.
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index 581bb07f5893f..a792b9ca5edd1 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
[ ... ]
> @@ -696,28 +696,45 @@ static void imx_rproc_kick(struct rproc *rproc, int vqid)
> {
> struct imx_rproc *priv = rproc->priv;
> int err;
> - __u32 mmsg;
> + __u32 *mmsg;
>
> if (!priv->tx_ch) {
> dev_err(priv->dev, "No initialized mbox tx channel\n");
> return;
> }
>
> + mmsg = kzalloc_obj(*mmsg, GFP_ATOMIC);
> + if (!mmsg) {
> + dev_err_ratelimited(priv->dev, "cannot allocate kick message\n");
> + return;
> + }
> +
> /*
> * Send the index of the triggered virtqueue as the mu payload.
> * Let remote processor know which virtqueue is used.
> */
> - mmsg = vqid << 16;
> + *mmsg = vqid << 16;
>
> - err = mbox_send_message(priv->tx_ch, (void *)&mmsg);
> - if (err < 0)
> + err = mbox_send_message(priv->tx_ch, (void *)mmsg);
> + if (err < 0) {
> dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
> __func__, vqid, err);
> + kfree(mmsg);
> + }
> +}
> +
> +static void imx_rproc_kick_tx_done(struct mbox_client *cl, void *mmsg, int r)
> +{
> + if (r != 0)
> + dev_err_ratelimited(cl->dev, "failed to kick vqid %u: %d\n",
> + *(__u32 *)mmsg >> 16, r);
> +
> + kfree(mmsg);
> }
[Severity: High]
Does this leak mmsg when the mailbox channel is freed or when transmission
does not complete with a tx_done callback?
In imx_rproc_kick(), once mbox_send_message() returns a non-negative ring
buffer index, freeing mmsg relies solely on imx_rproc_kick_tx_done() being
called from tx_tick().
However, there are several paths where imx_rproc_kick_tx_done() is never
invoked for a queued or active mmsg:
1. When imx_rproc_free_mbox() calls mbox_free_channel(priv->tx_ch) during
stop, detach, crash recovery, or driver teardown,
mbox_free_channel()->mbox_clean_and_put_channel() aborts the active request
and all queued requests without invoking cl->tx_done:
drivers/mailbox/mailbox.c:mbox_clean_and_put_channel() {
/* The queued TX requests are simply aborted, no callbacks are made */
scoped_guard(spinlock_irqsave, &chan->lock) {
chan->cl = NULL;
chan->active_req = MBOX_NO_MSG;
if (chan->txdone_method == MBOX_TXDONE_BY_ACK)
chan->txdone_method = MBOX_TXDONE_BY_POLL;
}
...
}
Any in-flight kick in chan->active_req (such as kicks sent by virtio
subdevices during rproc_stop_subdevices() right before imx_rproc_stop()) or
queued kicks in chan->msg_data[] (for example, when the remote processor
crashes or stops reading the MU register) will be leaked.
2. In mbox_send_message()->msg_submit(), if chan->mbox->ops->send_data()
returns an error, chan->active_req is not set and mmsg remains in
chan->msg_data[] without tx_done being called, while mbox_send_message()
still returns the non-negative slot index t to imx_rproc_kick().
3. For IMX_MU_TYPE_TXDB_V2 channels, imx_mu_xlate() configures
txdone_method as MBOX_TXDONE_BY_ACK, while imx_rproc_xtr_mbox_init() sets
cl->knows_txdone = false and never calls mbox_client_txdone(), so tx_tick()
and imx_rproc_kick_tx_done() are never called.
Since mbox_send_message() only stores the void * pointer in
chan->msg_data[] and passes it to send_data(), could vqid (or vqid << 16)
be encoded directly in the pointer via uintptr_t or stored in a preallocated
per-vq/per-device array instead of dynamically allocating mmsg on every
kick?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102-remoteproc_virtio_map-v2-0-26b300e01c62@valla.it?part=9
next prev parent reply other threads:[~2026-11-02 0:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 23:26 [PATCH RFC v2 00/11] remoteproc: add support for any virtio device Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 01/11] remoteproc: virtio: cleanup rproc_add_virtio_dev error path Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 02/11] remoteproc: virtio: replace commas with semicolons Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 03/11] remoteproc: virtio: support dynamic number of vrings Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 04/11] remoteproc: report VIRTIO_F_VERSION_1 for non-rproc-specific vdevs Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 05/11] remoteproc: virtio: report VIRTIO_F_ACCESS_PLATFORM when required Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 06/11] dt-bindings: remoteproc: add remoteproc-virtio Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 07/11] remoteproc: assign fwnode during vdev registration Francesco Valla
2026-11-02 0:02 ` sashiko-bot
2026-11-01 23:26 ` [PATCH RFC v2 08/11] Documentation: remoteproc: expand virtio support section Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 09/11] remoteproc: imx_rproc: always use non-blocking mailboxes Francesco Valla
2026-11-02 0:03 ` sashiko-bot [this message]
2026-11-01 23:26 ` [PATCH RFC v2 10/11] dt-bindings: remoteproc: imx-rproc: support virtio Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 11/11] PoC: arm64: dts: imx93-11x11-frdm: add multiple vdevs Francesco Valla
2026-11-02 0:16 ` sashiko-bot
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=sashiko-outbox-192789@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=francesco@valla.it \
--cc=imx@lists.linux.dev \
--cc=robh@kernel.org \
--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