Skip to content

Commit

Permalink
netns: get more entropy from net_hash_mix()
Browse files Browse the repository at this point in the history
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 <edumazet@google.com>
Reported-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Jun 23, 2018
1 parent 6c1f0a1 commit 5424ea2
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions include/net/netns/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ struct net;
static inline u32 net_hash_mix(const struct net *net)
{
#ifdef CONFIG_NET_NS
/*
* shift this right to eliminate bits, that are
* always zeroed
*/

return (u32)(((unsigned long)net) >> L1_CACHE_SHIFT);
return (u32)(((unsigned long)net) >> ilog2(sizeof(*net)));
#else
return 0;
#endif
Expand Down

0 comments on commit 5424ea2

Please sign in to comment.