DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Binbin Zhou" <zhoubinbin@loongson.cn>, dmaengine@vger.kernel.org
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 4/4] dmaengine: loongson: loongson2-apb-cmc-dma: Add pause/resume support
Date: Mon, 26 Oct 2026 09:35:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-184805@kernel.org> (raw)
In-Reply-To: <92800ae186112366116647ee4f50d4ba09249ef8.1792988985.git.zhoubinbin@loongson.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] dmaengine: loongson: loongson2_cmc_dma_start_transfer() clears pause state
- [Medium] dmaengine: loongson: loongson2_cmc_dma_tx_status() ignores pause if !state
--

commit 8e161a43d78d90e76eaddc39b1b96c7a28b1dd6c
Author: Binbin Zhou <zhoubinbin@loongson.cn>

dmaengine: loongson: loongson2-apb-cmc-dma: Add pause/resume support

This commit adds pause and resume support to the Loongson-2 APB CMC DMA
driver by clearing and restoring LOONGSON2_CMCDMA_CCR_EN while preserving
the hardware transfer position. It also updates status reporting and
cyclic scatterlist advancement to honor the paused state.

> diff --git a/drivers/dma/loongson/loongson2-apb-cmc-dma.c b/drivers/dma/loongson/loongson2-apb-cmc-dma.c
> index c654e05729024..a4153ea854623 100644
> --- a/drivers/dma/loongson/loongson2-apb-cmc-dma.c
> +++ b/drivers/dma/loongson/loongson2-apb-cmc-dma.c

[ ... ]

> @@ -184,6 +185,8 @@ static void loongson2_cmc_dma_stop(struct loongson2_cmc_dma_chan *lchan)
>  	loongson2_cmc_dma_write(lddev, LOONGSON2_CMCDMA_CCR, lchan->id, ccr);
>  
>  	loongson2_cmc_dma_irq_clear(lchan, LOONGSON2_CMCDMA_MASKI);
> +
> +	lchan->paused = false;
>  }

[Severity: Medium]
Can this reset lchan->paused and restart DMA when a segment completion
interrupt races with loongson2_cmc_dma_pause() on a non-cyclic transfer?

loongson2_cmc_dma_pause() allows pausing any channel with an active
lchan->desc, including non-cyclic slave_sg transfers. If a scatterlist
segment finishes and latches LOONGSON2_CMCDMA_TCI just before
loongson2_cmc_dma_pause() acquires lchan->vchan.lock and sets
lchan->paused = true, the interrupt handler will subsequently run:

  loongson2_cmc_dma_chan_irq()
    -> loongson2_cmc_dma_handle_chan_done()
      -> loongson2_cmc_dma_start_transfer()

Unlike the cyclic path in loongson2_cmc_dma_configure_next_sg(), the
non-cyclic path in loongson2_cmc_dma_handle_chan_done() calls
loongson2_cmc_dma_start_transfer():

	loongson2_cmc_dma_stop(lchan);
	...
	/* Start DMA */
	reg->ccr |= LOONGSON2_CMCDMA_CCR_EN;
	loongson2_cmc_dma_write(lddev, LOONGSON2_CMCDMA_CCR, lchan->id, reg->ccr);

This clears lchan->paused = false in loongson2_cmc_dma_stop() and
unconditionally sets LOONGSON2_CMCDMA_CCR_EN for the next scatterlist
entry or next queued descriptor. Should non-cyclic scatterlist
advancement also preserve lchan->paused and avoid re-enabling the channel
while paused?

[ ... ]

> @@ -534,6 +545,13 @@ static enum dma_status loongson2_cmc_dma_tx_status(struct dma_chan *chan, dma_co
>  			/* Active descriptor: compute residue from hardware progress */
>  			state->residue = loongson2_cmc_dma_desc_residue(lchan, lchan->desc,
>  									lchan->next_sg);
> +			/*
> +			 * A paused channel still has an active descriptor but is not making
> +			 * progress. Report DMA_PAUSED so clients can distinguish it from a
> +			 * running transfer.
> +			 */
> +			if (lchan->paused && status == DMA_IN_PROGRESS)
> +				status = DMA_PAUSED;
>  		} else if (vdesc) {
>  			/* Queued descriptor not yet started: residue is the total length */
>  			struct loongson2_cmc_dma_desc *ldesc = to_lmdma_desc(vdesc);

[Severity: Medium]
What happens if a client queries transfer status on a paused channel with
a NULL state pointer, such as via dmaengine_tx_status(chan, cookie, NULL)
or dma_async_is_tx_complete()?

Earlier in loongson2_cmc_dma_tx_status():

	status = dma_cookie_status(chan, cookie, state);
	if (status == DMA_COMPLETE || !state)
		return status;

When state is NULL, loongson2_cmc_dma_tx_status() returns early before
acquiring lchan->vchan.lock and checking lchan->paused, so it will return
DMA_IN_PROGRESS instead of DMA_PAUSED for the active paused descriptor.
Should the lchan->paused check still be performed when state is NULL?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1792988985.git.zhoubinbin@loongson.cn?part=4

      reply	other threads:[~2026-10-26  9:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26  4:31 [PATCH 0/4] loongson2-apb-cmc-dma: Fixes issues and pause/resume support Binbin Zhou
2026-10-26  4:31 ` [PATCH 1/4] dmaengine: loongson: loongson2-apb-cmc-dma: Fix cyclic residue wrap NULL dereference Binbin Zhou
2026-10-26  9:17   ` sashiko-bot
2026-10-27 11:16     ` Binbin Zhou
2026-10-26  4:31 ` [PATCH 2/4] dmaengine: loongson: loongson2-apb-cmc-dma: Fix residue for queued descriptors Binbin Zhou
2026-10-28 16:06   ` Frank Li
2026-10-26  4:31 ` [PATCH 3/4] dmaengine: loongson: loongson2-apb-cmc-dma: Program CNDTR when advancing sg Binbin Zhou
2026-10-28 16:12   ` Frank Li
2026-10-29  7:41     ` Binbin Zhou
2026-10-26  4:31 ` [PATCH 4/4] dmaengine: loongson: loongson2-apb-cmc-dma: Add pause/resume support Binbin Zhou
2026-10-26  9:35   ` 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-184805@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --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 \
    --cc=zhoubinbin@loongson.cn \
    /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