DMA Engine development
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Ruoyu Wang <ruoyuw560@gmail.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] dmaengine: mmp_pdma: Check virtual channel before scheduling tasklet
Date: Tue, 1 Dec 2026 16:13:24 -0600	[thread overview]
Message-ID: <aw9GhA0ZjedcAXBk@SMW015318> (raw)
In-Reply-To: <20261129152817.27494-1-ruoyuw560@gmail.com>

On Sun, Nov 29, 2026 at 11:28:17PM +0800, Ruoyu Wang wrote:
> mmp_pdma_chan_handler() clears a physical-channel interrupt and then
> unconditionally schedules phy->vchan->tasklet. The physical channel can
> be detached from its virtual channel when the channel is terminated or
> when no pending work remains, so a late or shared interrupt can reach the
> handler with phy->vchan already NULL. If the physical channel has been
> reassigned in the meantime, the interrupt can also schedule the tasklet
> of the new virtual channel.
>
> Handle the interrupt and read phy->vchan under phy_lock, which protects
> the attach/detach stores, and skip tasklet scheduling when there is no
> virtual channel. Call clear_chan_irq() in mmp_pdma_free_phy() before
> detaching, so that a pending interrupt is not handled for the next
> virtual channel.
>
> This issue was found by a static analysis checker and confirmed by
> manual source review.
>
> Fixes: c8acd6aa6bed ("dmaengine: mmp-pdma support")
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> Changes in v2:
> - Take phy_lock in the interrupt handler and call clear_chan_irq() before
>   detaching the physical channel, to address the phy->vchan race pointed
>   out by Frank Li.
>
> v1: https://lore.kernel.org/r/20260707150356.2257833-1-ruoyuw560@gmail.com/
>
>  drivers/dma/mmp_pdma.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma/mmp_pdma.c b/drivers/dma/mmp_pdma.c
> index 6045d6d1c..38c187299 100644
> --- a/drivers/dma/mmp_pdma.c
> +++ b/drivers/dma/mmp_pdma.c
> @@ -134,6 +134,7 @@ struct mmp_pdma_phy {
>  	int idx;
>  	void __iomem *base;
>  	struct mmp_pdma_chan *vchan;
> +	struct mmp_pdma_device *pdev;
>  };
>
>  /**
> @@ -369,12 +370,17 @@ static int clear_chan_irq(struct mmp_pdma_phy *phy)
>  static irqreturn_t mmp_pdma_chan_handler(int irq, void *dev_id)
>  {
>  	struct mmp_pdma_phy *phy = dev_id;
> +	irqreturn_t ret = IRQ_NONE;
>
> -	if (clear_chan_irq(phy) != 0)
> -		return IRQ_NONE;
> +	spin_lock(&phy->pdev->phy_lock);
> +	if (clear_chan_irq(phy) == 0) {
> +		if (phy->vchan)
> +			tasklet_schedule(&phy->vchan->tasklet);
> +		ret = IRQ_HANDLED;
> +	}
> +	spin_unlock(&phy->pdev->phy_lock);
>
> -	tasklet_schedule(&phy->vchan->tasklet);
> -	return IRQ_HANDLED;
> +	return ret;
>  }
>
>  static irqreturn_t mmp_pdma_int_handler(int irq, void *dev_id)
> @@ -452,6 +458,7 @@ static void mmp_pdma_free_phy(struct mmp_pdma_chan *pchan)
>  	writel(0, pchan->phy->base + reg);
>
>  	spin_lock_irqsave(&pdev->phy_lock, flags);
> +	clear_chan_irq(pchan->phy);
>  	pchan->phy->vchan = NULL;
>  	pchan->phy = NULL;
>  	spin_unlock_irqrestore(&pdev->phy_lock, flags);
> @@ -1155,6 +1162,7 @@ static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev, int idx, int irq)
>
>  	phy->idx = idx;
>  	phy->base = pdev->base;
> +	phy->pdev = pdev;
>
>  	if (irq) {
>  		ret = devm_request_irq(pdev->dev, irq, mmp_pdma_chan_handler,
>
> base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8
> --
> 2.43.0
>

      reply	other threads:[~2026-12-01 22:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 15:28 [PATCH v2] dmaengine: mmp_pdma: Check virtual channel before scheduling tasklet Ruoyu Wang
2026-12-01 22:13 ` Frank Li [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=aw9GhA0ZjedcAXBk@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=arnd@arndb.de \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ruoyuw560@gmail.com \
    --cc=vkoul@kernel.org \
    /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