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 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup
Date: Fri, 20 Nov 2026 09:24:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-224842@kernel.org> (raw)
In-Reply-To: <20261120-dma3-fixes-v1-3-f29c1f437399@foss.st.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: stm32-dma3: LIFO free order in
stm32_dma3_chan_desc_alloc() wedges pool
--
commit 59d36dd2cf6d4c14f9f6d6159b6dc9354dffd965
Author: Amelie Delaunay <amelie.delaunay@foss.st.com>
dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup
This commit validates that all hardware descriptors in a linked list share
the same 64 KiB address window and frees all allocated descriptors on failure.
> 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--;
> + }
[Severity: Medium]
Does freeing swdesc->lli[] in reverse order restore chan->lli_pool to the
exact same state after a 64KB window mismatch?
dma_pool keeps a LIFO free list (pool->next_block in mm/dmapool.c), where
dma_pool_alloc() pops from the head and dma_pool_free() pushes back onto the
head. When a page in chan->lli_pool runs out and a newly allocated page lands
in a different 64KB address window, freeing from last_alloc_idx down to 0
pushes the descriptors from the old window back onto the head ahead of the new
page in the exact order they were popped. Any subsequent call to
stm32_dma3_chan_desc_alloc() with count > i will pop the same sequence of
descriptors and fail at the same boundary check forever.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-dma3-fixes-v1-0-f29c1f437399@foss.st.com?part=3
next prev parent reply other threads:[~2026-11-20 9:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 9:18 [PATCH 0/4] dmaengine: stm32-dma3: fix IRQ flag race and linked-list handling Amelie Delaunay
2026-11-20 9:18 ` [PATCH 1/4] dmaengine: stm32-dma3: clear flags before signaling transfer completion Amelie Delaunay
2026-11-20 9:18 ` [PATCH 2/4] dmaengine: stm32-dma3: set LL base address when transfer starts Amelie Delaunay
2026-11-20 9:18 ` [PATCH 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup Amelie Delaunay
2026-11-20 9:24 ` sashiko-bot [this message]
2026-11-20 9:18 ` [PATCH 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-224842@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