DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Benoît Monin" <benoit.monin@bootlin.com>
Cc: imx@lists.linux.dev, vkoul@kernel.org, Frank.Li@kernel.org,
	dmaengine@vger.kernel.org
Subject: Re: [PATCH v7 2/2] dmaengine: fsl-edma: Support dynamic scatter/gather chaining
Date: Tue, 28 Jul 2026 14:21:10 +0000	[thread overview]
Message-ID: <20260728142110.A103D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728-fsl-edma-dyn-sg-v7-2-10dffb4167c2@bootlin.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A completed dynamically linked scatter/gather descriptor will be erroneously re-issued for execution if its interrupt is delayed, leading to double-execution and memory corruption.
- [High] Descriptors can be erroneously marked as completed without execution if channel linking (E_LINK) is configured.
--

--- Patch [2]: [PATCH v7 2/2] dmaengine: fsl-edma: Support dynamic scatter/gather chaining ---
commit b8502bf27e9fa2ac70190840a26c1603f5640651
Author: Benoît Monin <benoit.monin@bootlin.com>

dmaengine: fsl-edma: Support dynamic scatter/gather chaining

Implement dynamic linking of scatter/gather transfers to enable
chaining multiple DMA descriptors without stopping the channel.

> diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
> --- a/drivers/dma/fsl-edma-common.c
> +++ b/drivers/dma/fsl-edma-common.c
[ ... ]
> @@ -55,10 +55,29 @@ void fsl_edma_tx_chan_handler(struct fsl_edma_chan *fsl_chan)
>  	}
>  
>  	if (!fsl_chan->edesc->iscyclic) {
> -		list_del(&fsl_chan->edesc->vdesc.node);
> -		vchan_cookie_complete(&fsl_chan->edesc->vdesc);
> +		u8 link_sg_id = FIELD_GET(EDMA_TCD_CSR_LINKCH, edma_read_tcdreg(fsl_chan, csr));

[Severity: High]
Will this misinterpret a hardware channel link ID as a software SG ID if
channel linking (EDMA_TCD_CSR_E_LINK) is configured?

If a transfer uses EDMA_TCD_CSR_E_LINK to link to a non-zero channel, the
handler appears to unconditionally extract link_sg_id from the CSR. This
channel number would be read as the link_sg_id, causing id_match to be false
for all pending descriptors (which have link_sg_id == 0).

Does this cause the handler to iterate through the entire desc_issued list,
prematurely deleting and completing every queued descriptor without them ever
executing?

> +		struct virt_dma_desc *vdesc, *tmp;
> +
> +		list_for_each_entry_safe(vdesc, tmp, &fsl_chan->vchan.desc_issued, node) {
> +			struct fsl_edma_desc *fsl_desc = to_fsl_edma_desc(vdesc);
> +			bool id_match = (link_sg_id == fsl_desc->link_sg_id);
> +
> +			if (id_match && fsl_desc != fsl_chan->edesc)
> +				break;

[Severity: High]
If multiple dynamically linked descriptors finish before the interrupt handler
processes them (e.g., due to system load or interrupt latency), could a
completed descriptor be stranded in the queue?

When the hardware stops on a later descriptor and sets the DONE flag, this
loop will break early when it matches the link_sg_id of the finished
descriptor, assuming it is still running because fsl_desc != fsl_chan->edesc.

> +
> +			list_del(&vdesc->node);
> +			vchan_cookie_complete(vdesc);
> +
> +			if (id_match)
> +				break;
> +		}
> +
>  		fsl_chan->edesc = NULL;
> -		fsl_chan->status = DMA_COMPLETE;
> +
> +		if (!(fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_SPLIT_REG) ||
> +		    (edma_readl_chreg(fsl_chan, ch_csr) & EDMA_V3_CH_CSR_DONE)) {
> +			fsl_chan->status = DMA_COMPLETE;
> +		}
>  	} else {
>  		vchan_cyclic_callback(&fsl_chan->edesc->vdesc);
>  	}
[ ... ]
> @@ -931,14 +950,87 @@ void fsl_edma_xfer_desc(struct fsl_edma_chan *fsl_chan)
>  	if (!vdesc)
>  		return;
>  	fsl_chan->edesc = to_fsl_edma_desc(vdesc);
> -	fsl_edma_set_tcd_regs(fsl_chan, fsl_chan->edesc->tcd[0].vtcd);
> -	fsl_edma_enable_request(fsl_chan);
> -	fsl_chan->status = DMA_IN_PROGRESS;
> +
> +	if (fsl_chan->status != DMA_IN_PROGRESS) {
> +		fsl_edma_set_tcd_regs(fsl_chan, fsl_chan->edesc->tcd[0].vtcd);
> +		fsl_edma_enable_request(fsl_chan);
> +		fsl_chan->status = DMA_IN_PROGRESS;
> +	}
> +}

[Severity: High]
Because the channel status was updated to DMA_COMPLETE in
fsl_edma_tx_chan_handler() above, will fsl_edma_xfer_desc() then fetch the
stranded descriptor from the queue and erroneously reprogram it to the
hardware?

This seems like it would cause the hardware to re-execute a DMA transfer that
has already finished, potentially leading to data corruption for I/O devices
(such as duplicated writes or dropped reads).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-fsl-edma-dyn-sg-v7-0-10dffb4167c2@bootlin.com?part=2

  reply	other threads:[~2026-07-28 14:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 14:08 [PATCH v7 0/2] dmaengine: fsl-edma: Scatter/gather improvements Benoît Monin
2026-07-28 14:08 ` [PATCH v7 1/2] dmaengine: fsl-edma: Implement device_prep_peripheral_dma_vec Benoît Monin
2026-07-28 14:20   ` sashiko-bot
2026-07-28 14:08 ` [PATCH v7 2/2] dmaengine: fsl-edma: Support dynamic scatter/gather chaining Benoît Monin
2026-07-28 14:21   ` sashiko-bot [this message]
2026-07-28 15:12     ` Frank Li

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=20260728142110.A103D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=benoit.monin@bootlin.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox