DMA Engine development
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,
	Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Sergey Khimich <serghox@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sia Jee Heng <jee.heng.sia@intel.com>,
	Baruch Siach <baruch@tkos.co.il>,
	Mitch Barnett <mitch@accuratesound.ca>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v8 7/9] dmaengine: dw-axi-dmac: serialize interrupt status with channel reuse
Date: Thu, 19 Nov 2026 10:44:34 -0600	[thread overview]
Message-ID: <av8ncvLCe85P5j0r@SMW015318> (raw)
In-Reply-To: <20261119-submit-dw-axi-dma-stop-pause-v1-v8-7-f8e7fe60594c@gmail.com>

On Thu, Nov 19, 2026 at 09:01:02AM -0700, James Hilliard wrote:
> The interrupt handler reads and acknowledges channel status before taking
> the channel lock. Termination can finish and a new transfer can start
> before the handler takes that lock. The saved completion or error status
> then applies to the new descriptor, stopping it and completing its cookie
> before its DMA transfer has finished.
>
> Termination also leaves completion and error status pending. A subsequent
> interrupt can consume that status after the channel has been reused, even
> if no handler was running when the old transfer was stopped.
>
> Read and acknowledge status under the channel lock and keep it held while
> processing the event. Move locking out of the completion and error helpers
> into their sole caller, and clear all channel status after a successful
> stop. Status collection, descriptor ownership and channel reuse then share
> the same serialization.
>
> Initialize the virtual channels before requesting the shared IRQs so every
> lock is ready before the interrupt handler can run.
>
> Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>  drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 31 ++++++++++++--------------
>  1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 2547f9596ae6..2eeb902eaad3 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -21,6 +21,7 @@
>  #include <linux/iopoll.h>
>  #include <linux/io-64-nonatomic-lo-hi.h>
>  #include <linux/kernel.h>
> +#include <linux/lockdep.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/of_dma.h>
> @@ -1072,9 +1073,8 @@ static void axi_chan_list_dump_lli(struct axi_dma_chan *chan,
>  static noinline void axi_chan_handle_err(struct axi_dma_chan *chan, u32 status)
>  {
>  	struct virt_dma_desc *vd;
> -	unsigned long flags;
>
> -	spin_lock_irqsave(&chan->vc.lock, flags);
> +	lockdep_assert_held(&chan->vc.lock);
>
>  	axi_chan_disable(chan);
>
> @@ -1083,7 +1083,7 @@ static noinline void axi_chan_handle_err(struct axi_dma_chan *chan, u32 status)
>  	if (!vd) {
>  		dev_err(vchan_chan_dev(&chan->vc), "BUG: %s, IRQ with no descriptors\n",
>  			axi_chan_name(chan));
> -		goto out;
> +		return;
>  	}
>  	/* Remove the completed descriptor from issued list */
>  	list_del(&vd->node);
> @@ -1100,9 +1100,6 @@ static noinline void axi_chan_handle_err(struct axi_dma_chan *chan, u32 status)
>  	chan->desc = NULL;
>  	chan->cyclic_restart = false;
>  	axi_chan_start_first_queued(chan);
> -
> -out:
> -	spin_unlock_irqrestore(&chan->vc.lock, flags);
>  }
>
>  static void axi_chan_block_xfer_complete(struct axi_dma_chan *chan)
> @@ -1111,11 +1108,11 @@ static void axi_chan_block_xfer_complete(struct axi_dma_chan *chan)
>  	struct axi_dma_hw_desc *hw_desc;
>  	struct axi_dma_desc *desc;
>  	struct virt_dma_desc *vd;
> -	unsigned long flags;
>  	u64 llp;
>  	int i;
>
> -	spin_lock_irqsave(&chan->vc.lock, flags);
> +	lockdep_assert_held(&chan->vc.lock);
> +
>  	if (unlikely(axi_chan_is_hw_enable(chan))) {
>  		dev_err(vchan_chan_dev(&chan->vc), "BUG: %s caught DWAXIDMAC_IRQ_DMA_TRF, but channel not idle!\n",
>  			axi_chan_name(chan));
> @@ -1127,7 +1124,7 @@ static void axi_chan_block_xfer_complete(struct axi_dma_chan *chan)
>  	if (!vd) {
>  		dev_err(vchan_chan_dev(&chan->vc), "BUG: %s, IRQ with no descriptors\n",
>  			axi_chan_name(chan));
> -		goto out;
> +		return;
>  	}
>
>  	desc = vd_to_axi_desc(vd);
> @@ -1159,9 +1156,6 @@ static void axi_chan_block_xfer_complete(struct axi_dma_chan *chan)
>  		chan->desc = NULL;
>  		axi_chan_start_first_queued(chan);
>  	}
> -
> -out:
> -	spin_unlock_irqrestore(&chan->vc.lock, flags);
>  }
>
>  static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
> @@ -1169,6 +1163,7 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
>  	struct axi_dma_chip *chip = dev_id;
>  	struct dw_axi_dma *dw = chip->dw;
>  	struct axi_dma_chan *chan;
> +	unsigned long flags;
>
>  	u32 status, i;
>
> @@ -1178,6 +1173,7 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
>  	/* Poll, clear and process every channel interrupt status */
>  	for (i = 0; i < dw->hdata->nr_channels; i++) {
>  		chan = &dw->chan[i];
> +		spin_lock_irqsave(&chan->vc.lock, flags);
>  		status = axi_chan_irq_read(chan);
>  		/* Leave suspension status for the pause and resume paths. */
>  		status &= ~DWAXIDMAC_IRQ_SUSPENDED;
> @@ -1190,6 +1186,7 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
>  			axi_chan_handle_err(chan, status);
>  		else if (status & DWAXIDMAC_IRQ_DMA_TRF)
>  			axi_chan_block_xfer_complete(chan);
> +		spin_unlock_irqrestore(&chan->vc.lock, flags);
>  	}
>
>  	/* Re-enable interrupts */
> @@ -1220,7 +1217,7 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
>
>  		vchan_terminate_all(&chan->vc);
>
> -		axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> +		axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_ALL);
>  		chan->desc = NULL;
>  		chan->pause_requested = false;
>  		chan->is_paused = false;
> @@ -1600,10 +1597,6 @@ static int dw_probe(struct platform_device *pdev)
>  	if (!dw->chan)
>  		return -ENOMEM;
>
> -	ret = axi_req_irqs(pdev, chip);
> -	if (ret)
> -		return ret;
> -
>  	INIT_LIST_HEAD(&dw->dma.channels);
>  	for (i = 0; i < hdata->nr_channels; i++) {
>  		struct axi_dma_chan *chan = &dw->chan[i];
> @@ -1617,6 +1610,10 @@ static int dw_probe(struct platform_device *pdev)
>  		vchan_init(&chan->vc, &dw->dma);
>  	}
>
> +	ret = axi_req_irqs(pdev, chip);
> +	if (ret)
> +		return ret;
> +

Most likely, irq request should after dma engine register. irq handle may
use some DMAengine APIs.

Frank

>  	/* Set capabilities */
>  	dma_cap_set(DMA_MEMCPY, dw->dma.cap_mask);
>  	dma_cap_set(DMA_SLAVE, dw->dma.cap_mask);
>
> --
> 2.53.0
>

  reply	other threads:[~2026-11-19 16:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 16:00 [PATCH v8 0/9] dmaengine: dw-axi-dmac: fix termination and pause acknowledgment James Hilliard
2026-11-19 16:00 ` [PATCH v8 1/9] dmaengine: dw-axi-dmac: keep cyclic mode in the descriptor James Hilliard
2026-11-19 16:00 ` [PATCH v8 2/9] dmaengine: dw-axi-dmac: poll the correct enable bit during termination James Hilliard
2026-11-19 16:17   ` Frank Li
2026-11-19 16:00 ` [PATCH v8 3/9] dmaengine: dw-axi-dmac: retain descriptors when termination times out James Hilliard
2026-11-19 16:18   ` Frank Li
2026-11-19 16:00 ` [PATCH v8 4/9] dmaengine: dw-axi-dmac: use atomic polling for suspend acknowledgment James Hilliard
2026-11-19 16:19   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 5/9] dmaengine: dw-axi-dmac: preserve pending pause requests James Hilliard
2026-11-19 16:27   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 6/9] dmaengine: dw-axi-dmac: retain descriptors until callbacks drain James Hilliard
2026-11-19 16:41   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 7/9] dmaengine: dw-axi-dmac: serialize interrupt status with channel reuse James Hilliard
2026-11-19 16:44   ` Frank Li [this message]
2026-11-19 16:01 ` [PATCH v8 8/9] dmaengine: dw-axi-dmac: require an IRQ before registering the controller James Hilliard
2026-11-19 16:47   ` Frank Li
2026-11-19 16:01 ` [PATCH v8 9/9] dmaengine: dw-axi-dmac: guard shared IRQs across the controller lifetime James Hilliard
2026-11-19 16:50   ` Frank Li

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=av8ncvLCe85P5j0r@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Eugeniy.Paltsev@synopsys.com \
    --cc=Frank.Li@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=baruch@tkos.co.il \
    --cc=dmaengine@vger.kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=jee.heng.sia@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitch@accuratesound.ca \
    --cc=serghox@gmail.com \
    --cc=stable@vger.kernel.org \
    --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