From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796326090; b=hjJgDKNDJdO9SCwuKtrGnhxgpNZO5LtkjqnTX+FqRO4vPAW1jcYyUPytHp7MPZ0Unbbp uKQVtT++8j0HorjlsuHfSz+6pLXcezghzdePumG1ttR3dkr50J9okN+YNi9Q+lRLrFz2r jHYpayguc243pskJL1fd3WhujfxoFTylVICHsvomXlHi/dnzPwpPPPp9OVX1TE+EyJYpM lVDmcE3mW0xh3w2cEat3eQ529wjfKzAi58o/yiGP55loHBwJVcrAWBsStKeqWdyurx5Uw LH+Wf7vA+5iJ76OOAAYhEc4b/3e/PMQNG5VsyMo1iBdcm2hiJIPzGuLdgxtmUrLWcsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326090; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=okuVsqVxHIjjf9bo36eTSbt6jd9feGs9QRg6tjtXrPQ=; b=oAvc9VNWkef/b+ZlZHnUbWo/qc9h2dPuUct3rz131cg/f0JBMR8XSdEiNdBgFkOb0teD m3nSbGRKea/NIj9prQb2ZhQeb2vYitXF4ImRNOAdsYb8M+/bHCkCHwxCNvxhLl/Di0sV7 ZeOLMws17tjnxHflzIG1lIoSLGz2fcczbC8OZ11z1KuooQ16lJaI6xnrDkz3OyMaxShSt ltiBijOpXo1PHNL6P43vrjquPJgDP+hKGWHTyVDUnWZPvcOpORFOt+6X7crlJxEHi6MKu x/OeEgsaTjbRbP7zl1L/tV+0sEdsHYdR8gP9e2leWMiXQ2TWYRyzlQlykRXi60Ps77Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oVLnXdiQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C2C5606A32C for ; Thu, 3 Dec 2026 19:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oVLnXdiQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 845E31F000C2; Thu, 3 Dec 2026 19:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796326089; bh=okuVsqVxHIjjf9bo36eTSbt6jd9feGs9QRg6tjtXrPQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oVLnXdiQ/dNYd/5xWrXaIFclkex9jrU9PHi3BbHzy3MA/QQJjrQTOsHMjt0NH11oS ik2/ZOwkhv/3Gg4YXbMNgvrZwyg4y04jsiMKX5eydxTd93cMtqbATdDBh9jerc/09l kA/BZk9AXI1R/c6wVYnBosYaBmaUFpNqIUv6NRDPuENmeQWoDST0m7CTTOjuSTcREu CxVwWs8/CpeYHdziWOp/xVchfMr58Nz1b0JZRxp2S5llzajCx13WD5e2vziK20yJOA U9nc4MiVUfVJep97SJtpnBhUBcfWhPVGdE596Ud+VpXYo0DsXiovUgABETKMBUW8c8 q+Au2sDeUxRSQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 4/4] remoteproc: amd_mbv_bram: Add RPMsg support Reply-To: sashiko-reviews@lists.linux.dev To: "Ben Levinsky" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203175731.661503-5-ben.levinsky@amd.com> References: <20261203175731.661503-1-ben.levinsky@amd.com> <20261203175731.661503-5-ben.levinsky@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 19:28:09 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D 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 >=3D 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 =3D priv->notify_msgs[vqid]; > + msg->len =3D 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 =3D 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 =3D priv->dev->of_node; > + int ret; > + > + ret =3D of_property_read_string_index(np, "memory-region-names", i, nam= e); > + if (ret) > + return dev_err_probe(priv->dev, ret, > + "failed to read memory-region name %d\n", i); > + > + ret =3D 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 =3D rproc->priv; > + struct rproc_mem_entry *mem; > + int count; > + int ret; > + int i; > + > + count =3D amd_bram_rproc_reserved_mem_count(priv); > + if (count < 0) > + return count; > + > + for (i =3D 0; i < count; i++) { > + struct resource res; > + const char *name; > + > + ret =3D amd_bram_rproc_get_reserved_mem(priv, i, &name, &res); > + if (ret) > + return ret; > + > + if (!strcmp(name, "vdev0buffer")) > + mem =3D rproc_of_resm_mem_entry_init(priv->dev, i, > + resource_size(&res), > + res.start, name); > + else > + mem =3D 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; > } > =20 > + ret =3D amd_bram_rproc_check_reserved_mem(priv); > + if (ret) > + return ret; > + > mem =3D 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)); > =20 > - 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. > =20 > /* 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_devi= ce *pdev) > return dev_err_probe(dev, PTR_ERR(priv->reset), > "failed to get reset gpio\n"); > =20 > + priv->tx_client.dev =3D dev; > + priv->tx_client.tx_block =3D false; > + priv->tx_client.knows_txdone =3D false; > + priv->rx_client.dev =3D dev; > + priv->rx_client.rx_callback =3D amd_bram_rproc_rx_callback; > + for (i =3D 0; i < ARRAY_SIZE(priv->notify_msgs); i++) { > + priv->notify_msgs[i] =3D > + 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203175731.6615= 03-1-ben.levinsky@amd.com?part=3D4