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: <b239b40b-0abe-43a5-af41-346283a634f6@gmail.com>
Date: Mon, 28 Jul 2025 19:46:52 +0100
From: Pavel Begunkov <asml.silence@...il.com>
To: Mina Almasry <almasrymina@...gle.com>, Byungchul Park <byungchul@...com>
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
 davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
 pabeni@...hat.com, horms@...nel.org, hawk@...nel.org, toke@...hat.com
Subject: Re: [RFC net-next] netmem: replace __netmem_clear_lsb() with
 netmem_to_nmdesc()

On 7/28/25 18:44, Mina Almasry wrote:
> On Sun, Jul 27, 2025 at 9:21 PM Byungchul Park <byungchul@...com> wrote:
>>

...>> - * Return: the netmem_ref cast to net_iov* regardless of its underlying type.
>> + * Return: the pointer to struct netmem_desc * regardless of its
>> + * underlying type.
>>    */
>> -static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem)
>> +static inline struct netmem_desc *netmem_to_nmdesc(netmem_ref netmem)
>>   {
>> -       return (struct net_iov *)((__force unsigned long)netmem & ~NET_IOV);
>> +       if (netmem_is_net_iov(netmem))
>> +               return &((struct net_iov *)((__force unsigned long)netmem &
>> +                                           ~NET_IOV))->desc;
>> +
>> +       return __netmem_to_nmdesc(netmem);
> 
> The if statement generates overhead. I'd rather avoid it. We can
> implement netmem_to_nmdesc like this, no?
> 
> netmem_to_nmdesc(netmem_ref netmem)
> {
>    return (struct netmem_desc)((__force unsigned long)netmem & ~NET_IOV);
> }
> 
> Because netmem_desc is the first element in both net_iov and page for
> the moment. (yes I know that will change eventually, but we don't have
> to incur overhead of an extra if statement until netmem_desc is
> removed from page, right?)

Same concern, but I think the goal here should be to make enough
info to the compiler to optimise it out without assumptions on
the layouts nor NET_IOV_ASSERT_OFFSET. Currently it's not so bad,
but we should be able to remove this test+cmove.

	movq	%rdi, %rax	# netmem, tmp105
	andq	$-2, %rax	#, tmp105
	testb	$1, %dil	#, netmem
	cmove	%rdi, %rax	# tmp105,, netmem, <retval>
	jmp	__x86_return_thunk


-- 
Pavel Begunkov


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ