Re: [PATCH v8 6/9] dmaengine: dw-axi-dmac: retain descriptors until callbacks drain
From: James Hilliard
Date: Thu Nov 19 2026 - 12:07:29 EST
On Thu, Nov 19, 2026 at 9:41 AM Frank Li <Frank.li@xxxxxxxxxxx> wrote:
>
> On Thu, Nov 19, 2026 at 09:01:01AM -0700, James Hilliard wrote:
> > Termination frees every descriptor while a pending period callback can
> > still refer to one through vc->cyclic. An executing callback has already
> > cleared that pointer, but still receives a pointer to the descriptor's
> > tx_result and can use it after termination frees the descriptor.
> >
> > An error interrupt can also move the cyclic descriptor to desc_completed
> > before termination. Looking only at the head of desc_issued therefore
> > does not cover every pending cyclic callback.
> >
> > Use vchan_terminate_all() after stopping the channel to clear the pending
> > alias and move the collected descriptors to desc_terminated. The existing
> > synchronize callback drains the tasklet before reclaiming that list.
> > Descriptors already detached onto the tasklet's private completed list
> > remain owned by the tasklet. Repeated termination preserves the retired
> > list, including when called from a completion callback.
> >
> > Fixes: 1deb96c0fa58 ("dmaegine: dw-axi-dmac: Support device_prep_dma_cyclic()")
> > Reported-by: Wang YuWei <1973615295@xxxxxx>
> > Link: https://lore.kernel.org/r/tencent_C00D995A9F70206DFD1330DCB1222EEBCB07@xxxxxx/
> > Reported-by: Mitch Barnett <mitch@xxxxxxxxxxxxxxxx>
> > Cc: Wang YuWei <1973615295@xxxxxx>
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> > ---
> > drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 5 +----
> > 1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > 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 99b648d4ca76..2547f9596ae6 100644
> > --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> > +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> > @@ -1202,7 +1202,6 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
> > {
> > struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan);
> > int ret;
> > - LIST_HEAD(head);
> >
> > scoped_guard(spinlock_irqsave, &chan->vc.lock) {
> > bool enabled;
> > @@ -1219,7 +1218,7 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
> > if (chan->direction == DMA_MEM_TO_DEV)
> > dw_axi_dma_set_byte_halfword(chan, false);
> >
> > - vchan_get_all_descriptors(&chan->vc, &head);
> > + vchan_terminate_all(&chan->vc);
>
> I have not found this function, Any dependence I missed?
vchan_terminate_all() is added by patch 1/3 of the sun4i DMA series
[0], which v8 lists as a prerequisite.
>
> And keep allocate_queue when terminate,
>
> https://lore.kernel.org/dmaengine/20261104-dma40-fixes-v1-1-48c5180f5210@xxxxxxxxxx/
>
> Look like we new APIs to distingiush terminate_all() and free channel.
>
> when free channel, need clean alloc queue, but termiate_all() should be
> keep alloc queue.
>
> terminate should means terminate all DMA engine own's queue, before
> submit, desc should be own by consumer.
I checked the helper, and it does take desc_allocated along with the
submitted descriptors. That means a client can prepare a descriptor,
terminate earlier work on the same channel, and lose the descriptor
before it has submitted it.
Termination should leave desc_allocated alone. The channel resource
cleanup path still needs to collect that list. This distinction belongs
in the virt-dma helper rather than in the DW AXI caller.
[0] https://lore.kernel.org/r/20261115-submit-sun4i-dma-callback-lifetime-v1-v2-1-fb7d258702f8@xxxxxxxxx/
>
> Frank
>
> >
> > axi_chan_irq_clear(chan, DWAXIDMAC_IRQ_SUSPENDED);
> > chan->desc = NULL;
> > @@ -1234,8 +1233,6 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
> > return ret;
> > }
> >
> > - vchan_dma_desc_free_list(&chan->vc, &head);
> > -
> > dev_vdbg(dmaengine_chan_dev(dchan), "terminated: %s\n", axi_chan_name(chan));
> >
> > return 0;
> >
> > --
> > 2.53.0
> >