summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2018-06-23 01:27:47 +0200
committerDavid S. Miller <davem@davemloft.net>2018-06-23 03:59:56 +0200
commit5424ea27390f1f8903e5de0eaa0c5b561e8e877a (patch)
treebd28494ae183d0327978152a43a1124dcc71327a
parentnet: drivers/net: Convert random_ether_addr to eth_random_addr (diff)
downloadlinux-5424ea27390f1f8903e5de0eaa0c5b561e8e877a.tar.xz
linux-5424ea27390f1f8903e5de0eaa0c5b561e8e877a.zip
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 <edumazet@google.com> Reported-by: Maciej Żenczykowski <maze@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/netns/hash.h7
1 files changed, 1 insertions, 6 deletions
diff --git a/include/net/netns/hash.h b/include/net/netns/hash.h
index 24c78183a4c2..16a842456189 100644
--- a/include/net/netns/hash.h
+++ b/include/net/netns/hash.h
@@ -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