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=1796324140; b=m7fe0Ub1yu9RyIijq6gkZu2wT24uy/6yAzWU8hXjwD43UznTfRCWHDWD4Yi3t6hoKY3r Xinits9QnJq7yJnX2Eck3SwIfaaEblHgPWEaTn0oZdlGaXh7jpmubVoBydOQ3NF6r2Y7h LleX4s8rpvX3IhPyemAocomIFD6h4ks65wkBhNxMsmbEDDUuHz/Oj3676L9RQKKcXXP9H gySengmIZhrTRZg+1Ldu6SeCJ2XRcUMjtsOT4bWb6HgB3g350yOwMKLr/dTiDX+cACfH1 U0H/waMZLFwG1DrKBPL5khlAfHI650MXEeaHSIask+gvwRCm+X1cUma2PPRNatSVvag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324140; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=d+arDS4rLxKDqJWh/wO5AgOqZHclyXkw5amj3G0tvYQ=; b=Zw+rtYSyPg8qH3zxdYlNSC12A3aBTnhPnQCAs9MXdF5K1EcjEe+WCE7zPaZWPkBryB2o p+bYhE0l8QL44uqrp/qDxm8UZ7zQIX6wrNyMkxXh7DLAHa2WgRCYyCtBgGlbiNEO6nwMw fnKDK5cahFHYLGQY6Nu4cT+71VbN1tqLKkDwAsx4i+LZSFVSK5Oob+0xvY+aecbhdNLbB /lJwyNAURxRibxn4WZKz2vrIf1mlVKBX5wSyOGlVfwKy5zoMEBaqA0m5hV+tgsUdAyAcH 2nneOLhG74TJtV8Y7TFYdJoCLWYAfY8kSQgv2Iuri63FVsrG53lL65HCOCrRI04+FVA== 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=Vyp+IwNg; 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 C77B2606A322 for ; Thu, 3 Dec 2026 18:55:40 +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=Vyp+IwNg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7650E1F000C1; Thu, 3 Dec 2026 18:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796324140; bh=d+arDS4rLxKDqJWh/wO5AgOqZHclyXkw5amj3G0tvYQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Vyp+IwNg8bNPemXsKEYRcj0nG1oXN1CBdxnM6lwx+pVPMuKzAgSntMx8yQRdJt/35 DTwDHq/5rZbT1buIGJYYvX7pYNIj/vkHLlNXjH8l/9D7GUd2H5G5dsHuOnuK1SdG5k 4v25DvkOGacA6ScAkts1JYOHYJrZvDTGeMUNjezrcbpSGbNgY8Wrc/MSgs/jrpUYR8 W4usRtKH/utR6JoHnkysuGVCm/2bo0Iw+O10yd8+lbQ0sf5vQT/XJD1PMHGKOvWzjP 5WXVVeQrrwaIuV7HapEgmJHMc6TBiLbqnfVs69dx2QD2kPCsm5I7+9rNHRjWCmC1Y9 I4qpilrrxFFPA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/4] mailbox: Add AMD PL Mailbox soft IP controller 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-3-ben.levinsky@amd.com> References: <20261203175731.661503-1-ben.levinsky@amd.com> <20261203175731.661503-3-ben.levinsky@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 18:55:40 +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 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 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-ma= ilbox.c > new file mode 100644 > index 0000000000000..d1fe0f381dce5 > --- /dev/null > +++ b/drivers/mailbox/amd-pl-mailbox.c [ ... ] > + for (offset =3D 0; offset < msg->len; offset +=3D sizeof(u32)) { > + size_t count =3D min(sizeof(u32), msg->len - offset); > + u32 word =3D 0; > + > + if (readl(mb->regs + AMD_PL_MBOX_STATUS) & > + AMD_PL_MBOX_STS_TX_FULL) { > + ret =3D -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 =3D chan->con_priv; > + unsigned long flags; > + bool done =3D 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 =3D 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 () mbox_free_channel() amd_pl_mbox_shutdown() mb->tx_active =3D 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 =3D 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 =3D readl(mb->regs + AMD_PL_MBOX_IRQ_ENABLE); > + irq_enable |=3D 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 bit= s. 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 =3D 0; words < mb->fifo_len; words++) { > + if (readl(mb->regs + AMD_PL_MBOX_STATUS) & > + AMD_PL_MBOX_STS_RX_EMPTY) > + break; > + > + rx_words[words] =3D readl(mb->regs + AMD_PL_MBOX_RDDATA); > + } > + > + if (!words) > + break; > + > + mb->rx_msg->len =3D words * sizeof(u32); > + mbox_chan_received_data(&mb->chans[AMD_PL_MBOX_CHAN_RX], > + mb->rx_msg); > + } while (words =3D=3D 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 rea= ds AMD_PL_MBOX_STATUS as 0), words =3D=3D 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=3Dn? 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 =3D 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 DM= A, kvzalloc() paired with devm_add_action_or_reset() to call kvfree() avoids t= he high-order contiguous allocation. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203175731.6615= 03-1-ben.levinsky@amd.com?part=3D2