🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
6 messages
6 total messages Started by Sasha Levin Tue, 03 Nov 2026 16:39
[PATCH] selftests: net: tcp_ao: don't shift a size_t by 32
#10536
Author: Sasha Levin
Date: Tue, 03 Nov 2026 16:39
36 lines
8796 bytes
gen_tcp_addr() shifts the size_t n right by 32 and masks it with BIT(32)
- 1. On 32-bit architectures both shifts are as wide as the type, which
is undefined:

  aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]

Convert n to uint64_t first and mask with 0xffffffff.

Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
-m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
KernelCI's 32-bit arm builds show the same warnings. The changed files
build without them now, and the x86_64 builds don't change.

 tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/tcp_ao/lib/aolib.h b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
index 53be1744237ee..71ff975533089 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/aolib.h
+++ b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
@@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)
 	union tcp_addr ret = net;
 
 #ifdef IPV6_TEST
-	ret.a6.s6_addr32[3] = htonl(n & (BIT(32) - 1));
-	ret.a6.s6_addr32[2] = htonl((n >> 32) & (BIT(32) - 1));
+	ret.a6.s6_addr32[3] = htonl((uint64_t)n & 0xffffffff);
+	ret.a6.s6_addr32[2] = htonl((uint64_t)n >> 32);
 #else
 	ret.a4.s_addr = htonl(ntohl(net.a4.s_addr) + n);
 #endif
-- 
2.53.0
Re: [PATCH] selftests: net: tcp_ao: don't shift a size_t by 32
#10735
Author: Hangbin Liu
Date: Wed, 04 Nov 2026 01:42
40 lines
9886 bytes
On Tue, Nov 03, 2026 at 11:39:21AM -0500, Sasha Levin wrote:
> gen_tcp_addr() shifts the size_t n right by 32 and masks it with BIT(32)
> - 1. On 32-bit architectures both shifts are as wide as the type, which
> is undefined:
> 
>   aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
> 
> Convert n to uint64_t first and mask with 0xffffffff.
> 
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
> -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
> KernelCI's 32-bit arm builds show the same warnings. The changed files
> build without them now, and the x86_64 builds don't change.
> 
>  tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/tcp_ao/lib/aolib.h b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> index 53be1744237ee..71ff975533089 100644
> --- a/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> +++ b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> @@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)
>  	union tcp_addr ret = net;
>  
>  #ifdef IPV6_TEST
> -	ret.a6.s6_addr32[3] = htonl(n & (BIT(32) - 1));
> -	ret.a6.s6_addr32[2] = htonl((n >> 32) & (BIT(32) - 1));
> +	ret.a6.s6_addr32[3] = htonl((uint64_t)n & 0xffffffff);
> +	ret.a6.s6_addr32[2] = htonl((uint64_t)n >> 32);
>  #else
>  	ret.a4.s_addr = htonl(ntohl(net.a4.s_addr) + n);
>  #endif
> -- 
> 2.53.0
> 

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Re: [PATCH] selftests: net: tcp_ao: don't shift a size_t by 32
#10976
Author: Dmitry Safonov
Date: Wed, 04 Nov 2026 13:45
44 lines
13633 bytes
On Tue, 3 Nov 2026 at 16:39, Sasha Levin <sashal@kernel.org> wrote:
>
> gen_tcp_addr() shifts the size_t n right by 32 and masks it with BIT(32)
> - 1. On 32-bit architectures both shifts are as wide as the type, which
> is undefined:
>
>   aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
>
> Convert n to uint64_t first and mask with 0xffffffff.
>
> Signed-off-by: Sasha Levin <sashal@kernel.org>

Acked-by: Dmitry Safonov <0x7f454c46@gmail.com>

Thanks!

> ---
> Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
> -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
> KernelCI's 32-bit arm builds show the same warnings. The changed files
> build without them now, and the x86_64 builds don't change.
>
>  tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/net/tcp_ao/lib/aolib.h b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> index 53be1744237ee..71ff975533089 100644
> --- a/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> +++ b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> @@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)
>         union tcp_addr ret = net;
>
>  #ifdef IPV6_TEST
> -       ret.a6.s6_addr32[3] = htonl(n & (BIT(32) - 1));
> -       ret.a6.s6_addr32[2] = htonl((n >> 32) & (BIT(32) - 1));
> +       ret.a6.s6_addr32[3] = htonl((uint64_t)n & 0xffffffff);
> +       ret.a6.s6_addr32[2] = htonl((uint64_t)n >> 32);
>  #else
>         ret.a4.s_addr = htonl(ntohl(net.a4.s_addr) + n);
>  #endif
> --
> 2.53.0
>
Re: [PATCH] selftests: net: tcp_ao: don't shift a size_t by 32
#11610
Author: David Laight
Date: Thu, 05 Nov 2026 11:08
49 lines
12872 bytes
On Tue,  3 Nov 2026 11:39:21 -0500
Sasha Levin <sashal@kernel.org> wrote:

> gen_tcp_addr() shifts the size_t n right by 32 and masks it with BIT(32)
> - 1. On 32-bit architectures both shifts are as wide as the type, which
> is undefined:
> 
>   aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
> 
> Convert n to uint64_t first and mask with 0xffffffff.
> 
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
> -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
> KernelCI's 32-bit arm builds show the same warnings. The changed files
> build without them now, and the x86_64 builds don't change.
> 
>  tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/tcp_ao/lib/aolib.h b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> index 53be1744237ee..71ff975533089 100644
> --- a/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> +++ b/tools/testing/selftests/net/tcp_ao/lib/aolib.h
> @@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)
>  	union tcp_addr ret = net;
>  
>  #ifdef IPV6_TEST
> -	ret.a6.s6_addr32[3] = htonl(n & (BIT(32) - 1));
> -	ret.a6.s6_addr32[2] = htonl((n >> 32) & (BIT(32) - 1));
> +	ret.a6.s6_addr32[3] = htonl((uint64_t)n & 0xffffffff);

You don't need a cast or mask there.

> +	ret.a6.s6_addr32[2] = htonl((uint64_t)n >> 32);

That can also be n >> 16 >> 16

Also see upper_32_bits() and lower_32_bits() in wordpart.h
which might not be available for selftests?

David


>  #else
>  	ret.a4.s_addr = htonl(ntohl(net.a4.s_addr) + n);
>  #endif
Re: [PATCH] selftests: net: tcp_ao: don't shift a size_t by 32
#11686
Author: Sasha Levin
Date: Thu, 05 Nov 2026 12:48
27 lines
8656 bytes
On Thu, Nov 05, 2026 at 11:08:56AM +0000, David Laight wrote:
>On Tue,  3 Nov 2026 11:39:21 -0500
>Sasha Levin <sashal@kernel.org> wrote:
>
>>  #ifdef IPV6_TEST
>> -	ret.a6.s6_addr32[3] = htonl(n & (BIT(32) - 1));
>> -	ret.a6.s6_addr32[2] = htonl((n >> 32) & (BIT(32) - 1));
>> +	ret.a6.s6_addr32[3] = htonl((uint64_t)n & 0xffffffff);
>
>You don't need a cast or mask there.
>
>> +	ret.a6.s6_addr32[2] = htonl((uint64_t)n >> 32);
>
>That can also be n >> 16 >> 16
>
>Also see upper_32_bits() and lower_32_bits() in wordpart.h
>which might not be available for selftests?

They aren't, tools/include has no copy of wordpart.h.

It works as is, but you're right, htonl(n) and htonl(n >> 16 >> 16) are enough.
Happy to respin with those if the maintainers prefer.

-- 
Thanks,
Sasha
Re: [PATCH] selftests: net: tcp_ao: don't shift a size_t by 32
#12346
Author: patchwork-bot+netdevbpf
Date: Fri, 06 Nov 2026 22:50
25 lines
8606 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  3 Nov 2026 11:39:21 -0500 you wrote:
> gen_tcp_addr() shifts the size_t n right by 32 and masks it with BIT(32)
> - 1. On 32-bit architectures both shifts are as wide as the type, which
> is undefined:
> 
>   aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
> 
> Convert n to uint64_t first and mask with 0xffffffff.
> 
> [...]

Here is the summary with links:
  - selftests: net: tcp_ao: don't shift a size_t by 32
    https://git.kernel.org/netdev/net-next/c/dc8410e0aad5

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads