All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 1/3] dmaengine: dw-axi-dmac: poll the correct enable bit during termination
Date: Mon, 09 Nov 2026 05:10:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-204416@kernel.org> (raw)
In-Reply-To: <20261108-submit-dw-axi-dma-stop-pause-v1-v1-1-c48ec19e9ee4@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] dmaengine: dw-axi-dmac: use-after-free in
  dma_chan_terminate_all() [1]
--

commit af0999f332d674abe73e6d4b71aee90f2aef6ba8
Author: James Hilliard <james.hilliard1@gmail.com>

dmaengine: dw-axi-dmac: poll the correct enable bit during termination

This commit updates dma_chan_terminate_all() to poll axi_chan_is_hw_enable()
so that upper-bank channel enable bits (channels 16 through 31) are checked
before freeing descriptors.

> 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 7520c78f55ccf..49f65486e8626 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -1181,16 +1181,15 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
>  static int dma_chan_terminate_all(struct dma_chan *dchan)
>  {
>  	struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan);
> -	u32 chan_active = BIT(chan->id) << DMAC_CHAN_EN_SHIFT;
>  	unsigned long flags;
> -	u32 val;
> +	bool enabled;
>  	int ret;
>  	LIST_HEAD(head);
>  
>  	axi_chan_disable(chan);
>  
> -	ret = readl_poll_timeout_atomic(chan->chip->regs + DMAC_CHEN, val,
> -					!(val & chan_active), 1000, 50000);
> +	ret = read_poll_timeout_atomic(axi_chan_is_hw_enable, enabled, !enabled,
> +				      1000, 50000, false, chan);

[Severity: Critical]
This problem wasn't introduced by this patch, but can dma_chan_terminate_all()
race with dma_chan_issue_pending() [1] and free descriptors while the
channel is active?

axi_chan_disable() and the poll loop run before chan->vc.lock is acquired:

CPU0                                  CPU1
dma_chan_terminate_all()
  axi_chan_disable(chan)
  read_poll_timeout_atomic(...)
                                      dma_chan_issue_pending()
                                        spin_lock_irqsave(&chan->vc.lock, ...)
                                        vchan_issue_pending(&chan->vc)
                                        axi_chan_start_first_queued(chan)
                                        spin_unlock_irqrestore(...)
  spin_lock_irqsave(&chan->vc.lock, ...)
  vchan_get_all_descriptors(&chan->vc, &head)
  spin_unlock_irqrestore(...)
  vchan_dma_desc_free_list(&chan->vc, &head)  <-- use-after-free by DMA

Because CPU1 re-enables the channel after the poll finishes, the hardware
continues processing descriptors that CPU0 then collects and frees.

[1] https://sashiko.dev/#/bug/linux-d3e7b3db-d97f-48be-a317-9ef1a4cd9953

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-submit-dw-axi-dma-stop-pause-v1-v1-0-c48ec19e9ee4@gmail.com?part=1

  reply	other threads:[~2026-11-09  5:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  5:02 [PATCH 0/3] dmaengine: dw-axi-dmac: fix termination and pause acknowledgment James Hilliard
2026-11-09  5:02 ` [PATCH 1/3] dmaengine: dw-axi-dmac: poll the correct enable bit during termination James Hilliard
2026-11-09  5:10   ` sashiko-bot [this message]
2026-11-09  5:38     ` James Hilliard
2026-11-09 22:49   ` Andy Shevchenko
2026-11-09  5:02 ` [PATCH 2/3] dmaengine: dw-axi-dmac: retain descriptors when termination times out James Hilliard
2026-11-09  5:02 ` [PATCH 3/3] dmaengine: dw-axi-dmac: preserve suspension status until pause observes it James Hilliard
2026-11-09  5:17   ` sashiko-bot
2026-11-09  5:57     ` James Hilliard

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-204416@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=james.hilliard1@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 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.