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 2/4] mailbox: Add AMD PL Mailbox soft IP controller
Date: Thu, 03 Dec 2026 18:55:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-248439@kernel.org> (raw)
In-Reply-To: <20261203175731.661503-3-ben.levinsky@amd.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] mailbox: lost RX threshold IRQ race in amd_pl_mbox_startup()
- [Medium] mailbox: partial TX FIFO write before -EBUSY in
amd_pl_mbox_send_data()
- [Medium] mailbox: unbounded RX drain loop in amd_pl_mbox_rx() can hang
shutdown
- [Medium] mailbox: amd_pl_mbox_last_tx_done() returns true during TX
shutdown
- [Medium] mailbox: skipped error register read in
amd_pl_mbox_irq_thread()
- [Low] mailbox: RMW on IRQ_ENABLE preserves stale IRQs in
amd_pl_mbox_startup()
- [Low] mailbox: costly order-4 devm_kzalloc() in amd_pl_mbox_probe()
--
commit e7914f70a5a1f024d98d1709d7c6139f8397fd34
Author: Ben Levinsky <ben.levinsky@amd.com>
mailbox: Add AMD PL Mailbox soft IP controller
This commit adds a mailbox controller driver for the AMD Programmable Logic
Mailbox soft IP, providing polling-based TX and threaded-IRQ RX channels.
> diff --git a/drivers/mailbox/amd-pl-mailbox.c b/drivers/mailbox/amd-pl-mailbox.c
> new file mode 100644
> index 0000000000000..d1fe0f381dce5
> --- /dev/null
> +++ b/drivers/mailbox/amd-pl-mailbox.c
[ ... ]
> + for (offset = 0; offset < msg->len; offset += sizeof(u32)) {
> + size_t count = min(sizeof(u32), msg->len - offset);
> + u32 word = 0;
> +
> + if (readl(mb->regs + AMD_PL_MBOX_STATUS) &
> + AMD_PL_MBOX_STS_TX_FULL) {
> + ret = -EBUSY;
> + goto unlock;
> + }
> +
> + memcpy(&word, &msg->data[offset], count);
> + writel(word, mb->regs + AMD_PL_MBOX_WRDATA);
> + }
[Severity: Medium]
Can this loop push partial words into AMD_PL_MBOX_WRDATA before returning
-EBUSY and corrupt the remote message stream?
The TX FIFO is not guaranteed to be empty on entry: when a blocking
mbox_send_message() times out, tx_tick(chan, -ETIME) clears chan->active_req
and submits the next queued message even if unread words remain in the
hardware FIFO.
If AMD_PL_MBOX_STS_TX_FULL trips mid-message, msg_submit() keeps the failed
message at the head of chan->msg_data[], so the retry starts again from
offset 0 and duplicates the leading words already written to the FIFO.
Checking AMD_PL_MBOX_STS_TX_THRESHOLD once before the loop ensures the TX
FIFO is empty before writing any words.
[ ... ]
> +static bool amd_pl_mbox_last_tx_done(struct mbox_chan *chan)
> +{
> + struct amd_pl_mbox *mb = chan->con_priv;
> + unsigned long flags;
> + bool done = true;
> +
> + /*
> + * The mailbox core can poll after shutdown() has started, while the
> + * interface clock is being disabled. Do not access registers then.
> + */
> + spin_lock_irqsave(&mb->tx_lock, flags);
> + if (mb->tx_active)
> + /* SIT is zero, so the threshold status means TX FIFO empty. */
> + done = readl(mb->regs + AMD_PL_MBOX_STATUS) &
> + AMD_PL_MBOX_STS_TX_THRESHOLD;
> + spin_unlock_irqrestore(&mb->tx_lock, flags);
> +
> + return done;
> +}
[Severity: Medium]
Should done default to false instead of true when mb->tx_active is cleared
during TX shutdown?
mbox_free_channel() calls amd_pl_mbox_shutdown() before
mbox_clean_and_put_channel() clears chan->cl and chan->active_req, while
poll_hrt can still fire:
CPU0 CPU1 (<hardirq>)
mbox_free_channel()
amd_pl_mbox_shutdown()
mb->tx_active = false
writel(TX_RESET, ...)
clk_disable_unprepare()
txdone_hrtimer()
amd_pl_mbox_last_tx_done() -> true
tx_tick(chan, 0)
mbox_clean_and_put_channel()
chan->cl = NULL
chan->cl->tx_done() <-- NULL deref
Returning true fabricates a successful completion for an aborted transfer
whose FIFO was just reset, and lets tx_tick() dereference chan->cl outside
chan->lock while mbox_clean_and_put_channel() clears it. Returning false
lets poll_hrt reschedule once and stop cleanly once chan->cl is cleared.
[ ... ]
> + writel(AMD_PL_MBOX_CTRL_RX_RESET, mb->regs + AMD_PL_MBOX_CTRL);
> + /* Interrupt when the RX FIFO changes from empty to nonempty. */
> + writel(0, mb->regs + AMD_PL_MBOX_RECV_THRESHOLD);
> + writel(AMD_PL_MBOX_IRQ_RX_THRESHOLD | AMD_PL_MBOX_IRQ_ERROR,
> + mb->regs + AMD_PL_MBOX_IRQ_STATUS);
[Severity: Medium]
Can clearing AMD_PL_MBOX_IRQ_STATUS after AMD_PL_MBOX_CTRL_RX_RESET lose the
first RX threshold interrupt and wedge RX delivery?
Because AMD_PL_MBOX_IRQ_RX_THRESHOLD latches only when RX FIFO occupancy
transitions from empty to nonempty, a word arriving in the window between
the reset and the status clear leaves the FIFO nonempty with its interrupt
cleared:
CPU0 Remote peer
amd_pl_mbox_startup()
writel(RX_RESET, CTRL)
writes word to RX FIFO (0 -> 1)
RX_THRESHOLD latches
writel(0, RECV_THRESHOLD)
writel(RX_THRESHOLD, IRQ_STATUS) <-- clears latched IRQ
enable_irq(mb->irq)
Subsequent writes never produce another empty-to-nonempty transition, so RX
stays stuck until the channel is restarted. Programming
AMD_PL_MBOX_RECV_THRESHOLD and clearing AMD_PL_MBOX_IRQ_STATUS before
AMD_PL_MBOX_CTRL_RX_RESET (or draining after enabling interrupts) avoids
losing the edge.
> + irq_enable = readl(mb->regs + AMD_PL_MBOX_IRQ_ENABLE);
> + irq_enable |= AMD_PL_MBOX_IRQ_RX_THRESHOLD | AMD_PL_MBOX_IRQ_ERROR;
> + writel(irq_enable, mb->regs + AMD_PL_MBOX_IRQ_ENABLE);
> + enable_irq(mb->irq);
[Severity: Low]
Can this read-modify-write preserve stale bits in AMD_PL_MBOX_IRQ_ENABLE?
Neither probe, startup, nor shutdown initializes AMD_PL_MBOX_IRQ_ENABLE to a
known value, and amd_pl_mbox_shutdown() only masks out the RX and error bits.
If firmware or a prior kexec kernel leaves another bit set (such as the send
threshold interrupt), amd_pl_mbox_irq_thread() will wake up spuriously on TX
empty events and the bit will remain enabled after shutdown. Writing
AMD_PL_MBOX_IRQ_RX_THRESHOLD | AMD_PL_MBOX_IRQ_ERROR directly in startup and
0 in shutdown ensures a deterministic mask.
[ ... ]
> + do {
> + for (words = 0; words < mb->fifo_len; words++) {
> + if (readl(mb->regs + AMD_PL_MBOX_STATUS) &
> + AMD_PL_MBOX_STS_RX_EMPTY)
> + break;
> +
> + rx_words[words] = readl(mb->regs + AMD_PL_MBOX_RDDATA);
> + }
> +
> + if (!words)
> + break;
> +
> + mb->rx_msg->len = words * sizeof(u32);
> + mbox_chan_received_data(&mb->chans[AMD_PL_MBOX_CHAN_RX],
> + mb->rx_msg);
> + } while (words == mb->fifo_len);
[Severity: Medium]
Can this unbounded loop in amd_pl_mbox_rx() monopolize the CPU and hang
amd_pl_mbox_shutdown()?
amd_pl_mbox_irq_thread() runs at SCHED_FIFO priority with IRQF_ONESHOT. If
a remote peer refills the FIFO faster than it is drained (or a PL fault reads
AMD_PL_MBOX_STATUS as 0), words == mb->fifo_len stays true indefinitely,
starving normal tasks and blocking disable_irq() in amd_pl_mbox_shutdown()
forever. Checking an rx_active flag cleared before disable_irq() and
bounding drain iterations allows shutdown to complete cleanly.
[ ... ]
> + if (pending_intr & AMD_PL_MBOX_IRQ_ERROR)
> + dev_warn_ratelimited(mb->controller.dev,
> + "mailbox FIFO error: %#x\n",
> + readl(mb->regs + AMD_PL_MBOX_ERROR));
[Severity: Medium]
Will readl(mb->regs + AMD_PL_MBOX_ERROR) be skipped when
dev_warn_ratelimited() suppresses the message or when CONFIG_PRINTK=n?
dev_warn_ratelimited() only evaluates its variadic arguments when
__ratelimit() returns true, which skips the MMIO read and leaves sticky
clear-on-read error bits uncleared in hardware. Reading AMD_PL_MBOX_ERROR
into a local variable before logging avoids this, and reading it once in
amd_pl_mbox_startup() clears any pre-existing error bits before enabling the
error interrupt.
[ ... ]
> + mb->rx_msg = devm_kzalloc(dev, struct_size(mb->rx_msg, data,
> + mb->fifo_len * sizeof(u32)),
> + GFP_KERNEL);
[Severity: Low]
Can this devm_kzalloc() exceed PAGE_ALLOC_COSTLY_ORDER at the maximum FIFO
depth?
At AMD_PL_MBOX_FIFO_LEN_MAX (8192 words), struct_size() is 32776 bytes on
64-bit systems plus struct devres overhead, forcing an order-4 (64 KiB)
physically contiguous allocation. On fragmented systems such as dynamically
loaded FPGA overlays, this risks compaction stalls or -ENOMEM probe failures
and wastes nearly 32 KiB per instance. Since mb->rx_msg is not used for DMA,
kvzalloc() paired with devm_add_action_or_reset() to call kvfree() avoids the
high-order contiguous allocation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203175731.661503-1-ben.levinsky@amd.com?part=2
next prev parent reply other threads:[~2026-12-03 18:55 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 [this message]
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
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-248439@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.