All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Runyu Xiao <runyu.xiao@seu.edu.cn>
Cc: Bjorn Andersson <andersson@kernel.org>,
	Tanmay Shah <tanmay.shah@amd.com>,
	Jianhao Xu <jianhao.xu@seu.edu.cn>,
	linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v3] remoteproc: xlnx: initialize mailbox work before requesting channels
Date: Tue, 25 Aug 2026 10:53:57 -0600	[thread overview]
Message-ID: <ao3IpdsQDjDXXawj@p14s> (raw)
In-Reply-To: <20260818101201.1603947-1-runyu.xiao@seu.edu.cn>

On Tue, Aug 18, 2026 at 06:12:01PM +0800, Runyu Xiao wrote:
> zynqmp_r5_setup_mbox() installs zynqmp_r5_mb_rx_cb() as the mailbox RX
> callback before requesting the mailbox channels, but initializes
> ipi->mbox_work only after both channels have been requested. Once the RX
> channel is active, a notification delivered before the late INIT_WORK()
> would make the callback queue an uninitialized work item.
> 
> Initialize the work item before requesting channels. Also drain the work
> before freeing the mailbox state, after the channels have been released so
> no new callbacks can queue it. Use the same drain before freeing ipi from
> the channel request error paths, since the callback is already published
> there as well.
> 
> This issue was found by our static analysis tool and then confirmed by
> manual review of the mailbox setup sequence. The callback is published
> before the channel requests complete, so the work item should be ready
> before the mailbox provider can invoke it.
> 
> A QEMU PoC modeled a mailbox notification delivered after the RX callback
> became reachable but before the delayed INIT_WORK(). DEBUG_OBJECTS reported
> queueing an uninitialized work item from the zynqmp_r5_setup_mbox() path.
> 
> This is sent as an RFC because the practical trigger depends on the ZynqMP
> IPI mailbox provider and firmware delivery timing. If the provider cannot
> invoke the RX callback until after setup returns, this is a defensive
> lifecycle cleanup rather than a reachable race on current systems.
> 
> Fixes: 5dfb28c257b7 ("remoteproc: xilinx: Add mailbox channels for rpmsg")
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
> ---
> Changes in v3:
> - Follow Mathieu's feedback and call cancel_work_sync() before freeing ipi
>   from the tx/rx channel request error paths.
> 
> Changes in v2:
> - Follow Tanmay's suggestion and keep zynqmp_r5_setup_mbox() taking the
>   child device pointer. Do not move the r5_core assignment in this patch.
> - Only move INIT_WORK() before channel requests and drain the work in
>   zynqmp_r5_free_mbox().
> 
>  drivers/remoteproc/xlnx_r5_remoteproc.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>

I will pick this up when RC1 comes out next week.

Thanks,
Mathieu
 
> diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c
> index c685bb5fa62c..d47fbf143acd 100644
> --- a/drivers/remoteproc/xlnx_r5_remoteproc.c
> +++ b/drivers/remoteproc/xlnx_r5_remoteproc.c
> @@ -318,6 +318,8 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev)
>  	if (!ipi)
>  		return NULL;
>  
> +	INIT_WORK(&ipi->mbox_work, handle_event_notified);
> +
>  	mbox_cl = &ipi->mbox_cl;
>  	mbox_cl->rx_callback = zynqmp_r5_mb_rx_cb;
>  	mbox_cl->tx_block = false;
> @@ -329,6 +331,7 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev)
>  	ipi->tx_chan = mbox_request_channel_byname(mbox_cl, "tx");
>  	if (IS_ERR(ipi->tx_chan)) {
>  		ipi->tx_chan = NULL;
> +		cancel_work_sync(&ipi->mbox_work);
>  		kfree(ipi);
>  		dev_warn(cdev, "mbox tx channel request failed\n");
>  		return NULL;
> @@ -339,13 +342,12 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev)
>  		mbox_free_channel(ipi->tx_chan);
>  		ipi->rx_chan = NULL;
>  		ipi->tx_chan = NULL;
> +		cancel_work_sync(&ipi->mbox_work);
>  		kfree(ipi);
>  		dev_warn(cdev, "mbox rx channel request failed\n");
>  		return NULL;
>  	}
>  
> -	INIT_WORK(&ipi->mbox_work, handle_event_notified);
> -
>  	return ipi;
>  }
>  
> @@ -364,6 +366,8 @@ static void zynqmp_r5_free_mbox(struct mbox_info *ipi)
>  		ipi->rx_chan = NULL;
>  	}
>  
> +	cancel_work_sync(&ipi->mbox_work);
> +
>  	kfree(ipi);
>  }
>  
> -- 
> 2.34.1
> 

      reply	other threads:[~2026-08-25 16:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19  7:48 [RFC PATCH] remoteproc: xlnx: initialize mailbox work before requesting channels Runyu Xiao
2026-06-22 18:00 ` Shah, Tanmay
2026-07-17  2:31 ` [RFC PATCH v2] " Runyu Xiao
2026-07-17 13:13   ` Shah, Tanmay
2026-07-22 15:36   ` Mathieu Poirier
2026-08-18 10:12 ` [RFC PATCH v3] " Runyu Xiao
2026-08-25 16:53   ` Mathieu Poirier [this message]

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=ao3IpdsQDjDXXawj@p14s \
    --to=mathieu.poirier@linaro.org \
    --cc=andersson@kernel.org \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=runyu.xiao@seu.edu.cn \
    --cc=tanmay.shah@amd.com \
    /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.