From: sashiko-bot@kernel.org
To: "Paul Cercueil" <paul.cercueil@bootlin.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 2/3] mailbox: marvell-mhu: add Marvell MHU driver
Date: Thu, 19 Nov 2026 15:49:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-223424@kernel.org> (raw)
In-Reply-To: <20261119152944.276763-3-paul.cercueil@bootlin.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] mailbox: marvell-mhu: manual pci_free_irq_vectors() conflicts
with devres
- [High] mailbox: marvell-mhu: missing shutdown op causes NULL deref in
IRQ
- [Medium] mailbox: marvell-mhu: missing PCI dependency in Kconfig
- [Medium] mailbox: marvell-mhu: wrong register and polarity in
mrvl_mhu_last_tx_done()
- [Low] mailbox: marvell-mhu: duplicate and unused register macro
definitions
--
commit d88d0044b75f722104999e16b9dd2c9f50a997d0
Author: George Cherian <gcherian@marvell.com>
mailbox: marvell-mhu: add Marvell MHU driver
This commit adds a PCI mailbox controller driver for the Marvell Message
Handling Unit on OcteonTX and OcteonTX2 platforms.
> diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
> index ab869769e2789..ce3b70749a182 100644
> --- a/drivers/mailbox/Kconfig
> +++ b/drivers/mailbox/Kconfig
> @@ -195,6 +195,17 @@ config MAILBOX_TEST
> Test client to help with testing new Controller driver
> implementations.
>
> +config MARVELL_MHU
> + tristate "Marvell Message Handling Unit"
> + depends on (ARM64 || COMPILE_TEST) && 64BIT
> + depends on OF
> + help
[Severity: Medium]
Should MARVELL_MHU also depend on PCI? Without CONFIG_PCI, building this
driver fails because module_pci_driver() is only defined under CONFIG_PCI
and pcim_request_region() and pcim_iomap() have no !CONFIG_PCI stubs.
[ ... ]
> diff --git a/drivers/mailbox/marvell_mhu.c b/drivers/mailbox/marvell_mhu.c
> new file mode 100644
> index 0000000000000..a037fe104195b
> --- /dev/null
> +++ b/drivers/mailbox/marvell_mhu.c
[ ... ]
> +/* Register offset: Enable interrupt from SCP to AP */
> +#define XCP0_XCP_DEV0_MBOX_RINT_ENA_W1S 0x000D1C40
> +#define XCP0_XCP_DEV1_MBOX_RINT_ENA_W1S 0x000D1C50
> +#define XCP0_XCP_DEV2_MBOX_RINT_ENA_W1S 0x000D1C60
> +#define XCP0_XCP_DEV3_MBOX_RINT_ENA_W1S 0x000D1C70
> +
> +/* Rx interrupt from SCP to Non-secure AP (linux kernel) */
> +#define XCPX_XCP_DEVY_MBOX_RINT_OFFSET 0x000D1C00
> +#define XCPX_XCP_DEVY_MBOX_RINT(xcp_core, device_id) \
> + (XCPX_XCP_DEVY_MBOX_RINT_OFFSET | \
> + ((uint64_t)(xcp_core) << 36) | \
> + ((uint64_t)(device_id) << 4))
> +
> +/* The interrupt status register */
> +#define SCP_TO_AP0_MBOX_RINT XCPX_XCP_DEVY_MBOX_RINT(SCP_INDEX, DEV_AP0)
> +
> +#define XCPX_XCP_DEVY_MBOX_RINT_OFFSET 0x000D1C00
> +#define XCPX_XCP_DEVY_MBOX_RINT(xcp_core, device_id) \
> + (XCPX_XCP_DEVY_MBOX_RINT_OFFSET | \
> + ((uint64_t)(xcp_core) << 36) | \
> + ((uint64_t)(device_id) << 4))
> +
> +#define SCP_TO_AP0_MBOX_RINT XCPX_XCP_DEVY_MBOX_RINT(SCP_INDEX, DEV_AP0)
> +#define SCP_TO_DEV0 XCPX_XCP_DEVY_MBOX_RINT(0, 0)
> +#define SCP_TO_DEV1 XCPX_XCP_DEVY_MBOX_RINT(0, 1)
> +#define SCP_TO_DEV2 XCPX_XCP_DEVY_MBOX_RINT(0, 2)
> +#define SCP_TO_DEV3 XCPX_XCP_DEVY_MBOX_RINT(0, 3)
[Severity: Low]
This isn't a bug, but XCPX_XCP_DEVY_MBOX_RINT_OFFSET,
XCPX_XCP_DEVY_MBOX_RINT, and SCP_TO_AP0_MBOX_RINT are defined twice here,
and XCP0_XCP_DEV0/1/3_MBOX_RINT_ENA_W1S and SCP_TO_DEV0..3 are unused.
> +
> +struct mrvl_mhu {
> + /* SCP link information */
> + void __iomem *base; /* tx_reg, rx_reg */
> +
> + struct mbox_controller ctrl;
> + struct mbox_chan chan;
> +};
> +
> +static irqreturn_t mrvl_mhu_rx_interrupt(int irq, void *p)
> +{
> + struct mrvl_mhu *mhu = p;
> + u64 val;
> +
> + /* Read interrupt status register */
> + val = readq_relaxed(mhu->base + SCP_TO_AP0_MBOX_RINT);
> + if (val) {
> + /* Clear the interrupt : Write on clear */
> + writeq_relaxed(1ul, mhu->base + SCP_TO_AP0_MBOX_RINT);
> + /* Poke mbox */
> + mbox_chan_received_data(&mhu->chan, (void *)&val);
> + return IRQ_HANDLED;
> + }
> +
> + return IRQ_NONE;
> +}
> +
> +static int mrvl_mhu_send_data(struct mbox_chan *chan, void *data)
> +{
> + const u64 doorbell = 0xff; /* Arbitrary value, SCP requires a value */
> + struct mrvl_mhu *mhu = chan->con_priv;
> +
> + /* signal SCP */
> + iowrite64(doorbell, mhu->base + AP0_TO_SCP_MBOX);
> +
> + return 0;
> +}
> +
> +static bool mrvl_mhu_last_tx_done(struct mbox_chan *chan)
> +{
> + struct mrvl_mhu *mhu = chan->con_priv;
> + u64 status;
> +
> + status = ioread64(mhu->base + XCPX_XCP_DEVY_MBOX_RINT(0, 2));
> +
> + return status != 0;
> +}
[Severity: Medium]
Does mrvl_mhu_last_tx_done() check the wrong register and polarity?
XCPX_XCP_DEVY_MBOX_RINT(0, 2) is SCP_TO_AP0_MBOX_RINT, the SCP-to-AP0 RX
interrupt status register, which mrvl_mhu_rx_interrupt() immediately clears
to 0 in hardirq context when an RX interrupt fires. Consequently, any
client relying on the controller's txdone_poll = true will read 0 and time
out. Meanwhile, the AP0-to-SCP TX interrupt status macro
AP0_TO_SCP_MBOX_LINT defined earlier in this file is unused, and its status
bit is cleared to 0 when the SCP consumes the doorbell (status == 0).
> +
> +static int mrvl_mhu_startup(struct mbox_chan *chan)
> +{
> + struct mrvl_mhu *mhu = chan->con_priv;
> +
> + /* Enable interrupts only if there is client for data */
> + writeq_relaxed(1ul, mhu->base + XCP0_XCP_DEV2_MBOX_RINT_ENA_W1S);
> +
> + return 0;
> +}
> +
> +/* Define operations related to mbox */
> +static const struct mbox_chan_ops mrvl_mhu_chan_ops = {
> + .startup = mrvl_mhu_startup,
> + .send_data = mrvl_mhu_send_data,
> + .last_tx_done = mrvl_mhu_last_tx_done,
> +};
[Severity: High]
Can an SCP interrupt after mbox_free_channel() cause a NULL pointer
dereference in mrvl_mhu_rx_interrupt() -> mbox_chan_received_data()?
mrvl_mhu_startup() enables the hardware interrupt via
XCP0_XCP_DEV2_MBOX_RINT_ENA_W1S, but mrvl_mhu_chan_ops provides no
.shutdown callback to disable it when a client releases the channel (or if
the interrupt was already left enabled before a client binds). Once
mbox_free_channel() sets chan->cl = NULL, an incoming interrupt calls
mbox_chan_received_data(&mhu->chan, ...), which unconditionally
dereferences chan->cl->rx_callback. In addition, mrvl_mhu_rx_interrupt()
clears SCP_TO_AP0_MBOX_RINT before mbox_chan_received_data() finishes
processing the shared memory payload.
[ ... ]
> + pci_set_drvdata(pdev, mhu);
> + ret = pcim_enable_device(pdev);
> + if (ret)
> + return ret;
> +
> + ret = pcim_request_region(pdev, BAR0, DRIVER_NAME);
> + if (ret)
> + return ret;
> +
> + mhu->base = pcim_iomap(pdev, BAR0, pci_resource_len(pdev, BAR0));
> + if (!mhu->base)
> + return -EINVAL;
> +
> + /* Configure IRQ from SCP to AP */
> + ret = mrvl_mhu_setup_irq(pdev);
> + if (ret)
> + return ret;
> +
> + ret = mbox_controller_register(&mhu->ctrl);
> + if (ret) {
> + pci_free_irq_vectors(pdev);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static void mrvl_mhu_remove(struct pci_dev *pdev)
> +{
> + struct mrvl_mhu *mhu = pci_get_drvdata(pdev);
> +
> + mbox_controller_unregister(&mhu->ctrl);
> + pci_free_irq_vectors(pdev);
> +}
[Severity: High]
Does calling pci_free_irq_vectors() here tear down the MSI-X IRQ descriptor
while the devm_request_irq() handler is still registered?
Because mrvl_mhu_probe() calls pcim_enable_device(), pci_alloc_irq_vectors()
is already managed by devres (via pcim_msi_release()). Calling
pci_free_irq_vectors() manually in mrvl_mhu_remove() and on the
mbox_controller_register() failure path frees the IRQ descriptors before
devres runs devm_irq_release(), which triggers a warning when removing the
populated procfs IRQ directory, causes free_irq() to fail to find the
descriptor and leak struct irqaction, and then runs pci_free_irq_vectors()
a second time during devres teardown.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119152944.276763-1-paul.cercueil@bootlin.com?part=2
next prev parent reply other threads:[~2026-11-19 15:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 15:29 [PATCH 0/3] mailbox: Add Marvell MHU driver Paul Cercueil
2026-11-19 15:29 ` [PATCH 1/3] dt-bindings: mailbox: add Marvell MHU Paul Cercueil
2026-11-19 15:38 ` sashiko-bot
2026-11-19 15:29 ` [PATCH 2/3] mailbox: marvell-mhu: add Marvell MHU driver Paul Cercueil
2026-11-19 15:49 ` sashiko-bot [this message]
2026-11-19 15:29 ` [PATCH 3/3] scmi: driver: Increase timeout for rx response Paul Cercueil
2026-11-19 15:38 ` sashiko-bot
2026-11-19 15:54 ` [PATCH 0/3] mailbox: Add Marvell MHU driver Paul Cercueil
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-223424@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=paul.cercueil@bootlin.com \
--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