From: sashiko-bot@kernel.org
To: "Rui Wang" <wr574332525@163.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v7] dmaengine: dw-axi-dmac: report paused state and residue in tx_status
Date: Fri, 20 Nov 2026 10:21:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-224921@kernel.org> (raw)
In-Reply-To: <20261120101012.1789-1-wr574332525@163.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] dmaengine: dw-axi-dmac: wrong block match in
axi_chan_get_xferred()
- [Low] dmaengine: dw-axi-dmac: missing Fixes trailer for commit
8e55444da65c
--
commit c8d0c69cc29c111365ef5036a266d8a0e8d86f5b
Author: Rui Wang <wr574332525@163.com>
> dmaengine: dw-axi-dmac: report paused state and residue in tx_status
>
> The driver implements device_pause/device_resume, but device_tx_status
> keeps reporting DMA_IN_PROGRESS for a paused channel, so clients cannot
> tell a paused channel apart from a running one. Report DMA_PAUSED when
> the channel is paused and the cookie is still in flight, including for
> callers that pass a NULL dma_tx_state, and clear the stale is_paused
> flag in dma_chan_terminate_all(), which disables the channel and thus
> implicitly cancels the paused state.
>
> Also, the residue of an in-flight transfer is currently derived from
> the number of completed LLI blocks, so it only advances in block-size
> steps and stays stale for the duration of a large block. Read the
> current hardware pointer (CH_SAR for MEM_TO_DEV and MEM_TO_MEM, CH_DAR
> for DEV_TO_MEM) and walk the descriptor's LLIs to compute how many
> bytes have actually been transferred. The 64-bit pointer is sampled
> with a tearing-safe double read, as the transfer may be running
> concurrently. The pointer is only consulted for the descriptor most
> recently programmed into the hardware, tracked in the previously
> unused chan->desc field; any other descriptor has not been started yet
> and keeps reporting its full length. When the transfer has just
> completed but the descriptor has not been reaped yet, the pointer sits
> at the end of the last block and the residue naturally reads as 0. The
> pointer registers are pre-loaded with the first block's addresses when
> the channel is programmed, so a stale pointer left by a previous
> transfer (e.g. when its buffer is reused) can never be observed before
> the first LLI fetch completes. Cyclic descriptors keep the
> block-granular accounting.
>
> Tested on an FPGA platform.
>
> Signed-off-by: Rui Wang <wr574332525@163.com>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
[Severity: Low]
This restores the DMA_PAUSED check and fixes the burst-granularity residue
reporting in dma_chan_tx_status(). Should this include:
Fixes: 8e55444da65c ("dmaengine: dw-axi-dmac: Support burst residue granularity")
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 7520c78f55ccf..5e90d7d6c3282 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -355,33 +355,110 @@ static void vchan_desc_put(struct virt_dma_desc *vdesc)
> axi_desc_put(vd_to_axi_desc(vdesc));
> }
>
> +/*
> + * Read a 64-bit channel address register while the transfer may be
> + * running. The two 32-bit halves cannot be read atomically on all
> + * platforms, so sample the high half before and after the low half
> + * and retry if it moved (the low half wrapped in between).
> + */
> +static u64 axi_chan_readq(struct axi_dma_chan *chan, u32 reg)
> +{
> + u32 hi, lo, hi2;
> +
> + do {
> + hi = readl(chan->chan_regs + reg + 4);
> + lo = readl(chan->chan_regs + reg);
> + hi2 = readl(chan->chan_regs + reg + 4);
> + } while (unlikely(hi != hi2));
> +
> + return (u64)hi << 32 | lo;
> +}
> +
> +/*
> + * Return the number of bytes already transferred by the descriptor
> + * currently on the hardware (running, paused or just completed), based
> + * on the current read or write position: CH_SAR for MEM_TO_DEV and
> + * MEM_TO_MEM, CH_DAR for DEV_TO_MEM. Must be called with vc.lock held.
> + */
> +static u32 axi_chan_get_xferred(struct axi_dma_chan *chan,
> + struct axi_dma_desc *desc)
> +{
> + struct axi_dma_hw_desc *hw_desc;
> + bool dst = chan->direction == DMA_DEV_TO_MEM;
> + u64 pos, start;
> + u32 xferred = 0;
> + int i;
> +
> + pos = axi_chan_readq(chan, dst ? CH_DAR : CH_SAR);
> +
> + for (i = 0; i < desc->nr_hw_descs; i++) {
> + hw_desc = &desc->hw_desc[i];
> + start = le64_to_cpu(dst ? hw_desc->lli->dar : hw_desc->lli->sar);
> +
> + /* Current position is inside this block: partial progress */
> + if (pos >= start && pos <= start + hw_desc->len)
> + return xferred + (u32)(pos - start);
[Severity: Medium]
Can axi_chan_get_xferred() match the wrong LLI block when a scatter-gather
transfer reuses the same physical buffer across multiple SG entries (such
as SPI dummy transfers using a shared zero or scratch page) or when a later
SG block sits immediately below an earlier one in physical memory so its
end address equals the earlier block's start?
Because the loop checks only the address range without consulting CH_LLP to
identify the active LLI, pos matches the earlier entry in desc->hw_desc[]
and reports a smaller transferred byte count, causing the reported DMA
residue to jump backwards.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120101012.1789-1-wr574332525@163.com?part=1
prev parent reply other threads:[~2026-11-20 10:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:10 [PATCH v7] dmaengine: dw-axi-dmac: report paused state and residue in tx_status Rui Wang
2026-11-20 10:21 ` 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-224921@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
--cc=wr574332525@163.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.