From: Frank Li <Frank.li@oss.nxp.com>
To: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Binbin Zhou <zhoubb.aaron@gmail.com>,
Huacai Chen <chenhuacai@loongson.cn>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Vinod Koul <vkoul@kernel.org>,
Frank Li <Frank.Li@kernel.org>,
dmaengine@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>,
Xuerui Wang <kernel@xen0n.name>,
loongarch@lists.linux.dev, devicetree@vger.kernel.org,
Keguang Zhang <keguang.zhang@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 2/4] dmaengine: loongson: loongson2-apb-cmc-dma: Fix residue for queued descriptors
Date: Wed, 28 Oct 2026 12:06:48 -0400 [thread overview]
Message-ID: <auIdmAvMsz193TLx@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <bd120f2c1ab291645a21b1cf9babdfcc0412cac7.1792988985.git.zhoubinbin@loongson.cn>
On Mon, Oct 26, 2026 at 12:31:21PM +0800, Binbin Zhou wrote:
> tx_status() computes residue for both the active and the queued
> descriptors through loongson2_cmc_dma_desc_residue(), which reads the
> hardware CNDTR register. For a descriptor that has not started yet that
> register does not describe its transfer, so clients can observe a
> residue that does not match the amount of data still to be moved.
why this happen, suppose write CNDTR at loongson2_cmc_dma_start_transfer()
when issue pending.
Maybe there are raise condition, between send to issue list and start_transfer()
suppose loongson2_cmc_dma_tx_status() should not find vdesc by cookie id
if issue pending have not complete yet.
Maybe move loongson2_cmc_dma_start_transfer() into lchan->vchan.lock, you
will not see this problem.
Frank
>
> Report residue from the descriptor length for queued transfers, and keep
> the hardware-based calculation only for the active descriptor.
>
> Cc: stable@vger.kernel.org
> Fixes: 1c0028e725f1 ("dmaengine: loongson: New driver for the Loongson Multi-Channel DMA controller")
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
> drivers/dma/loongson/loongson2-apb-cmc-dma.c | 23 ++++++++++++++++----
> 1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma/loongson/loongson2-apb-cmc-dma.c b/drivers/dma/loongson/loongson2-apb-cmc-dma.c
> index f090fbe0b8a1..8b8d530d60c3 100644
> --- a/drivers/dma/loongson/loongson2-apb-cmc-dma.c
> +++ b/drivers/dma/loongson/loongson2-apb-cmc-dma.c
> @@ -472,6 +472,17 @@ loongson2_cmc_dma_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, si
> return vchan_tx_prep(&lchan->vchan, &desc->vdesc, flags);
> }
>
> +static size_t loongson2_cmc_dma_desc_total_len(struct loongson2_cmc_dma_desc *desc)
> +{
> + size_t total = 0;
> + u32 i;
> +
> + for (i = 0; i < desc->num_sgs; i++)
> + total += desc->sg_req[i].len;
> +
> + return total;
> +}
> +
> static size_t loongson2_cmc_dma_desc_residue(struct loongson2_cmc_dma_chan *lchan,
> struct loongson2_cmc_dma_desc *desc, u32 next_sg)
> {
> @@ -518,12 +529,16 @@ static enum dma_status loongson2_cmc_dma_tx_status(struct dma_chan *chan, dma_co
>
> scoped_guard(spinlock_irqsave, &lchan->vchan.lock) {
> vdesc = vchan_find_desc(&lchan->vchan, cookie);
> - if (lchan->desc && cookie == lchan->desc->vdesc.tx.cookie)
> + if (lchan->desc && cookie == lchan->desc->vdesc.tx.cookie) {
> + /* Active descriptor: compute residue from hardware progress */
> state->residue = loongson2_cmc_dma_desc_residue(lchan, lchan->desc,
> lchan->next_sg);
> - else if (vdesc)
> - state->residue = loongson2_cmc_dma_desc_residue(lchan,
> - to_lmdma_desc(vdesc), 0);
> + } else if (vdesc) {
> + /* Queued descriptor not yet started: residue is the total length */
> + struct loongson2_cmc_dma_desc *ldesc = to_lmdma_desc(vdesc);
> +
> + state->residue = loongson2_cmc_dma_desc_total_len(ldesc);
> + }
> }
>
> return status;
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-10-28 16:07 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 [this message]
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
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=auIdmAvMsz193TLx@lizhi-Precision-Tower-5810 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=keguang.zhang@gmail.com \
--cc=kernel@xen0n.name \
--cc=krzk+dt@kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=vkoul@kernel.org \
--cc=zhoubb.aaron@gmail.com \
--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