Commit 66415cf8 authored by Hannes Frederic Sowa's avatar Hannes Frederic Sowa Committed by David S. Miller

net: initialize hashrnd in flow_dissector with net_get_random_once

We also can defer the initialization of hashrnd in flow_dissector
to its first use. Since net_get_random_once is irq safe now we don't
have to audit the call paths if one of this functions get called by an
interrupt handler.

Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f84be2bd
...@@ -184,6 +184,22 @@ bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow) ...@@ -184,6 +184,22 @@ bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow)
EXPORT_SYMBOL(skb_flow_dissect); EXPORT_SYMBOL(skb_flow_dissect);
static u32 hashrnd __read_mostly; static u32 hashrnd __read_mostly;
static __always_inline void __flow_hash_secret_init(void)
{
net_get_random_once(&hashrnd, sizeof(hashrnd));
}
static __always_inline u32 __flow_hash_3words(u32 a, u32 b, u32 c)
{
__flow_hash_secret_init();
return jhash_3words(a, b, c, hashrnd);
}
static __always_inline u32 __flow_hash_1word(u32 a)
{
__flow_hash_secret_init();
return jhash_1word(a, hashrnd);
}
/* /*
* __skb_get_rxhash: calculate a flow hash based on src/dst addresses * __skb_get_rxhash: calculate a flow hash based on src/dst addresses
...@@ -210,9 +226,9 @@ void __skb_get_rxhash(struct sk_buff *skb) ...@@ -210,9 +226,9 @@ void __skb_get_rxhash(struct sk_buff *skb)
swap(keys.port16[0], keys.port16[1]); swap(keys.port16[0], keys.port16[1]);
} }
hash = jhash_3words((__force u32)keys.dst, hash = __flow_hash_3words((__force u32)keys.dst,
(__force u32)keys.src, (__force u32)keys.src,
(__force u32)keys.ports, hashrnd); (__force u32)keys.ports);
if (!hash) if (!hash)
hash = 1; hash = 1;
...@@ -248,7 +264,7 @@ u16 __skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb, ...@@ -248,7 +264,7 @@ u16 __skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb,
hash = skb->sk->sk_hash; hash = skb->sk->sk_hash;
else else
hash = (__force u16) skb->protocol; hash = (__force u16) skb->protocol;
hash = jhash_1word(hash, hashrnd); hash = __flow_hash_1word(hash);
return (u16) (((u64) hash * qcount) >> 32) + qoffset; return (u16) (((u64) hash * qcount) >> 32) + qoffset;
} }
...@@ -340,7 +356,7 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb) ...@@ -340,7 +356,7 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
else else
hash = (__force u16) skb->protocol ^ hash = (__force u16) skb->protocol ^
skb->rxhash; skb->rxhash;
hash = jhash_1word(hash, hashrnd); hash = __flow_hash_1word(hash);
queue_index = map->queues[ queue_index = map->queues[
((u64)hash * map->len) >> 32]; ((u64)hash * map->len) >> 32];
} }
...@@ -395,11 +411,3 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev, ...@@ -395,11 +411,3 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev,
skb_set_queue_mapping(skb, queue_index); skb_set_queue_mapping(skb, queue_index);
return netdev_get_tx_queue(dev, queue_index); return netdev_get_tx_queue(dev, queue_index);
} }
static int __init initialize_hashrnd(void)
{
get_random_bytes(&hashrnd, sizeof(hashrnd));
return 0;
}
late_initcall_sync(initialize_hashrnd);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment