DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jelly Jia" <Jelly.Jia@cixtech.com>
Cc: devicetree@vger.kernel.org, dmaengine@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, vkoul@kernel.org,
	Frank.Li@kernel.org
Subject: Re: [PATCH v7 04/10] dmaengine: arm-dma350: Serialize IRQ and termination state
Date: Tue, 17 Nov 2026 10:03:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-218565@kernel.org> (raw)
In-Reply-To: <20261117094335.1393735-5-Jelly.Jia@cixtech.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: arm-dma350: stale CH_STATUS bits left latched
  across stop and teardown
--

commit 2d57cff302a30b3310a5e4ef93f2c69bd2b47684
Author: Jelly Jia <Jelly.Jia@cixtech.com>

dmaengine: arm-dma350: Serialize IRQ and termination state

This commit serializes CH_STATUS sampling and active descriptor handling
under the channel lock, and waits for STOPCMD and IRQ completion during
channel synchronization and resource teardown.

> diff --git a/drivers/dma/arm-dma350.c b/drivers/dma/arm-dma350.c
> index 266df7923d7f8..af1b030b955f5 100644
> --- a/drivers/dma/arm-dma350.c
> +++ b/drivers/dma/arm-dma350.c

[ ... ]

> @@ -458,28 +482,44 @@ static void d350_start_next(struct d350_chan *dch)
>  static void d350_issue_pending(struct dma_chan *chan)
>  {
>  	struct d350_chan *dch = to_d350_chan(chan);
> -	unsigned long flags;
>  
> -	spin_lock_irqsave(&dch->vc.lock, flags);
> +	guard(spinlock_irqsave)(&dch->vc.lock);
> +
>  	if (vchan_issue_pending(&dch->vc) && !dch->desc)
>  		d350_start_next(dch);
> -	spin_unlock_irqrestore(&dch->vc.lock, flags);
>  }
>  
>  static irqreturn_t d350_irq(int irq, void *data)
>  {
>  	struct d350_chan *dch = data;
> -	struct device *dev = dch->vc.chan.device->dev;
> -	struct virt_dma_desc *vd = &dch->desc->vd;
> +	struct virt_dma_desc *vd;
> +	struct d350_desc *desc;
> +	u32 residue;
>  	u32 ch_status;
> +	u32 irq_status;
> +	u32 errinfo = 0;
> +
> +	/* Keep the sampled status paired with the active descriptor. */
> +	guard(spinlock)(&dch->vc.lock);
>  
>  	ch_status = readl(dch->base + CH_STATUS);
> -	if (!ch_status)
> +	irq_status = ch_status & (CH_STAT_INTR_DONE | CH_STAT_INTR_ERR);
> +	if (!irq_status)
>  		return IRQ_NONE;
>  
> -	if (ch_status & CH_STAT_INTR_ERR) {
> -		u32 errinfo = readl_relaxed(dch->base + CH_ERRINFO);
> +	/* INTR bits are read-only; clearing W1C STAT_ERR also clears ERRINFO. */
> +	if (irq_status & CH_STAT_INTR_ERR)
> +		errinfo = readl_relaxed(dch->base + CH_ERRINFO);
> +
> +	writel_relaxed(ch_status & (CH_STAT_DONE | CH_STAT_ERR),
> +		       dch->base + CH_STATUS);

[ ... ]

> @@ -513,6 +549,7 @@ static int d350_alloc_chan_resources(struct dma_chan *chan)
>  	struct d350_chan *dch = to_d350_chan(chan);
>  	int ret = request_irq(dch->irq, d350_irq, IRQF_SHARED,
>  			      vchan_chan_name(&dch->vc), dch);
> +
>  	if (!ret)
>  		writel_relaxed(CH_INTREN_DONE | CH_INTREN_ERR, dch->base + CH_INTREN);
>  
> @@ -524,7 +561,11 @@ static void d350_free_chan_resources(struct dma_chan *chan)
>  	struct d350_chan *dch = to_d350_chan(chan);
>  
>  	writel_relaxed(0, dch->base + CH_INTREN);
> +	d350_terminate_all(chan);
> +	d350_wait_for_stop(dch);
> +
>  	free_irq(dch->irq, dch);
> +	vchan_synchronize(&dch->vc);
>  	vchan_free_chan_resources(&dch->vc);
>  }

[Severity: Medium]
Can clearing CH_INTREN before stopping the channel leave CH_STAT_DONE or
CH_STAT_ERR latched in CH_STATUS across channel teardown?

In DMA-350, CH_STAT_DONE and CH_STAT_ERR are sticky W1C bits, whereas
CH_STAT_INTR_DONE and CH_STAT_INTR_ERR are gated by CH_INTREN.  Because
d350_free_chan_resources() clears CH_INTREN before calling
d350_terminate_all() and d350_wait_for_stop(), a transfer that completes or
faults just before CH_INTREN is cleared (or while stopping) leaves
CH_STAT_DONE or CH_STAT_ERR set while CH_STAT_INTR_DONE and
CH_STAT_INTR_ERR read as 0.  Even if d350_irq() is already in flight, it
now checks irq_status and returns IRQ_NONE without clearing CH_STATUS.

When the channel is later re-allocated in d350_alloc_chan_resources() and
CH_INTREN_DONE | CH_INTREN_ERR is written to CH_INTREN, the stale status
bit immediately asserts an interrupt that can race with d350_start_next()
and prematurely complete or fail a newly started transfer.  Clearing
CH_STAT_DONE | CH_STAT_ERR after d350_wait_for_stop() (or before enabling
CH_INTREN) would avoid this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117094335.1393735-1-Jelly.Jia@cixtech.com?part=4

  reply	other threads:[~2026-11-17 10:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:43 [PATCH v7 00/10] dmaengine: arm-dma350: Add slave support and Sky1 integration Jelly Jia
2026-11-17  9:43 ` [PATCH v7 01/10] dmaengine: arm-dma350: Fix source trigger bit Jelly Jia
2026-11-17  9:43 ` [PATCH v7 02/10] dmaengine: arm-dma350: Check DMA mask setup errors Jelly Jia
2026-11-17  9:43 ` [PATCH v7 03/10] dmaengine: arm-dma350: Initialize channel coherency Jelly Jia
2026-11-17  9:43 ` [PATCH v7 04/10] dmaengine: arm-dma350: Serialize IRQ and termination state Jelly Jia
2026-11-17 10:03   ` sashiko-bot [this message]
2026-11-17  9:43 ` [PATCH v7 05/10] dmaengine: arm-dma350: Report submitted descriptor status Jelly Jia
2026-11-17  9:43 ` [PATCH v7 06/10] dmaengine: arm-dma350: Use managed device registration Jelly Jia
2026-11-17  9:43 ` [PATCH v7 07/10] dmaengine: arm-dma350: Track descriptor byte lengths explicitly Jelly Jia
2026-11-17  9:43 ` [PATCH v7 08/10] dmaengine: arm-dma350: Add slave and cyclic transfer support Jelly Jia
2026-11-17  9:43 ` [PATCH v7 09/10] dt-bindings: dma: arm,dma-350: Describe the CIX Sky1 integration Jelly Jia
2026-11-17  9:43 ` [PATCH v7 10/10] dmaengine: arm-dma350: Support integration clocks and resets Jelly Jia

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-218565@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=Jelly.Jia@cixtech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=robh@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