DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: dmaengine@vger.kernel.org, Frank.Li@kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v4 2/9] dmaengine: dw-edma: Terminate all descriptors without callbacks
Date: Thu, 16 Jul 2026 15:42:04 +0000	[thread overview]
Message-ID: <20260716154204.AFD5E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716152503.1747922-3-den@valinux.co.jp>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] If channel termination times out, the channel state becomes permanently wedged in BUSY, rendering it unusable.

Pre-existing issues:
- [High] Pre-existing missing locking in `dw_edma_device_pause()` causes data races with interrupt handlers.
--

--- Patch [2]: [PATCH v4 2/9] dmaengine: dw-edma: Terminate all descriptors without callbacks ---
commit 9db3cc9880b9ba6f4fe534fd17ede7df5d2a503f
Author: Koichiro Den <den@valinux.co.jp>

dmaengine: dw-edma: Terminate all descriptors without callbacks

This commit moves all issued and submitted descriptors to the terminated
list when termination completes. It also introduces a wait for pending
STOPs before releasing resources to prevent late callbacks from
dereferencing freed client state.

> diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c
> --- a/drivers/dma/dw-edma/dw-edma-core.c
> +++ b/drivers/dma/dw-edma/dw-edma-core.c
> @@ -673,8 +705,7 @@ static void dw_edma_done_interrupt(struct dw_edma_chan *chan)
>  			break;
>  
>  		case EDMA_REQ_STOP:
> -			list_del(&vd->node);
> -			vchan_cookie_complete(vd);
> +			dw_edma_terminate_all_descs(chan);
>  			chan->request = EDMA_REQ_NONE;
>  			chan->status = EDMA_ST_IDLE;
>  			break;

[Severity: High]
This is a pre-existing issue, but can dw_edma_device_pause() race with
the interrupt handler and wedge the channel?

dw_edma_device_pause() modifies chan->request and chan->status locklessly.

If it races with dw_edma_done_interrupt() (which holds the lock and sets
chan->status = EDMA_ST_IDLE here), dw_edma_device_pause() can concurrently
set chan->request = EDMA_REQ_PAUSE on an IDLE channel.

This leaves the channel in a state where dw_edma_device_resume() returns
-EPERM because it expects EDMA_ST_PAUSE, and dw_edma_device_issue_pending()
ignores it because chan->request is not EDMA_REQ_NONE, permanently
breaking the channel.

[ ... ]

> +static void dw_edma_free_chan_resources(struct dma_chan *dchan)
> +{
> +	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
> +
> +	dw_edma_device_terminate_all(dchan);
> +	dw_edma_device_synchronize(dchan);
> +
> +	scoped_guard(spinlock_irqsave, &chan->vc.lock)
> +		chan->configured = false;
> +
> +	vchan_free_chan_resources(&chan->vc);
>  }

[Severity: High]
If dw_edma_wait_termination() (called via dw_edma_device_synchronize)
times out, does the channel become permanently wedged in a BUSY state?

If the hardware fails to respond within 5 seconds, the timeout returns and
vchan_free_chan_resources() clears all descriptors.

If the hardware eventually finishes and raises a deferred DONE interrupt,
dw_edma_done_interrupt() is called. Because the descriptors were already
freed, vchan_next_desc() returns NULL.

Since the state reset logic (setting chan->request = EDMA_REQ_NONE and
chan->status = EDMA_ST_IDLE) is nested inside the if (vd) check in
dw_edma_done_interrupt(), it is completely skipped. This leaves the channel
stuck in EDMA_ST_BUSY and causes future dw_edma_alloc_chan_resources()
calls to fail with -EBUSY.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716152503.1747922-1-den@valinux.co.jp?part=2

  reply	other threads:[~2026-07-16 15:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 15:24 [PATCH v4 0/9] dmaengine: dw-edma: Fixes and interrupt-path groundwork Koichiro Den
2026-07-16 15:24 ` [PATCH v4 1/9] dmaengine: dw-edma: Fix HDMA channel status register access Koichiro Den
2026-07-16 15:24 ` [PATCH v4 2/9] dmaengine: dw-edma: Terminate all descriptors without callbacks Koichiro Den
2026-07-16 15:42   ` sashiko-bot [this message]
2026-07-16 16:30   ` Frank Li
2026-07-16 15:24 ` [PATCH v4 3/9] dmaengine: dw-edma: Serialize abort state updates Koichiro Den
2026-07-16 15:42   ` sashiko-bot
2026-07-16 15:24 ` [PATCH v4 4/9] dmaengine: dw-edma: Complete descriptors before pausing Koichiro Den
2026-07-16 15:45   ` sashiko-bot
2026-07-16 15:24 ` [PATCH v4 5/9] dmaengine: dw-edma: Serialize channel state checks Koichiro Den
2026-07-16 15:25 ` [PATCH v4 6/9] dmaengine: dw-edma: Clear stale requests on termination Koichiro Den
2026-07-16 15:25 ` [PATCH v4 7/9] dmaengine: dw-edma-pcie: Drop redundant pci_free_irq_vectors() Koichiro Den
2026-07-16 15:25 ` [PATCH v4 8/9] dmaengine: dw-edma: Snapshot the v0 interrupt status once per handler pass Koichiro Den
2026-07-16 15:25 ` [PATCH v4 9/9] dmaengine: dw-edma: Defer channel IRQ handling to workqueue Koichiro Den
2026-07-16 15:53   ` sashiko-bot

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=20260716154204.AFD5E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=den@valinux.co.jp \
    --cc=dmaengine@vger.kernel.org \
    --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