From: sashiko-bot@kernel.org
To: "Jia Yang" <jia.yang@oss.qualcomm.com>
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mailbox: qcom-cpucp: fix PREEMPT_RT self-deadlock in IRQ handler
Date: Thu, 06 Aug 2026 07:16:14 +0000 [thread overview]
Message-ID: <20260806071615.6F9E11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806-mailbox-qcom-cpucp-preempt-rt-fix-v1-1-d302a63dfb5e@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Dropping `chan->lock` before `mbox_chan_received_data()` introduces a TOCTOU race with `mbox_free_channel()`, leading to a NULL pointer dereference.
- [Medium] Acknowledging the hardware RX interrupt before invoking the RX callback violates the mailbox framework API and can cause client re-entrancy.
--
--- Patch [1]: [PATCH 1/2] mailbox: qcom-cpucp: fix PREEMPT_RT self-deadlock in IRQ handler ---
commit 995d8aa11aed719aa1d45f140bab12a284779e97
Author: Jia Yang <jia.yang@oss.qualcomm.com>
mailbox: qcom-cpucp: fix PREEMPT_RT self-deadlock in IRQ handler
This patch addresses a PREEMPT_RT self-deadlock in the qcom-cpucp mailbox IRQ
handler. It prevents lock re-entrancy by caching the channel client, clearing
the hardware interrupt inside the lock, and invoking the receive callback
outside the lock.
> diff --git a/drivers/mailbox/qcom-cpucp-mbox.c b/drivers/mailbox/qcom-cpucp-mbox.c
> index 862e45e8fbd58..0f7fe189e8b1f 100644
> --- a/drivers/mailbox/qcom-cpucp-mbox.c
> +++ b/drivers/mailbox/qcom-cpucp-mbox.c
> @@ -63,14 +63,25 @@ static irqreturn_t qcom_cpucp_mbox_irq_fn(int irq, void *data)
[ ... ]
> /*
> * Provide mutual exclusion with changes to chan->cl.
> * Save cl locally and clear the HW interrupt inside the lock,
> * then invoke mbox_chan_received_data() outside the lock to
> * avoid a PREEMPT_RT self-deadlock: mbox_chan_received_data()
> * can call back into mbox_send_message() via scmi_rx_callback()
> * -> mailbox_clear_channel(), which re-acquires chan->lock
> * (converted to an rt_spinlock under PREEMPT_RT).
> */
> spin_lock_irqsave(&chan->lock, flags);
> - if (chan->cl)
> - mbox_chan_received_data(chan, &val);
> + cl = chan->cl;
> writeq(BIT(i), cpucp->rx_base + APSS_CPUCP_RX_MBOX_CLEAR);
[Severity: Medium]
Does clearing the hardware interrupt before invoking the RX callback violate
the mailbox framework API expectations?
If the remote processor immediately sends another message upon seeing this
ACK, could a new interrupt fire and be processed on another CPU while the
lock is dropped, leading to concurrent entries into the client's rx_callback
for the same channel?
> spin_unlock_irqrestore(&chan->lock, flags);
> +
> + if (cl)
> + mbox_chan_received_data(chan, &val);
[Severity: High]
If mbox_free_channel() runs concurrently and sets chan->cl = NULL immediately
after spin_unlock_irqrestore(), won't mbox_chan_received_data() cause a NULL
pointer dereference?
Even though we check the local cached "cl" variable here, the framework API
unconditionally dereferences chan->cl without locking:
drivers/mailbox/mailbox.c:mbox_chan_received_data() {
/* No buffering the received data */
if (chan->cl->rx_callback)
chan->cl->rx_callback(chan->cl, mssg);
}
Could this race be reliably triggered during channel teardown or client
driver unbind?
> }
>
> return IRQ_HANDLED;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806-mailbox-qcom-cpucp-preempt-rt-fix-v1-0-d302a63dfb5e@oss.qualcomm.com?part=1
next prev parent reply other threads:[~2026-08-06 7:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 7:03 [PATCH 0/2] mailbox: qcom-cpucp: fix two PREEMPT_RT bugs in IRQ handler Jia Yang
2026-08-06 7:03 ` [PATCH 1/2] mailbox: qcom-cpucp: fix PREEMPT_RT self-deadlock " Jia Yang
2026-08-06 7:16 ` sashiko-bot [this message]
2026-08-06 7:03 ` [PATCH 2/2] mailbox: qcom-cpucp: handle NULL data in send_data callback Jia Yang
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=20260806071615.6F9E11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jia.yang@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--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