tcp: use __jhash_final() in inet6_ehashfn()
Subsystems (3)
PATCH 1/1 tcp: use __jhash_final() in inet6_ehashfn()
I misread jhash2() implementation.
Last round should use __jhash_final() instead of __jhash_mix().
Using __jhash_mix() here leaves entropy distributed across a, b, and c, which might lead to incomplete diffusion of the faddr and fport bits into the bucket index. Replacing this last __jhash_mix() with __jhash_final() provides the correct avalanche properties for the returned value in c.
$ scripts/bloat-o-meter -t vmlinux.0 vmlinux add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-4 (-4) Function old new delta inet6_ehashfn 306 302 -4 Total: Before=25155089, After=25155085, chg -0.00%
--- net/ipv6/inet6_hashtables.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/inet6_hashtables.c +1 -1
@@ -63,7 +63,7 @@ u32 inet6_ehashfn(const struct net *net, a += (__force u32 )faddr->s6_addr32[2 ]; b += (__force u32 )faddr->s6_addr32[3 ]; c += (__force u32 )fport; -__jhash_mix (a, b, c); +__jhash_final (a, b, c);/* Note: We need to add @lport instead of fully hashing it. * See commits 9544d60a2605 ("inet: change lport contribution
Signature · 1 line
2.53.0.959.g497ff81fa9-goog
Quoted 11 lines · Eric Dumazet
I misread
jhash2()implementation.Last round should use
__jhash_final()instead of__jhash_mix().Using
__jhash_mix()here leaves entropy distributed across a, b, and c, which might lead to incomplete diffusion of the faddr and fport bits into the bucket index. Replacing this last__jhash_mix()with__jhash_final()provides the correct avalanche properties for the returned value in c.
Quoted 8 lines
$ scripts/bloat-o-meter -t vmlinux.0 vmlinux add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-4 (-4) Function old new delta inet6_ehashfn 306 302 -4 Total: Before=25155089, After=25155085, chg -0.00%Fixes 854587e69ef3 ("tcp: improve inet6_ehashfn() entropy")Signed-off-by Eric Dumazet <[email protected]>
Jakub Kicinski
maintainerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
tcp: use __jhash_final() in inet6_ehashfn()
This commit fixes a bug in inet6_ehashfn() where the last round of jhash incorrectly used __jhash_mix() instead of __jhash_final(), which left entropy distributed incompletely and didn't provide proper avalanche properties.
net/ipv6/inet6_hashtables.c u32 inet6_ehashfn(const struct net *net, · line 69
Quoted 13 lines
net/ipv6/inet6_hashtables.c +1
-1@@ -63,7 +63,7 @@ u32 inet6_ehashfn(const struct net *net, a += (__force u32 )faddr->s6_addr32[2 ]; b += (__force u32 )faddr->s6_addr32[3 ]; c += (__force u32 )fport; -__jhash_mix (a, b, c); +__jhash_final (a, b, c);/* Note: We need to add @lport instead of fully hashing it. * See commits 9544d60a2605 ("inet: change lport contribution
This isn't a bug, but the comment earlier in the function needs updating. The comment currently says:
/*
* Please look at jhash() implementation for reference.
* Hash laddr + faddr + lport/fport + net_hash_mix.
* Notes:
* We combine laddr[0] (high order 32 bits of local address)
* with net_hash_mix() to avoid using __jhash_final(a, b, c). *
The line "to avoid using __jhash_final(a, b, c)" is now misleading since the code was just changed to use __jhash_final() in the last round. Should this comment be updated to explain that we combine laddr[0] with net_hash_mix() to avoid an extra __jhash_mix() round, and that the final round correctly uses __jhash_final() for proper avalanche properties?
Signature · 1 line
pw-bot: cr
Quoted 38 lines · Jakub Kicinski
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
tcp: use__jhash_final()ininet6_ehashfn()This commit fixes a bug in
inet6_ehashfn()where the last round of jhash incorrectly used__jhash_mix()instead of__jhash_final(), which left entropy distributed incompletely and didn't provide proper avalanche properties.net/ipv6/inet6_hashtables.c u32 inet6_ehashfn(const struct net *net, · line 69
Quoted 13 lines
net/ipv6/inet6_hashtables.c +1
-1@@ -63,7 +63,7 @@ u32 inet6_ehashfn(const struct net *net, a += (__force u32 )faddr->s6_addr32[2 ]; b += (__force u32 )faddr->s6_addr32[3 ]; c += (__force u32 )fport; -__jhash_mix (a, b, c); +__jhash_final (a, b, c);/* Note: We need to add @lport instead of fully hashing it. * See commits 9544d60a2605 ("inet: change lport contribution This isn't a bug, but the comment earlier in the function needs updating. The comment currently says:
/*
* Please look atjhash()implementation for reference.
* Hash laddr + faddr + lport/fport +net_hash_mix.
* Notes:
* We combine laddr[0] (high order 32 bits of local address)
* withnet_hash_mix()to avoid using__jhash_final(a, b, c). *
Quoted 5 lines
The line "to avoid using
__jhash_final(a, b, c)" is now misleading since the code was just changed to use__jhash_final()in the last round. Should this comment be updated to explain that we combine laddr[0] withnet_hash_mix()to avoid an extra__jhash_mix()round, and that the final round correctly uses__jhash_final()for proper avalanche properties?
Ah well, comments are stale after one week.