[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DBWA12ZND9TY.2SA3R9T5UJTZR@bootlin.com>
Date: Thu, 07 Aug 2025 16:48:27 +0200
From: Théo Lebrun <theo.lebrun@...tlin.com>
To: "Sean Anderson" <sean.anderson@...ux.dev>, "Andrew Lunn"
<andrew+netdev@...n.ch>, "David S. Miller" <davem@...emloft.net>, "Eric
Dumazet" <edumazet@...gle.com>, "Jakub Kicinski" <kuba@...nel.org>, "Paolo
Abeni" <pabeni@...hat.com>, "Rob Herring" <robh@...nel.org>, "Krzysztof
Kozlowski" <krzk+dt@...nel.org>, "Conor Dooley" <conor+dt@...nel.org>,
"Nicolas Ferre" <nicolas.ferre@...rochip.com>, "Claudiu Beznea"
<claudiu.beznea@...on.dev>, "Paul Walmsley" <paul.walmsley@...ive.com>,
"Palmer Dabbelt" <palmer@...belt.com>, "Albert Ou" <aou@...s.berkeley.edu>,
"Alexandre Ghiti" <alex@...ti.fr>, "Samuel Holland"
<samuel.holland@...ive.com>, "Richard Cochran" <richardcochran@...il.com>,
"Russell King" <linux@...linux.org.uk>, "Thomas Bogendoerfer"
<tsbogend@...ha.franken.de>, "Vladimir Kondratiev"
<vladimir.kondratiev@...ileye.com>, "Gregory CLEMENT"
<gregory.clement@...tlin.com>, "Cyrille Pitchen"
<cyrille.pitchen@...el.com>, "Harini Katakam" <harini.katakam@...inx.com>,
"Rafal Ozieblo" <rafalo@...ence.com>, "Haavard Skinnemoen"
<hskinnemoen@...el.com>
Cc: <netdev@...r.kernel.org>, <devicetree@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-riscv@...ts.infradead.org>,
<linux-mips@...r.kernel.org>, "Thomas Petazzoni"
<thomas.petazzoni@...tlin.com>, "Tawfik Bayouk"
<tawfik.bayouk@...ileye.com>
Subject: Re: [PATCH net-next v2 11/18] net: macb: single
dma_alloc_coherent() for DMA descriptors
Hello Sean,
Thanks for the review! I'll reply only to questions (or comments about
which I have questions).
On Tue Jul 1, 2025 at 6:32 PM CEST, Sean Anderson wrote:
> On 6/27/25 05:08, Théo Lebrun wrote:
>> Move from two (Tx/Rx) dma_alloc_coherent() for DMA descriptor rings *per
>> queue* to two dma_alloc_coherent() overall.
>>
>> Issue is with how all queues share the same register for configuring the
>> upper 32-bits of Tx/Rx descriptor rings. For example, with Tx, notice
>> how TBQPH does *not* depend on the queue index:
>>
>> #define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2))
>> #define GEM_TBQPH(hw_q) (0x04C8)
>>
>> queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma));
>> #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
>> if (bp->hw_dma_cap & HW_DMA_CAP_64B)
>> queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma));
>> #endif
>>
>> To maxime our chances of getting valid DMA addresses, we do a single
>
> maximize
>
>> dma_alloc_coherent() across queues.
>
> Is there really any chance involved (other than avoiding ENOMEM)?
If we land in the the page allocator codepath of dma_alloc_coherent(),
then we get natural alignment guarantees, see alloc_pages() comment [0].
[0]: https://elixir.bootlin.com/linux/v6.16/source/mm/mempolicy.c#L2499-L2502
However, we cannot be certain we land in that path. If we have an
IOMMU, then I don't think the API provides strong enough guarantees.
Same for custom `struct dma_map_ops`, be it per-device or arch-specific.
I am not aware (is anything documented on that?) of any alignment
guarantees.
Even if those give us page-aligned allocations, that isn't enough. For
example let's say we want 256KiB. We get 0xFFFF0000 from an allocator.
That is page aligned, but:
upper_32_bits(START) != upper_32_bits(START + SIZE - 1)
upper_32_bits(0xFFFF0000) != upper_32_bits(0xFFFF0000 + 0x40000 - 1)
0x0 != 0x1
Thanks!
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Powered by blists - more mailing lists