lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D8Q58KMGV4R4.ELW8TLEK5W5V@bootlin.com>
Date: Wed, 26 Mar 2025 11:59:13 +0100
From: Théo Lebrun <theo.lebrun@...tlin.com>
To: "Maxime Chevallier" <maxime.chevallier@...tlin.com>
Cc: "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>, <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 08/13] net: macb: introduce DMA descriptor
 helpers (is 64bit? is PTP?)

Hello Maxime,

On Mon Mar 24, 2025 at 9:55 AM CET, Maxime Chevallier wrote:
> On Fri, 21 Mar 2025 20:09:39 +0100
> Théo Lebrun <theo.lebrun@...tlin.com> wrote:
>
>> Introduce macb_dma_is_64b() and macb_dma_is_ptp() helper functions.
>> Many codepaths are made simpler by dropping conditional compilation.
>> 
>> This implies three changes:
>>  - Always compile related structure definitions inside <macb.h>.
>>  - Make the field hw_dma_cap in struct macb always present.
>>  - MACB_EXT_DESC can be dropped as it is useless now.
>> 
>> The common case is:
>> 
>> 	#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
>> 		struct macb_dma_desc_64 *desc_64;
>> 		if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
>> 			desc_64 = macb_64b_desc(bp, desc);
>> 			// ...
>> 		}
>> 	#endif
>> 
>> And replaced by:
>> 
>> 	struct macb_dma_desc_64 *desc_64;
>> 	if (macb_dma_is_64b(bp)) {
>> 		desc_64 = macb_64b_desc(bp, desc);
>> 		// ...
>> 	}
>
> Just a thought, but this is adding some more branches in the hotpath on
> 32 bits DMA setups. Did you measure any performance changes on
> these platforms (if you have access to one :) )
>
> As the caps can't be changed dynamically, maybe these helpers could be
> replaced more efficiently with some static_key ? This would benefit
> both 32 and 64 bits systems as the following would be more efficient
>
> 	if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
> 		//  ...
> 	}
>
> Just a thought of course, maybe this patch doesn't really hurt perfs :)

Good question! I asked myself the same thing before posting.

We go from:

	void bar(struct macb *bp) {
	#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
		if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
			foo();
		}
	#endif
	}

To:

	static bool macb_dma_is_64b(struct macb *bp)
	{
		return IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
		       bp->hw_dma_cap & HW_DMA_CAP_64B;
	}

	void bar(struct macb *bp) {
		if (macb_dma_is_64b(bp)) {
			foo();
		}
	}

In the first case, we use explicit preprocessor directives to remove
code if CONFIG_ARCH_DMA_ADDR_T_64BIT isn't defined.

In the second case, our compiler optimises away the IS_ENABLED() call.
 - If false, then the branch doesn't appear.
 - If true, then only the capability check is inlined in bar().
I checked the assembly on arm/arm64/MIPS.

Conclusion: the hotpath doesn't change.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ