Re: [PATCH v9 3/6] dmaengine: dw: use virt-dma for descriptor and callback ownership

From: Frank Li

Date: Wed Nov 18 2026 - 13:05:21 EST


On Tue, Nov 17, 2026 at 03:48:38PM -0700, James Hilliard wrote:
> The status getter can invoke a client's completion callback while polling
> the hardware. An 8250 RX timeout calls it with the port lock held, and the
> callback takes that same lock. Termination also lacks a synchronization
> hook to wait for callbacks already detached from the channel's queues.
>
> Use virt-dma for transaction queues, cookie completion and callback
> delivery. Keep the active transaction and hardware state under vc.lock.
> Polling still processes RAW.XFER and advances software-LLP blocks, so
> clients such as catpt can complete transfers with the controller interrupt
> masked. Client callbacks run only from the per-channel virt-dma tasklet.
>
> Submit only the first block of each transaction to virt-dma. Its child
> LLIs remain on the driver's hardware-chain list and are freed together
> after the callback returns. Keep the controller tasklet for hardware
> event processing and error recovery.
>
> Complete cookies under vc.lock before handing descriptors to the callback
> tasklet. Complete terminated cookies in submission order without invoking
> their callbacks, so a concurrent termination cannot advance the completed
> cookie past an older completion that later moves it backwards. Newly
> submitted transactions become eligible to start when issue_pending()
> moves them to the issued queue.
>
> Implement device_synchronize with vchan_synchronize(), which drains only
> the selected channel's callbacks. Drain them before releasing channel
> resources as well. Exclude the controller tasklet while clearing channel
> configuration and powering down, and let a pending run return without
> register access after the last channel has been released.
>
> This implements the callback deferral proposed by Serge Semin using the
> shared infrastructure suggested by Andy Shevchenko.
>
> Fixes: 3bfb1d20b547 ("dmaengine: Driver for the Synopsys DesignWare DMA controller")
> Fixes: 69cea5a00d31 ("dmaengine/dw_dmac: Replace spin_lock* with irqsave variants and enable submission from callback")
> Fixes: b36f09c3c441 ("dmaengine: Add transfer termination synchronization support")
> Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Link: https://lore.kernel.org/r/20240911184710.4207-3-fancer.lancer@xxxxxxxxx
> Link: https://lore.kernel.org/r/avrHOJ-fVZOO32bI@ashevche-desk.local
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> ---
...
>
> struct dw_dma_chan {
> - struct dma_chan chan;
> + struct virt_dma_chan vc;

This patch is too big to review.

Suggest create prepare patch change dma_chan to virt_dma_chan and remove
spinlock_t lock by using vc.lock.

So functional it is same.

Than base on prepare patch to switch to use vc's queue.

Frank

> void __iomem *ch_regs;
> u8 mask;
> u8 priority;
> @@ -273,14 +274,9 @@ struct dw_dma_chan {
> /* software emulation of the LLP transfers */
> struct list_head *tx_node_active;
>
> - spinlock_t lock;
> -
> - /* these other elements are all protected by lock */
> + /* these other elements are all protected by vc.lock */
> unsigned long flags;
> - struct list_head active_list;
> - struct list_head queue;
> -
> - unsigned int descs_allocated;
> + struct dw_desc *desc;
>
> /* hardware configuration */
> unsigned int block_size;
> @@ -307,7 +303,7 @@ __dwc_regs(struct dw_dma_chan *dwc)
>
> static inline struct dw_dma_chan *to_dw_dma_chan(struct dma_chan *chan)
> {
> - return container_of(chan, struct dw_dma_chan, chan);
> + return container_of(chan, struct dw_dma_chan, vc.chan);
> }
>
> struct dw_dma {
> @@ -391,18 +387,18 @@ struct dw_desc {
> #define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_le32(v))
>
> /* THEN values for driver housekeeping */
> - struct list_head desc_node;
> + /* Only the first block is submitted to virt-dma. */
> struct list_head tx_list;
> - struct dma_async_tx_descriptor txd;
> + struct virt_dma_desc vd;
> size_t len;
> size_t total_len;
> u32 residue;
> };
>
> -#define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node)
> +#define to_dw_desc(h) list_entry(h, struct dw_desc, vd.node)
>
> static inline struct dw_desc *
> -txd_to_dw_desc(struct dma_async_tx_descriptor *txd)
> +vd_to_dw_desc(struct virt_dma_desc *vd)
> {
> - return container_of(txd, struct dw_desc, txd);
> + return container_of(vd, struct dw_desc, vd);
> }
>
> --
> 2.53.0
>