Revert "net/flow_dissector: switch to siphash"
Fix build-break
This reverts commit 91460c9acb7c3087f9cc62dbda84c0343a0e1051.
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 7bb075b..3f61c64 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1068,8 +1068,7 @@
return skb->hash;
}
-__u32 skb_get_hash_perturb(const struct sk_buff *skb,
- const siphash_key_t *perturb);
+__u32 skb_get_hash_perturb(const struct sk_buff *skb, u32 perturb);
static inline __u32 skb_get_hash_raw(const struct sk_buff *skb)
{
diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index 62a4624..8c8548c 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -3,7 +3,6 @@
#include <linux/types.h>
#include <linux/in6.h>
-#include <linux/siphash.h>
#include <uapi/linux/if_ether.h>
/**
@@ -147,7 +146,7 @@
struct flow_keys {
struct flow_dissector_key_control control;
#define FLOW_KEYS_HASH_START_FIELD basic
- struct flow_dissector_key_basic basic __aligned(SIPHASH_ALIGNMENT);
+ struct flow_dissector_key_basic basic;
struct flow_dissector_key_tags tags;
struct flow_dissector_key_keyid keyid;
struct flow_dissector_key_ports ports;
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 903dc9e..ee90827 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -506,34 +506,45 @@
}
EXPORT_SYMBOL(__skb_flow_dissect);
-static siphash_key_t 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 const void *flow_keys_hash_start(const struct flow_keys *flow)
+static __always_inline u32 __flow_hash_words(const u32 *words, u32 length,
+ u32 keyval)
{
- BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET % SIPHASH_ALIGNMENT);
- return &flow->FLOW_KEYS_HASH_START_FIELD;
+ return jhash2(words, length, keyval);
+}
+
+static inline const u32 *flow_keys_hash_start(const struct flow_keys *flow)
+{
+ const void *p = flow;
+
+ BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET % sizeof(u32));
+ return (const u32 *)(p + FLOW_KEYS_HASH_OFFSET);
}
static inline size_t flow_keys_hash_length(const struct flow_keys *flow)
{
- size_t len = offsetof(typeof(*flow), addrs) - FLOW_KEYS_HASH_OFFSET;
+ size_t diff = FLOW_KEYS_HASH_OFFSET + sizeof(flow->addrs);
+ BUILD_BUG_ON((sizeof(*flow) - FLOW_KEYS_HASH_OFFSET) % sizeof(u32));
+ BUILD_BUG_ON(offsetof(typeof(*flow), addrs) !=
+ sizeof(*flow) - sizeof(flow->addrs));
switch (flow->control.addr_type) {
case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
- len += sizeof(flow->addrs.v4addrs);
+ diff -= sizeof(flow->addrs.v4addrs);
break;
case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
- len += sizeof(flow->addrs.v6addrs);
+ diff -= sizeof(flow->addrs.v6addrs);
break;
case FLOW_DISSECTOR_KEY_TIPC_ADDRS:
- len += sizeof(flow->addrs.tipcaddrs);
+ diff -= sizeof(flow->addrs.tipcaddrs);
break;
}
- return len;
+ return (sizeof(*flow) - diff) / sizeof(u32);
}
__be32 flow_get_u32_src(const struct flow_keys *flow)
@@ -599,15 +610,14 @@
}
}
-static inline u32 __flow_hash_from_keys(struct flow_keys *keys,
- const siphash_key_t *keyval)
+static inline u32 __flow_hash_from_keys(struct flow_keys *keys, u32 keyval)
{
u32 hash;
__flow_hash_consistentify(keys);
- hash = siphash(flow_keys_hash_start(keys),
- flow_keys_hash_length(keys), keyval);
+ hash = __flow_hash_words(flow_keys_hash_start(keys),
+ flow_keys_hash_length(keys), keyval);
if (!hash)
hash = 1;
@@ -617,13 +627,12 @@
u32 flow_hash_from_keys(struct flow_keys *keys)
{
__flow_hash_secret_init();
- return __flow_hash_from_keys(keys, &hashrnd);
+ return __flow_hash_from_keys(keys, hashrnd);
}
EXPORT_SYMBOL(flow_hash_from_keys);
static inline u32 ___skb_get_hash(const struct sk_buff *skb,
- struct flow_keys *keys,
- const siphash_key_t *keyval)
+ struct flow_keys *keys, u32 keyval)
{
skb_flow_dissect_flow_keys(skb, keys,
FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
@@ -671,7 +680,7 @@
NULL, 0, 0, 0,
FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
- return __flow_hash_from_keys(&keys, &hashrnd);
+ return __flow_hash_from_keys(&keys, hashrnd);
}
EXPORT_SYMBOL_GPL(__skb_get_hash_symmetric);
@@ -690,13 +699,12 @@
__flow_hash_secret_init();
- __skb_set_sw_hash(skb, ___skb_get_hash(skb, &keys, &hashrnd),
+ __skb_set_sw_hash(skb, ___skb_get_hash(skb, &keys, hashrnd),
flow_keys_have_l4(&keys));
}
EXPORT_SYMBOL(__skb_get_hash);
-__u32 skb_get_hash_perturb(const struct sk_buff *skb,
- const siphash_key_t *perturb)
+__u32 skb_get_hash_perturb(const struct sk_buff *skb, u32 perturb)
{
struct flow_keys keys;
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index 1800f79..d3fc8f9 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -55,7 +55,7 @@
struct fq_codel_flow *flows; /* Flows table [flows_cnt] */
u32 *backlogs; /* backlog table [flows_cnt] */
u32 flows_cnt; /* number of flows */
- siphash_key_t perturbation; /* hash perturbation */
+ u32 perturbation; /* hash perturbation */
u32 quantum; /* psched_mtu(qdisc_dev(sch)); */
struct codel_params cparams;
struct codel_stats cstats;
@@ -69,7 +69,7 @@
static unsigned int fq_codel_hash(const struct fq_codel_sched_data *q,
struct sk_buff *skb)
{
- u32 hash = skb_get_hash_perturb(skb, &q->perturbation);
+ u32 hash = skb_get_hash_perturb(skb, q->perturbation);
return reciprocal_scale(hash, q->flows_cnt);
}
@@ -420,7 +420,7 @@
sch->limit = 10*1024;
q->flows_cnt = 1024;
q->quantum = psched_mtu(qdisc_dev(sch));
- get_random_bytes(&q->perturbation, sizeof(q->perturbation));
+ q->perturbation = prandom_u32();
INIT_LIST_HEAD(&q->new_flows);
INIT_LIST_HEAD(&q->old_flows);
codel_params_init(&q->cparams, sch);
diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c
index 8441cee..45d4b2f 100644
--- a/net/sched/sch_hhf.c
+++ b/net/sched/sch_hhf.c
@@ -4,11 +4,11 @@
* Copyright (C) 2013 Nandita Dukkipati <nanditad@google.com>
*/
+#include <linux/jhash.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/vmalloc.h>
-#include <linux/siphash.h>
#include <net/pkt_sched.h>
#include <net/sock.h>
@@ -125,7 +125,7 @@
struct hhf_sched_data {
struct wdrr_bucket buckets[WDRR_BUCKET_CNT];
- siphash_key_t perturbation; /* hash perturbation */
+ u32 perturbation; /* hash perturbation */
u32 quantum; /* psched_mtu(qdisc_dev(sch)); */
u32 drop_overlimit; /* number of times max qdisc packet
* limit was hit
@@ -263,7 +263,7 @@
}
/* Get hashed flow-id of the skb. */
- hash = skb_get_hash_perturb(skb, &q->perturbation);
+ hash = skb_get_hash_perturb(skb, q->perturbation);
/* Check if this packet belongs to an already established HH flow. */
flow_pos = hash & HHF_BIT_MASK;
@@ -599,7 +599,7 @@
sch->limit = 1000;
q->quantum = psched_mtu(qdisc_dev(sch));
- get_random_bytes(&q->perturbation, sizeof(q->perturbation));
+ q->perturbation = prandom_u32();
INIT_LIST_HEAD(&q->new_buckets);
INIT_LIST_HEAD(&q->old_buckets);
diff --git a/net/sched/sch_sfb.c b/net/sched/sch_sfb.c
index 10c0b18..c696116 100644
--- a/net/sched/sch_sfb.c
+++ b/net/sched/sch_sfb.c
@@ -22,7 +22,7 @@
#include <linux/errno.h>
#include <linux/skbuff.h>
#include <linux/random.h>
-#include <linux/siphash.h>
+#include <linux/jhash.h>
#include <net/ip.h>
#include <net/pkt_sched.h>
#include <net/inet_ecn.h>
@@ -48,7 +48,7 @@
* (Section 4.4 of SFB reference : moving hash functions)
*/
struct sfb_bins {
- siphash_key_t perturbation; /* siphash key */
+ u32 perturbation; /* jhash perturbation */
struct sfb_bucket bins[SFB_LEVELS][SFB_NUMBUCKETS];
};
@@ -219,8 +219,7 @@
static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q)
{
- get_random_bytes(&q->bins[slot].perturbation,
- sizeof(q->bins[slot].perturbation));
+ q->bins[slot].perturbation = prandom_u32();
}
static void sfb_swap_slot(struct sfb_sched_data *q)
@@ -314,9 +313,9 @@
/* If using external classifiers, get result and record it. */
if (!sfb_classify(skb, fl, &ret, &salt))
goto other_drop;
- sfbhash = siphash_1u32(salt, &q->bins[slot].perturbation);
+ sfbhash = jhash_1word(salt, q->bins[slot].perturbation);
} else {
- sfbhash = skb_get_hash_perturb(skb, &q->bins[slot].perturbation);
+ sfbhash = skb_get_hash_perturb(skb, q->bins[slot].perturbation);
}
@@ -352,7 +351,7 @@
/* Inelastic flow */
if (q->double_buffering) {
sfbhash = skb_get_hash_perturb(skb,
- &q->bins[slot].perturbation);
+ q->bins[slot].perturbation);
if (!sfbhash)
sfbhash = 1;
sfb_skb_cb(skb)->hashes[slot] = sfbhash;
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index e5d3acf..3f2c3ee 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -18,7 +18,7 @@
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/skbuff.h>
-#include <linux/siphash.h>
+#include <linux/jhash.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <net/netlink.h>
@@ -120,7 +120,7 @@
u8 headdrop;
u8 maxdepth; /* limit of packets per flow */
- siphash_key_t perturbation;
+ u32 perturbation;
u8 cur_depth; /* depth of longest slot */
u8 flags;
unsigned short scaled_quantum; /* SFQ_ALLOT_SIZE(quantum) */
@@ -158,7 +158,7 @@
static unsigned int sfq_hash(const struct sfq_sched_data *q,
const struct sk_buff *skb)
{
- return skb_get_hash_perturb(skb, &q->perturbation) & (q->divisor - 1);
+ return skb_get_hash_perturb(skb, q->perturbation) & (q->divisor - 1);
}
static unsigned int sfq_classify(struct sk_buff *skb, struct Qdisc *sch,
@@ -607,11 +607,9 @@
struct Qdisc *sch = (struct Qdisc *)arg;
struct sfq_sched_data *q = qdisc_priv(sch);
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
- siphash_key_t nkey;
- get_random_bytes(&nkey, sizeof(nkey));
spin_lock(root_lock);
- q->perturbation = nkey;
+ q->perturbation = prandom_u32();
if (!q->filter_list && q->tail)
sfq_rehash(sch);
spin_unlock(root_lock);
@@ -680,7 +678,7 @@
del_timer(&q->perturb_timer);
if (q->perturb_period) {
mod_timer(&q->perturb_timer, jiffies + q->perturb_period);
- get_random_bytes(&q->perturbation, sizeof(q->perturbation));
+ q->perturbation = prandom_u32();
}
sch_tree_unlock(sch);
kfree(p);
@@ -736,7 +734,7 @@
q->quantum = psched_mtu(qdisc_dev(sch));
q->scaled_quantum = SFQ_ALLOT_SIZE(q->quantum);
q->perturb_period = 0;
- get_random_bytes(&q->perturbation, sizeof(q->perturbation));
+ q->perturbation = prandom_u32();
if (opt) {
int err = sfq_change(sch, opt);