From: Amelie Delaunay <amelie.delaunay@foss.st.com>
To: Frank Li <Frank.li@oss.nxp.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
<dmaengine@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup
Date: Mon, 23 Nov 2026 09:58:14 +0100 [thread overview]
Message-ID: <ae764ee9-cef8-415d-ad3f-64572ed5f4f0@foss.st.com> (raw)
In-Reply-To: <awCLUSCKqsBDF5g3@SMW015318>
On 11/20/26 19:02, Frank Li wrote:
> On Fri, Nov 20, 2026 at 10:18:03AM +0100, Amelie Delaunay wrote:
>> All descriptors in a linked list must share the same 64 KiB address
>> window because CLBAR provides the common upper address bits. The DMA pool
>> boundary only constrains individual allocations, not the whole list, so
>> descriptors in a single list may be allocated from different pool pages in
>> different windows.
>
> /**
> * dmam_pool_create - Managed dma_pool_create()
> * @name: name of pool, for diagnostics
> * @dev: device that will be doing the DMA
> * @size: size of the blocks in this pool.
> * @align: alignment requirement for blocks; must be a power of two
> * @allocation: returned blocks won't cross this boundary (or zero)
>
> suppose you can set allocation to 64K to avoid cross 64K boundary.
>
> *
> * Managed dma_pool_create(). DMA pool created with this function is
> * automatically destroyed on driver detach.
> *
> * Return: a managed dma allocation pool with the requested
> * characteristics, or %NULL if one can't be created.
> */
> struct dma_pool *dmam_pool_create(const char *name, struct device *dev,
> size_t size, size_t align, size_t allocation)
>
>
> Frank
>
The driver already passes SZ_64K as the last argument to
dmam_pool_create(). That argument constrains *individual* pool blocks,
not the linked list *as a whole*.
Each allocation here is one descriptor. When the pool grows, descriptors
from different backing allocations can end up in different 64 KiB
windows, even though every descriptor individually satisfies the
boundary constraint.
DMA3 requires all descriptors in a list to share the same window because
CLBAR provides the common upper address bits.
This check therefore prevents an invalid list from reaching the
hardware. Guaranteeing that such lists can always be allocated would
require a window-aware allocation strategy.
Amelie
>>
>> Check each descriptor's base address and reject lists that span multiple
>> windows, instead of letting the hardware fetch descriptors from wrong
>> addresses. Track the last allocated entry so that the error path frees
>> exactly the descriptors that were allocated, including the one that
>> failed the window check.
>>
>> While at it, simplify the ccr initialisation, which is functionnaly
>> equivalent to the previous code.
>>
>> Fixes: f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
>> ---
>> drivers/dma/stm32/stm32-dma3.c | 31 ++++++++++++++++++++++++++-----
>> 1 file changed, 26 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c
>> index a056f73fbe02..7c509a69f5e5 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;
>>
>> --
>> 2.43.0
>>
next prev parent reply other threads:[~2026-11-23 8:58 UTC|newest]
Thread overview: 11+ 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 17:48 ` Frank Li
2026-11-23 8:40 ` 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 17:51 ` Frank Li
2026-11-20 9:18 ` [PATCH 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup Amelie Delaunay
2026-11-20 18:02 ` Frank Li
2026-11-23 8:58 ` Amelie Delaunay [this message]
2026-11-20 9:18 ` [PATCH 4/4] dmaengine: stm32-dma3: replace hardcoded LLI size with aligned descriptor size Amelie Delaunay
2026-11-20 18:05 ` 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=ae764ee9-cef8-415d-ad3f-64572ed5f4f0@foss.st.com \
--to=amelie.delaunay@foss.st.com \
--cc=Frank.Li@kernel.org \
--cc=Frank.li@oss.nxp.com \
--cc=alexandre.torgue@foss.st.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=stable@vger.kernel.org \
--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
all inboxes | Powered by JetHome®