DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: Frank.Li@kernel.org, vkoul@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH 3/7] dmaengine: dw-edma: Clean up vchan descriptors on termination
Date: Fri, 10 Jul 2026 08:24:24 +0000	[thread overview]
Message-ID: <20260710082424.6CD7B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260710080903.2392888-4-den@valinux.co.jp>

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

Pre-existing issues:
- [High] Data race in dw_edma_abort_interrupt leads to permanently stalled DMA channels.
- [High] Missing lock protection in pause and resume paths leads to list corruption and data races.
--

--- Patch [3]: [PATCH 3/7] dmaengine: dw-edma: Clean up vchan descriptors on termination ---
commit 7bc17c43c74d58634aed20f3d0b0b4c9f907d26a
Author: Koichiro Den <den@valinux.co.jp>

dmaengine: dw-edma: Clean up vchan descriptors on termination

This patch cleans up virtual channel descriptors when a channel is terminated.
It moves issued and submitted descriptors to the terminated list whenever a
termination request completes, preventing leaked descriptors or restarting
work that was already terminated. It also changes the busy-polling wait
loop to use usleep_range() and cond_resched() instead of busy-polling.

> diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c
> index 4e0dc52397e2e..1b493c104a5b1 100644
> --- a/drivers/dma/dw-edma/dw-edma-core.c
> +++ b/drivers/dma/dw-edma/dw-edma-core.c
[ ... ]
> @@ -313,20 +337,25 @@ static int dw_edma_device_resume(struct dma_chan *dchan)
>  static int dw_edma_device_terminate_all(struct dma_chan *dchan)
>  {

[Severity: High]
This is a pre-existing issue, but can the lack of lock protection in the
pause and resume paths lead to list corruption and data races?

In dw_edma_device_resume() and dw_edma_device_pause(), the channel state is
modified concurrently without holding chan->vc.lock:

dw_edma_device_resume() {
    ...
    } else {
        chan->status = EDMA_ST_BUSY;
        dw_edma_start_transfer(chan);
    }
    ...
}

Calling dw_edma_start_transfer() unlocked invokes vchan_next_desc() (which
triggers lockdep_assert_held()) and modifies child->list with list_del().
Concurrent calls to dw_edma_device_pause() or dw_edma_device_resume(), or
in-flight interrupts, will corrupt the list pointers leading to a kernel
panic.

Should these functions acquire chan->vc.lock before modifying state and
calling dw_edma_start_transfer()?

>  	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
> +	unsigned long flags;
>  	int err = 0;
>  
> +	spin_lock_irqsave(&chan->vc.lock, flags);
>  	if (!chan->configured) {
[ ... ]
> @@ -680,7 +710,7 @@ static void dw_edma_done_interrupt(struct dw_edma_chan *chan)
>  			break;
>  
>  		case EDMA_REQ_STOP:
> -			dw_edma_terminate_vdesc(vd);
> +			dw_edma_terminate_all_descs(chan);
>  			chan->request = EDMA_REQ_NONE;
>  			chan->status = EDMA_ST_IDLE;
>  			break;

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential data
race in dw_edma_abort_interrupt() that could lead to permanently stalled
DMA channels.

In dw_edma_abort_interrupt(), the spinlock is released before chan->request
and chan->status are updated:

dw_edma_abort_interrupt() {
    ...
    spin_unlock_irqrestore(&chan->vc.lock, flags);
    chan->request = EDMA_REQ_NONE;
    chan->status = EDMA_ST_IDLE;
}

If a client concurrently calls dw_edma_device_issue_pending(), it will
acquire the lock, observe the old state (not IDLE), and skip starting the
transfer. Then the interrupt handler updates the state to IDLE outside the
lock. The pending descriptors remain on the queue but the hardware is never
started.

Could the state updates be moved inside the locked region to prevent this?

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

  reply	other threads:[~2026-07-10  8:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  8:08 [PATCH 0/7] dmaengine: dw-edma: Fixes and interrupt-path groundwork Koichiro Den
2026-07-10  8:08 ` [PATCH 1/7] dmaengine: dw-edma: Fix HDMA channel status register access Koichiro Den
2026-07-10  8:19   ` sashiko-bot
2026-07-10 21:26   ` Frank Li
2026-07-13  5:17     ` Koichiro Den
2026-07-10  8:08 ` [PATCH 2/7] dmaengine: dw-edma: Terminate STOP requests without callbacks Koichiro Den
2026-07-10  8:26   ` sashiko-bot
2026-07-11 14:27   ` Frank Li
2026-07-10  8:08 ` [PATCH 3/7] dmaengine: dw-edma: Clean up vchan descriptors on termination Koichiro Den
2026-07-10  8:24   ` sashiko-bot [this message]
2026-07-11 14:39   ` Frank Li
2026-07-10  8:09 ` [PATCH 4/7] dmaengine: dw-edma: Serialize channel state checks Koichiro Den
2026-07-10  8:28   ` sashiko-bot
2026-07-10  8:09 ` [PATCH 5/7] dmaengine: dw-edma-pcie: Drop redundant pci_free_irq_vectors() Koichiro Den
2026-07-11 14:41   ` Frank Li
2026-07-10  8:09 ` [PATCH 6/7] dmaengine: dw-edma: Snapshot the v0 interrupt status once per handler pass Koichiro Den
2026-07-11 14:44   ` Frank Li
2026-07-10  8:09 ` [PATCH 7/7] dmaengine: dw-edma: Defer channel IRQ handling to workqueue Koichiro Den
2026-07-10  8:24   ` sashiko-bot
2026-07-11 14:55   ` 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=20260710082424.6CD7B1F00A3A@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