From: sashiko-bot@kernel.org
To: "Ben Levinsky" <ben.levinsky@amd.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 4/4] remoteproc: amd_mbv_bram: Add RPMsg support
Date: Thu, 03 Dec 2026 19:28:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-248503@kernel.org> (raw)
In-Reply-To: <20261203175731.661503-5-ben.levinsky@amd.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] remoteproc: amd_mbv_bram: active RX mailbox races with stop and
vdev teardown
- [Medium] remoteproc: amd_mbv_bram: active TX mailbox polls and leaks
kicks after stop
- [Medium] remoteproc: amd_mbv_bram: unmapped vdev0buffer added to
coredump segments
- [Medium] remoteproc: amd_mbv_bram: leaked carveouts on
amd_bram_rproc_prepare() error
- [Medium] remoteproc: amd_mbv_bram: data race on queued notify_msgs in
kick()
- [Medium] remoteproc: amd_mbv_bram: amd_bram_rproc_kick() overflows
mailbox TX queue
- [Low] remoteproc: amd_mbv_bram: depends on MAILBOX drops existing
configs
- [Low] remoteproc: amd_mbv_bram: 256 unconditional devm_kzalloc() calls
in probe()
- [Low] remoteproc: amd_mbv_bram: dev_err_probe() called outside probe
context
--
commit 77f2bab5da4ee3427bc1be754e757411f2fd9e70
Author: Ben Levinsky <ben.levinsky@amd.com>
remoteproc: amd_mbv_bram: Add RPMsg support
This commit adds optional RPMsg support to the AMD MicroBlaze/V BRAM
remoteproc driver using the mailbox framework for virtqueue
notifications and reserved memory regions for vrings and the buffer
pool.
> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
> index 70dec8c3fe4ec..2d3c51cbcbad8 100644
> --- a/drivers/remoteproc/Kconfig
> +++ b/drivers/remoteproc/Kconfig
> @@ -26,10 +26,15 @@ config REMOTEPROC_CDEV
> config AMD_MBV_BRAM_REMOTEPROC
> tristate "AMD MicroBlaze/V BRAM-based remoteproc support"
> depends on OF && COMMON_CLK && (GPIOLIB || COMPILE_TEST)
> + depends on MAILBOX
[Severity: Low]
Will adding "depends on MAILBOX" silently drop AMD_MBV_BRAM_REMOTEPROC
from existing configurations that do not enable MAILBOX?
MAILBOX has no Kconfig dependencies, and the other mailbox-using
remoteproc drivers in this file (such as IMX_REMOTEPROC and
XLNX_R5_REMOTEPROC) use "select MAILBOX" instead. Using "select
MAILBOX" would preserve existing configs.
> diff --git a/drivers/remoteproc/amd_mbv_bram_rproc.c b/drivers/remoteproc/amd_mbv_bram_rproc.c
> index e4a103cf84558..0b54a6cc3e62b 100644
> --- a/drivers/remoteproc/amd_mbv_bram_rproc.c
> +++ b/drivers/remoteproc/amd_mbv_bram_rproc.c
[ ... ]
> +static void amd_bram_rproc_kick(struct rproc *rproc, int vqid)
> +{
> + struct amd_bram_rproc *priv = rproc->priv;
> + struct zynqmp_ipi_message *msg;
> + int ret;
> +
> + if (!priv->tx_chan) {
> + dev_warn_ratelimited(priv->dev,
> + "cannot kick vq%d: no TX mailbox\n", vqid);
> + return;
> + }
> +
> + if (vqid < 0 || vqid >= ARRAY_SIZE(priv->notify_msgs)) {
> + dev_err_ratelimited(priv->dev, "invalid notify id %d\n", vqid);
> + return;
> + }
> +
> + /*
> + * The mailbox core queues message pointers. Keep each notification word
> + * in persistent storage until the controller reports TX completion.
> + */
> + msg = priv->notify_msgs[vqid];
> + msg->len = sizeof(u32);
> + memcpy(msg->data, &vqid, sizeof(u32));
[Severity: Medium]
Does writing msg->len and msg->data on every kick race with the mailbox
controller reading a previously queued priv->notify_msgs[vqid]?
Because tx_block is false, mbox_send_message() queues the pointer and
returns immediately. A back-to-back kick for the same vqid can rewrite
msg->len and msg->data while txdone_hrtimer() -> msg_submit() ->
amd_pl_mbox_send_data() is concurrently reading them, violating the
mbox_send_message() lifetime contract and triggering KCSAN data races.
Since both fields are constant for a given vqid, initializing
priv->notify_msgs[i] once during probe makes the buffers immutable.
> + /* Order writes to WC vring mappings before notifying the remote. */
> + wmb();
> + ret = mbox_send_message(priv->tx_chan, msg);
> + if (ret < 0)
> + dev_err_ratelimited(priv->dev, "failed to kick vq%d: %d\n",
> + vqid, ret);
> +}
[Severity: Medium]
Can bursty RPMsg sends overflow the mailbox TX queue on priv->tx_chan?
rpmsg_send_offchannel_raw() kicks svq on every message with up to 256 TX
buffers, while amd-pl-mailbox polls TX completion every 1 ms until the
remote drains the TX FIFO. A burst of more than 20 sends within that
1 ms window fills all MBOX_TX_QUEUE_LEN slots with duplicate svq kicks.
Further kicks then fail with -ENOBUFS, emit un-ratelimited dev_err()
messages from mbox_send_message(), and can drop rvq buffer-replenishment
kicks from rpmsg_recv_done(). Coalescing pending TX kicks per vqid
(for example with a pending bitmap drained from a tx_done callback)
would prevent queue overflow and rvq starvation.
[ ... ]
> +static int amd_bram_rproc_get_reserved_mem(struct amd_bram_rproc *priv, int i,
> + const char **name,
> + struct resource *res)
> +{
> + struct device_node *np = priv->dev->of_node;
> + int ret;
> +
> + ret = of_property_read_string_index(np, "memory-region-names", i, name);
> + if (ret)
> + return dev_err_probe(priv->dev, ret,
> + "failed to read memory-region name %d\n", i);
> +
> + ret = of_reserved_mem_region_to_resource(np, i, res);
> + if (ret)
> + return dev_err_probe(priv->dev, ret,
> + "failed to parse memory-region %d\n", i);
> +
> + /* The remote uses the physical address as device address. */
> + if (res->end > U32_MAX)
> + return dev_err_probe(priv->dev, -EINVAL,
> + "memory-region %d %pR is above 4 GiB\n",
> + i, res);
> +
> + return 0;
> +}
[Severity: Low]
Should these error paths use dev_err() instead of dev_err_probe()?
amd_bram_rproc_get_reserved_mem() is only called from
amd_bram_rproc_prepare() at boot time, not from probe, and the other
error paths in amd_bram_rproc_prepare() use dev_err().
[ ... ]
> +static int amd_bram_rproc_add_reserved_mem(struct rproc *rproc)
> +{
> + struct amd_bram_rproc *priv = rproc->priv;
> + struct rproc_mem_entry *mem;
> + int count;
> + int ret;
> + int i;
> +
> + count = amd_bram_rproc_reserved_mem_count(priv);
> + if (count < 0)
> + return count;
> +
> + for (i = 0; i < count; i++) {
> + struct resource res;
> + const char *name;
> +
> + ret = amd_bram_rproc_get_reserved_mem(priv, i, &name, &res);
> + if (ret)
> + return ret;
> +
> + if (!strcmp(name, "vdev0buffer"))
> + mem = rproc_of_resm_mem_entry_init(priv->dev, i,
> + resource_size(&res),
> + res.start, name);
> + else
> + mem = rproc_mem_entry_init(priv->dev, NULL,
> + (dma_addr_t)res.start,
> + resource_size(&res), res.start,
> + rproc_mem_entry_ioremap_wc,
> + rproc_mem_entry_iounmap,
> + "%s", name);
> + if (!mem)
> + return -ENOMEM;
> +
> + rproc_add_carveout(rproc, mem);
> + rproc_coredump_add_segment(rproc, res.start, resource_size(&res));
> + dev_dbg(priv->dev, "reserved memory carveout %pR\n", &res);
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Should vdev0buffer be excluded from rproc_coredump_add_segment()?
rproc_of_resm_mem_entry_init() leaves mem->va NULL and the driver has no
.da_to_va callback. During a coredump, rproc_da_to_va() skips carveouts
with !carveout->va, so rproc_copy_segment() logs an error and fills the
vdev0buffer segment with 0xff.
[ ... ]
> @@ -68,6 +326,10 @@ static int amd_bram_rproc_prepare(struct rproc *rproc)
> return ret;
> }
>
> + ret = amd_bram_rproc_check_reserved_mem(priv);
> + if (ret)
> + return ret;
> +
> mem = rproc_mem_entry_init(priv->dev, NULL, (dma_addr_t)res.start,
> resource_size(&res), da,
> rproc_mem_entry_ioremap_wc,
> @@ -79,7 +341,7 @@ static int amd_bram_rproc_prepare(struct rproc *rproc)
> rproc_add_carveout(rproc, mem);
> rproc_coredump_add_segment(rproc, da, resource_size(&res));
>
> - return 0;
> + return amd_bram_rproc_add_reserved_mem(rproc);
> }
[Severity: Medium]
Does amd_bram_rproc_prepare() leak previously added carveouts and
coredump segments if amd_bram_rproc_add_reserved_mem() fails?
When rproc_prepare_device() returns an error, rproc_fw_boot() skips
rproc_resource_cleanup(). The already-registered entries then leak on
unbind or get duplicated on a boot retry; calling
rproc_resource_cleanup(rproc) on error would unwind them.
Also, the -ENOMEM return value of rproc_coredump_add_segment() is
unchecked here and in amd_bram_rproc_add_reserved_mem().
[ ... ]
> @@ -116,6 +378,9 @@ static int amd_bram_rproc_stop(struct rproc *rproc)
> dev_err(priv->dev, "failed to assert reset: %d\n", ret);
> return ret;
> }
> + cancel_work_sync(&priv->rx_work);
> + bitmap_zero(priv->pending_notify_ids,
> + ARRAY_SIZE(priv->notify_msgs));
[Severity: High]
Can an in-flight RX mailbox interrupt re-queue priv->rx_work after
amd_bram_rproc_stop() and trigger a use-after-free during vdev teardown?
priv->rx_chan stays active across stop, and asserting the reset GPIO
does not flush words already in the PL mailbox RX FIFO or quiesce
amd_pl_mbox_irq_thread(). Even amd_bram_rproc_release_mboxes() notes
that freeing the RX channel is needed before cancel_work_sync().
CPU0 CPU1
__rproc_shutdown()
rproc_stop()
amd_bram_rproc_stop()
gpiod_set_value_cansleep(...)
cancel_work_sync(&priv->rx_work)
bitmap_zero(...)
amd_pl_mbox_irq_thread()
amd_bram_rproc_rx_callback()
set_bit(...)
schedule_work(&priv->rx_work)
rproc_resource_cleanup()
platform_device_unregister(...)
rproc_virtio_remove()
rproc_free_vring()
idr_remove(...)
devres frees rvdev
amd_bram_rproc_rx_work()
rproc_vq_interrupt()
idr_find(...)
READ_ONCE(rvring->vq)
<-- use-after-free
rproc_virtio_remove() removes the notifyid from rproc->notifyids and
devres frees rvdev without waiting for vq_srcu, while
rproc_vq_interrupt() calls idr_find() and dereferences rvring->vq
without rproc->lock or rcu_read_lock().
In addition, the non-atomic bitmap_zero() races with set_bit() in
amd_bram_rproc_rx_callback() and can leave stale notify bits for the
next boot.
>
> /* Disable clock after asserting reset */
> clk_disable_unprepare(priv->clk);
[Severity: Medium]
Does leaving priv->tx_chan open across amd_bram_rproc_stop() keep the
mailbox TX poll timer firing every 1 ms while the remote is in reset?
amd-pl-mailbox reports TX completion only once the remote drains the TX
FIFO, and resets the FIFO only in amd_pl_mbox_shutdown(). If a kick is
still unread when the remote stops or crashes, txdone_hrtimer() polls
every 1 ms indefinitely and stale kicks carry over to the next boot.
[ ... ]
> @@ -178,6 +448,29 @@ static int amd_bram_rproc_probe(struct platform_device *pdev)
> return dev_err_probe(dev, PTR_ERR(priv->reset),
> "failed to get reset gpio\n");
>
> + priv->tx_client.dev = dev;
> + priv->tx_client.tx_block = false;
> + priv->tx_client.knows_txdone = false;
> + priv->rx_client.dev = dev;
> + priv->rx_client.rx_callback = amd_bram_rproc_rx_callback;
> + for (i = 0; i < ARRAY_SIZE(priv->notify_msgs); i++) {
> + priv->notify_msgs[i] =
> + devm_kzalloc(dev, struct_size(priv->notify_msgs[i],
> + data, sizeof(u32)),
> + GFP_KERNEL);
> + if (!priv->notify_msgs[i])
> + return -ENOMEM;
> + }
[Severity: Low]
Can these 256 notify_msgs entries be allocated as a single contiguous
block only when the mboxes property is present?
On arm64, struct devres aligns data[] to ARCH_DMA_MINALIGN (128 bytes),
so 256 separate devm_kzalloc() calls consume 64 KiB of slab memory and
256 devres nodes even when mailboxes are not configured.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203175731.661503-1-ben.levinsky@amd.com?part=4
prev parent reply other threads:[~2026-12-03 19:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 17:57 [PATCH v4 0/4] Add AMD PL Mailbox and RPMsg support for the AMD BRAM remoteproc Ben Levinsky
2026-12-03 17:57 ` [PATCH v4 1/4] dt-bindings: mailbox: Add AMD PL Mailbox IP Ben Levinsky
2026-12-03 18:31 ` sashiko-bot
2026-12-03 17:57 ` [PATCH v4 2/4] mailbox: Add AMD PL Mailbox soft IP controller Ben Levinsky
2026-12-03 18:55 ` sashiko-bot
2026-12-03 17:57 ` [PATCH v4 3/4] dt-bindings: remoteproc: Add RPMsg resources to AMD BRAM rproc Ben Levinsky
2026-12-03 17:57 ` [PATCH v4 4/4] remoteproc: amd_mbv_bram: Add RPMsg support Ben Levinsky
2026-12-03 19:28 ` sashiko-bot [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=sashiko-outbox-248503@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ben.levinsky@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.