Skip to content

Commit 5424ea2

Browse files
edumazetdavem330
authored andcommitted
netns: get more entropy from net_hash_mix()
struct net are effectively allocated from order-1 pages on x86, with one object per slab, meaning that the 13 low order bits of their addresses are zero. Once shifted by L1_CACHE_SHIFT, this leaves 7 zero-bits, meaning that net_hash_mix() does not help spreading objects on various hash tables. For example, TCP listen table has 32 buckets, meaning that all netns use the same bucket for port 80 or port 443. Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Maciej Żenczykowski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6c1f0a1 commit 5424ea2

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

include/net/netns/hash.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ struct net;
99
static inline u32 net_hash_mix(const struct net *net)
1010
{
1111
#ifdef CONFIG_NET_NS
12-
/*
13-
* shift this right to eliminate bits, that are
14-
* always zeroed
15-
*/
16-
17-
return (u32)(((unsigned long)net) >> L1_CACHE_SHIFT);
12+
return (u32)(((unsigned long)net) >> ilog2(sizeof(*net)));
1813
#else
1914
return 0;
2015
#endif

0 commit comments

Comments
 (0)