DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sergey Matsievskiy" <matsievskiysv@gmail.com>,
	dmaengine@vger.kernel.org
Cc: vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH] dmaengine: axi-dmac: change IRQ to threaded mode
Date: Tue, 17 Nov 2026 06:45:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-218277@kernel.org> (raw)
In-Reply-To: <20261117060124.27914-1-matsievskiysv@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] dmaengine: axi-dmac: threaded IRQ race with
  axi_dmac_synchronize()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] dmaengine: dma-axi-dmac: cyclic desc use-after-free in
  axi_dmac_terminate_all() [1]
--

commit fcedf11ce19d4d148f53f6d8bd9c6a0e04ee8801
Author: Sergey Matsievskiy <matsievskiysv@gmail.com>

dmaengine: axi-dmac: change IRQ to threaded mode

This commit converts axi_dmac_interrupt_handler() to a threaded interrupt
handler using devm_request_threaded_irq() and switches vchan.lock acquisition
in the handler to spin_lock_irqsave().

> diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
> index dbc31b185c4d4..c4b6f6ae6be8c 100644
> --- a/drivers/dma/dma-axi-dmac.c
> +++ b/drivers/dma/dma-axi-dmac.c
> @@ -582,6 +582,7 @@ static irqreturn_t axi_dmac_interrupt_handler(int irq, void *devid)
>  {
>  	struct axi_dmac *dmac = devid;
>  	unsigned int pending;
> +	unsigned long flags;
>  	bool start_next = false;
>  
>  	pending = axi_dmac_read(dmac, AXI_DMAC_REG_IRQ_PENDING);
> @@ -590,7 +591,7 @@ static irqreturn_t axi_dmac_interrupt_handler(int irq, void *devid)
>  
>  	axi_dmac_write(dmac, AXI_DMAC_REG_IRQ_PENDING, pending);
>  
> -	spin_lock(&dmac->chan.vchan.lock);
> +	spin_lock_irqsave(&dmac->chan.vchan.lock, flags);
>  	/* One or more transfers have finished */
>  	if (pending & AXI_DMAC_IRQ_EOT) {
>  		unsigned int completed;

[Severity: High]
This problem wasn't introduced by this patch, but can axi_dmac_terminate_all()
cause a use-after-free on the active cyclic descriptor [1] in
vchan_complete()?

CPU0                              CPU1
axi_dmac_interrupt_handler()
  axi_dmac_transfer_done()
    vchan_cyclic_callback()
      vc->cyclic = vd;
      tasklet_schedule(&vc->task)
                                  axi_dmac_terminate_all()
                                    list_splice_tail_init(..., &head)
                                    vchan_dma_desc_free_list(..., &head)
                                      axi_dmac_desc_free()
vchan_complete()
  vd = vc->cyclic;
  dmaengine_desc_get_callback(&vd->tx, &cb)  <-- use-after-free

axi_dmac_terminate_all() splices chan->active_descs into its free list and
frees the descriptors without calling vchan_terminate_vdesc(), leaving
vc->cyclic pointing to the freed axi_dmac_desc when the scheduled tasklet
runs.

> @@ -601,7 +602,7 @@ static irqreturn_t axi_dmac_interrupt_handler(int irq, void *devid)
>  	/* Space has become available in the descriptor queue */
>  	if ((pending & AXI_DMAC_IRQ_SOT) || start_next)
>  		axi_dmac_start_transfer(&dmac->chan);
> -	spin_unlock(&dmac->chan.vchan.lock);
> +	spin_unlock_irqrestore(&dmac->chan.vchan.lock, flags);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -1317,8 +1318,10 @@ static int axi_dmac_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_request_irq(&pdev->dev, dmac->irq, axi_dmac_interrupt_handler,
> -			       IRQF_SHARED, dev_name(&pdev->dev), dmac);
> +	ret = devm_request_threaded_irq(&pdev->dev, dmac->irq, NULL,
> +					axi_dmac_interrupt_handler,
> +					IRQF_SHARED | IRQF_ONESHOT,
> +					dev_name(&pdev->dev), dmac);

[Severity: High]
Does moving axi_dmac_interrupt_handler() to a thread without updating
axi_dmac_synchronize() and axi_dmac_terminate_all() introduce a race with
channel termination and teardown?

axi_dmac_synchronize() only calls vchan_synchronize() (which kills the vchan
tasklet) and does not call synchronize_irq(dmac->irq), while
axi_dmac_interrupt_handler() reads and clears AXI_DMAC_REG_IRQ_PENDING before
acquiring dmac->chan.vchan.lock:

CPU0 (IRQ thread)                 CPU1
axi_dmac_interrupt_handler()
  pending = axi_dmac_read(...)
  axi_dmac_write(..., pending)
                                  dmaengine_terminate_sync()
                                    axi_dmac_terminate_all()
                                    axi_dmac_synchronize()
                                      vchan_synchronize()
                                  axi_dmac_issue_pending()
                                    axi_dmac_start_transfer()
  spin_lock_irqsave(&vchan.lock)
  axi_dmac_transfer_done()
    list_del(&active->vdesc.node)
    vchan_cookie_complete()       <-- completes and frees new transfer

When an interrupt fires just before dmaengine_terminate_sync(), the woken IRQ
thread can run after a new transfer is issued and apply the stale
AXI_DMAC_IRQ_EOT to the new descriptor on chan->active_descs.  In chan->hw_sg
mode, axi_dmac_transfer_done() unconditionally pops and completes the head of
chan->active_descs, freeing the descriptor and its chan->pool SG entries via
axi_dmac_desc_free() while DMA hardware is still using them.

Similarly, during dma_release_channel(), an in-flight IRQ thread can run after
vchan_synchronize() and schedule the vchan tasklet while
axi_dmac_free_chan_resources() is destroying chan->pool.

[1] https://sashiko.dev/#/bug/linux-b5d0e7ef-3ad0-4c97-9c79-1694077caf95

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117060124.27914-1-matsievskiysv@gmail.com?part=1

      reply	other threads:[~2026-11-17  6:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  6:01 [PATCH] dmaengine: axi-dmac: change IRQ to threaded mode Sergey Matsievskiy
2026-11-17  6:45 ` sashiko-bot [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=sashiko-outbox-218277@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=matsievskiysv@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --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