DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amelie Delaunay" <amelie.delaunay@foss.st.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v2 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup
Date: Mon, 23 Nov 2026 09:25:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-228966@kernel.org> (raw)
In-Reply-To: <20261123-dma3-fixes-v2-3-0a5b013f79d2@foss.st.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: stm32-dma3: LIFO free in
  stm32_dma3_chan_desc_alloc() wedges pool
--

commit b1f0a54731f5c1a2b29b4e522069ca1bedc6096e
Author: Amelie Delaunay <amelie.delaunay@foss.st.com>

dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup

This commit checks that all LLI descriptors in a list share the same 64 KiB
CLBAR address window and frees every allocated descriptor on error.

> diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c
> index a056f73fbe025..7c509a69f5e54 100644
> --- a/drivers/dma/stm32/stm32-dma3.c
> +++ b/drivers/dma/stm32/stm32-dma3.c
> @@ -397,7 +397,8 @@ static void stm32_dma3_chan_dump_hwdesc(struct stm32_dma3_chan *chan,
>  static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_chan *chan, u32 count)
>  {
>  	struct stm32_dma3_swdesc *swdesc;
> -	int i;
> +	int i, last_alloc_idx = -1;
> +	dma_addr_t base_addr = 0;
>  
>  	/*
>  	 * If the memory to be allocated for the number of hwdesc (6 u32 members but 32-bytes
> @@ -419,18 +420,38 @@ static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_ch
>  							&swdesc->lli[i].hwdesc_addr);
>  		if (!swdesc->lli[i].hwdesc)
>  			goto err_pool_free;
> +
> +		last_alloc_idx = i;
> +
> +		if (i == 0) {
> +			base_addr = swdesc->lli[0].hwdesc_addr & CLBAR_LBA;
> +			continue;
> +		}
> +
> +		/*
> +		 * dma_pool boundary=SZ_64K only guarantees that one allocation does not span a 64KB
> +		 * boundary. It does not guarantee that all allocations of a given linked-list land
> +		 * in the same 64KB address window required by CLBAR/CLLR addressing.
> +		 */
> +		if (base_addr != (swdesc->lli[i].hwdesc_addr & CLBAR_LBA)) {
> +			dev_err(vchan_chan_dev(&chan->vchan), "LLI crosses a 64KB window (%pad)\n",
> +				&swdesc->lli[i].hwdesc_addr);
> +			goto err_pool_free;
> +		}
>  	}
> -	swdesc->ccr = 0;
>  
>  	/* Set LL allocated port */
> -	swdesc->ccr &= ~CCR_LAP;
> +	swdesc->ccr = FIELD_PREP(CCR_LAP, 0);
>  
>  	return swdesc;
>  
>  err_pool_free:
>  	dev_err(vchan_chan_dev(&chan->vchan), "Failed to alloc descriptors\n");
> -	while (--i >= 0)
> -		dma_pool_free(chan->lli_pool, swdesc->lli[i].hwdesc, swdesc->lli[i].hwdesc_addr);
> +	while (last_alloc_idx >= 0) {
> +		dma_pool_free(chan->lli_pool, swdesc->lli[last_alloc_idx].hwdesc,
> +			      swdesc->lli[last_alloc_idx].hwdesc_addr);
> +		last_alloc_idx--;
> +	}
>  	kfree(swdesc);
>  
>  	return NULL;

[Severity: Medium]
Can freeing descriptors in reverse order wedge chan->lli_pool after a 64 KiB
window mismatch?

dma_pool keeps free blocks on a LIFO stack (pool->next_block in
mm/dmapool.c), and each backing pool page holds 4 KiB (128 descriptors)
unless a larger pool page is allocated.  When descriptors 0..k-1 come from
one 64 KiB window and descriptor k comes from a newly allocated pool page in
another window, freeing from last_alloc_idx (k) down to 0 pushes descriptor
k and then descriptors k-1..0 back onto the head of pool->next_block in the
exact order they were popped.  Every subsequent call to
stm32_dma3_chan_desc_alloc() with count > k will pop the same k + 1
descriptors and fail at the window check until smaller allocations drain the
k blocks at the head.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dma3-fixes-v2-0-0a5b013f79d2@foss.st.com?part=3

  reply	other threads:[~2026-11-23  9:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  9:17 [PATCH v2 0/4] dmaengine: stm32-dma3: fix IRQ flag race and linked-list handling Amelie Delaunay
2026-11-23  9:17 ` [PATCH v2 1/4] dmaengine: stm32-dma3: clear flags before signaling transfer completion Amelie Delaunay
2026-11-23  9:17 ` [PATCH v2 2/4] dmaengine: stm32-dma3: set LL base address when transfer starts Amelie Delaunay
2026-11-23  9:17 ` [PATCH v2 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup Amelie Delaunay
2026-11-23  9:25   ` sashiko-bot [this message]
2026-11-23  9:17 ` [PATCH v2 4/4] dmaengine: stm32-dma3: replace hardcoded LLI size with aligned descriptor size Amelie Delaunay

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=sashiko-outbox-228966@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=amelie.delaunay@foss.st.com \
    --cc=dmaengine@vger.kernel.org \
    --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