Re: [PATCH v6 10/10] dmaengine: dw: Prevent tx-status calling DMA-desc callback
From: Frank Li
Date: Fri Nov 13 2026 - 14:58:50 EST
On Tue, Nov 03, 2026 at 03:26:12PM -0700, James Hilliard wrote:
> From: Serge Semin <fancer.lancer@xxxxxxxxx>
>
> The DMA transfer status getter can invoke a completion callback from
> dwc_scan_descriptors(). An 8250 RX timeout queries that status while
> holding the UART port lock, and its DMA callback takes the same lock:
>
> serial8250_handle_irq()
> uart_port_lock_irqsave(port)
> serial8250_rx_dma_flush()
> dmaengine_tx_status()
> dwc_scan_descriptors()
> dwc_descriptor_free()
> dma_rx_complete()
> uart_port_lock_irqsave(port)
>
> Queue completed descriptors on a channel completion list under the channel
> lock. Let the controller tasklet detach that list and invoke callbacks
> outside the lock. Termination discards notifications still on the shared
> list; the tasklet owns descriptors it has already detached, and the
> synchronization hook waits for that run.
>
> Keep handling raw completion events from tx_status(). Clients such as
> catpt poll transfers without DMA_PREP_INTERRUPT and can mask the controller
> interrupt externally. Polling must still advance software-emulated LLP
> blocks and complete cookies without waiting for tasklet execution. Hold
> the channel lock across event handling and status calculation, then
> schedule the tasklet for deferred notifications.
>
> On channel release, discard queued notifications after draining the
> tasklet, before clearing the controller's in-use state.
>
> Fixes: 3bfb1d20b547 ("dmaengine: Driver for the Synopsys DesignWare DMA controller")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Serge Semin <fancer.lancer@xxxxxxxxx>
> [james: defer notifications while preserving polled completion and cleanup]
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> ---
...
> @@ -988,19 +994,26 @@ dwc_tx_status(struct dma_chan *chan,
> struct dma_tx_state *txstate)
> {
> struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
> + struct dw_dma *dw = to_dw_dma(chan->device);
> enum dma_status ret;
> + unsigned long flags;
>
> + spin_lock_irqsave(&dwc->lock, flags);
use clean up guard to avoid below goto
Frank
> ret = dma_cookie_status(chan, cookie, txstate);
> if (ret == DMA_COMPLETE)
> - return ret;
> + goto unlock;
>
> - dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
> + /* Poll completion even when the client has masked the controller IRQ. */
> + dwc_handle_channel(dw, dwc);
> + if (!list_empty(&dwc->completed))
> + tasklet_schedule(&dw->tasklet);
>
> ret = dma_cookie_status(chan, cookie, txstate);
> - if (ret == DMA_COMPLETE)
> - return ret;
> + if (ret != DMA_COMPLETE)
> + dma_set_residue(txstate, dwc_get_residue_and_status(dwc, cookie, &ret));
>
> - dma_set_residue(txstate, dwc_get_residue_and_status(dwc, cookie, &ret));
> +unlock:
> + spin_unlock_irqrestore(&dwc->lock, flags);
> return ret;
> }
>
> @@ -1079,6 +1092,7 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
> struct dw_dma *dw = to_dw_dma(chan->device);
> unsigned long flags;
>
> + /* Polled completion can leave descriptors waiting for the tasklet. */
> tasklet_disable(&dw->tasklet);
>
> dev_dbg(dmaengine_chan_dev(chan), "%s: descs allocated=%u\n", __func__,
> @@ -1089,6 +1103,8 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
> BUG_ON(!list_empty(&dwc->queue));
> BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask);
>
> + dwc_free_completed(dwc, false);
> +
> spin_lock_irqsave(&dwc->lock, flags);
>
> /* Clear custom channel configuration */
> @@ -1238,6 +1254,7 @@ int do_dma_probe(struct dw_dma_chip *chip)
>
> INIT_LIST_HEAD(&dwc->active_list);
> INIT_LIST_HEAD(&dwc->queue);
> + INIT_LIST_HEAD(&dwc->completed);
>
> channel_clear_bit(dw, CH_EN, dwc->mask);
>
> diff --git a/drivers/dma/dw/regs.h b/drivers/dma/dw/regs.h
> index 5969d9cc8d7a..c41f18281efe 100644
> --- a/drivers/dma/dw/regs.h
> +++ b/drivers/dma/dw/regs.h
> @@ -279,6 +279,7 @@ struct dw_dma_chan {
> unsigned long flags;
> struct list_head active_list;
> struct list_head queue;
> + struct list_head completed;
>
> unsigned int descs_allocated;
>
>
> --
> 2.53.0
>