Re: [PATCH v2] dmaengine: mediatek: mtk-cqdma: fix list entry type, channel check, and locking in tx_status
From: Ziheng Wei
Date: Wed Dec 02 2026 - 01:45:59 EST
Hi Frank,
On Tue, Dec 01, 2026 at 02:17:44PM -0600, Frank Li wrote:
> On Mon, Nov 30, 2026 at 09:42:45PM +0800, Ziheng Wei wrote:
> > mtk_cqdma_issue_vchan_pending() links active descriptors onto pc->queue
> > via struct mtk_cqdma_vdesc::node, whereas mtk_cqdma_find_active_desc()
> > walks pc->queue using struct virt_dma_desc::node.
>
> how it work previously?
It was silently masked in normal use:
1) mtk_cqdma_tx_status() returns early when ret == DMA_COMPLETE or
txstate == NULL, which covers most DMA_MEMCPY callers.
2) Even when it does walk pc->queue, the shifted vd pointer makes
vd->tx.cookie read an unrelated field inside struct mtk_cqdma_vdesc,
so the cookie check almost always fails. mtk_cqdma_find_active_desc()
then returns NULL and mtk_cqdma_tx_status() silently reports residue
as 0 without crashing. The slab-out-of-bounds read on cvd->residue
only triggers if that misread field happens to equal cookie.
> > + if (vd) {
> > + cvd = to_cqdma_vdesc(vd);
> > + bytes = cvd->residue;
> > + }
> > + spin_unlock(&cvc->vc.lock);
> > + spin_unlock_irqrestore(&cvc->pc->lock, flags);
>
> Use two patches to fix it. one patch only fix one problem.
Makes sense. I will split the pc->queue lookup fix and the locking fix
into two separate patches and send v3 shortly.
Thanks,
Ziheng