aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/core/dev.c3
-rw-r--r--net/core/flow_dissector.c7
-rw-r--r--net/ipv4/inet_hashtables.c2
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c2
-rw-r--r--net/ipv4/udp.c6
-rw-r--r--net/ipv6/inet6_hashtables.c2
-rw-r--r--net/ipv6/udp.c4
-rw-r--r--net/netfilter/nf_conntrack_core.c2
-rw-r--r--net/netfilter/nf_conntrack_expect.c3
-rw-r--r--net/netfilter/nf_nat_core.c5
-rw-r--r--net/netfilter/xt_HMARK.c2
-rw-r--r--net/netfilter/xt_cluster.c3
-rw-r--r--net/netfilter/xt_hashlimit.c2
-rw-r--r--net/sched/sch_fq_codel.c3
14 files changed, 24 insertions, 22 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index b65a5051361f..1421dad4cb29 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3124,8 +3124,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3124 } 3124 }
3125 3125
3126 if (map) { 3126 if (map) {
3127 tcpu = map->cpus[((u64) hash * map->len) >> 32]; 3127 tcpu = map->cpus[reciprocal_scale(hash, map->len)];
3128
3129 if (cpu_online(tcpu)) { 3128 if (cpu_online(tcpu)) {
3130 cpu = tcpu; 3129 cpu = tcpu;
3131 goto done; 3130 goto done;
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 660c6492fb78..8ffcc97871c8 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -298,7 +298,7 @@ u16 __skb_tx_hash(const struct net_device *dev, struct sk_buff *skb,
298 qcount = dev->tc_to_txq[tc].count; 298 qcount = dev->tc_to_txq[tc].count;
299 } 299 }
300 300
301 return (u16) (((u64)skb_get_hash(skb) * qcount) >> 32) + qoffset; 301 return (u16) reciprocal_scale(skb_get_hash(skb), qcount) + qoffset;
302} 302}
303EXPORT_SYMBOL(__skb_tx_hash); 303EXPORT_SYMBOL(__skb_tx_hash);
304 304
@@ -371,9 +371,8 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
371 if (map->len == 1) 371 if (map->len == 1)
372 queue_index = map->queues[0]; 372 queue_index = map->queues[0];
373 else 373 else
374 queue_index = map->queues[ 374 queue_index = map->queues[reciprocal_scale(skb_get_hash(skb),
375 ((u64)skb_get_hash(skb) * map->len) >> 32]; 375 map->len)];
376
377 if (unlikely(queue_index >= dev->real_num_tx_queues)) 376 if (unlikely(queue_index >= dev->real_num_tx_queues))
378 queue_index = -1; 377 queue_index = -1;
379 } 378 }
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 43116e8c8e13..9111a4e22155 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -229,7 +229,7 @@ begin:
229 } 229 }
230 } else if (score == hiscore && reuseport) { 230 } else if (score == hiscore && reuseport) {
231 matches++; 231 matches++;
232 if (((u64)phash * matches) >> 32 == 0) 232 if (reciprocal_scale(phash, matches) == 0)
233 result = sk; 233 result = sk;
234 phash = next_pseudo_random32(phash); 234 phash = next_pseudo_random32(phash);
235 } 235 }
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 2510c02c2d21..e90f83a3415b 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -285,7 +285,7 @@ clusterip_hashfn(const struct sk_buff *skb,
285 } 285 }
286 286
287 /* node numbers are 1..n, not 0..n */ 287 /* node numbers are 1..n, not 0..n */
288 return (((u64)hashval * config->num_total_nodes) >> 32) + 1; 288 return reciprocal_scale(hashval, config->num_total_nodes) + 1;
289} 289}
290 290
291static inline int 291static inline int
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index f57c0e4c2326..32f9571e776b 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -224,7 +224,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
224 remaining = (high - low) + 1; 224 remaining = (high - low) + 1;
225 225
226 rand = prandom_u32(); 226 rand = prandom_u32();
227 first = (((u64)rand * remaining) >> 32) + low; 227 first = reciprocal_scale(rand, remaining) + low;
228 /* 228 /*
229 * force rand to be an odd multiple of UDP_HTABLE_SIZE 229 * force rand to be an odd multiple of UDP_HTABLE_SIZE
230 */ 230 */
@@ -448,7 +448,7 @@ begin:
448 } 448 }
449 } else if (score == badness && reuseport) { 449 } else if (score == badness && reuseport) {
450 matches++; 450 matches++;
451 if (((u64)hash * matches) >> 32 == 0) 451 if (reciprocal_scale(hash, matches) == 0)
452 result = sk; 452 result = sk;
453 hash = next_pseudo_random32(hash); 453 hash = next_pseudo_random32(hash);
454 } 454 }
@@ -529,7 +529,7 @@ begin:
529 } 529 }
530 } else if (score == badness && reuseport) { 530 } else if (score == badness && reuseport) {
531 matches++; 531 matches++;
532 if (((u64)hash * matches) >> 32 == 0) 532 if (reciprocal_scale(hash, matches) == 0)
533 result = sk; 533 result = sk;
534 hash = next_pseudo_random32(hash); 534 hash = next_pseudo_random32(hash);
535 } 535 }
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 262e13c02ec2..826019008958 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -198,7 +198,7 @@ begin:
198 } 198 }
199 } else if (score == hiscore && reuseport) { 199 } else if (score == hiscore && reuseport) {
200 matches++; 200 matches++;
201 if (((u64)phash * matches) >> 32 == 0) 201 if (reciprocal_scale(phash, matches) == 0)
202 result = sk; 202 result = sk;
203 phash = next_pseudo_random32(phash); 203 phash = next_pseudo_random32(phash);
204 } 204 }
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 4836af8f582d..25ffe737b975 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -243,7 +243,7 @@ begin:
243 goto exact_match; 243 goto exact_match;
244 } else if (score == badness && reuseport) { 244 } else if (score == badness && reuseport) {
245 matches++; 245 matches++;
246 if (((u64)hash * matches) >> 32 == 0) 246 if (reciprocal_scale(hash, matches) == 0)
247 result = sk; 247 result = sk;
248 hash = next_pseudo_random32(hash); 248 hash = next_pseudo_random32(hash);
249 } 249 }
@@ -323,7 +323,7 @@ begin:
323 } 323 }
324 } else if (score == badness && reuseport) { 324 } else if (score == badness && reuseport) {
325 matches++; 325 matches++;
326 if (((u64)hash * matches) >> 32 == 0) 326 if (reciprocal_scale(hash, matches) == 0)
327 result = sk; 327 result = sk;
328 hash = next_pseudo_random32(hash); 328 hash = next_pseudo_random32(hash);
329 } 329 }
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 0b634e7f1652..5016a6929085 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -142,7 +142,7 @@ static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple, u16 zone)
142 142
143static u32 __hash_bucket(u32 hash, unsigned int size) 143static u32 __hash_bucket(u32 hash, unsigned int size)
144{ 144{
145 return ((u64)hash * size) >> 32; 145 return reciprocal_scale(hash, size);
146} 146}
147 147
148static u32 hash_bucket(u32 hash, const struct net *net) 148static u32 hash_bucket(u32 hash, const struct net *net)
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index f87e8f68ad45..91a1837acd0e 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -83,7 +83,8 @@ static unsigned int nf_ct_expect_dst_hash(const struct nf_conntrack_tuple *tuple
83 hash = jhash2(tuple->dst.u3.all, ARRAY_SIZE(tuple->dst.u3.all), 83 hash = jhash2(tuple->dst.u3.all, ARRAY_SIZE(tuple->dst.u3.all),
84 (((tuple->dst.protonum ^ tuple->src.l3num) << 16) | 84 (((tuple->dst.protonum ^ tuple->src.l3num) << 16) |
85 (__force __u16)tuple->dst.u.all) ^ nf_conntrack_hash_rnd); 85 (__force __u16)tuple->dst.u.all) ^ nf_conntrack_hash_rnd);
86 return ((u64)hash * nf_ct_expect_hsize) >> 32; 86
87 return reciprocal_scale(hash, nf_ct_expect_hsize);
87} 88}
88 89
89struct nf_conntrack_expect * 90struct nf_conntrack_expect *
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 552f97cd9fde..4e0b47831d43 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -126,7 +126,8 @@ hash_by_src(const struct net *net, u16 zone,
126 /* Original src, to ensure we map it consistently if poss. */ 126 /* Original src, to ensure we map it consistently if poss. */
127 hash = jhash2((u32 *)&tuple->src, sizeof(tuple->src) / sizeof(u32), 127 hash = jhash2((u32 *)&tuple->src, sizeof(tuple->src) / sizeof(u32),
128 tuple->dst.protonum ^ zone ^ nf_conntrack_hash_rnd); 128 tuple->dst.protonum ^ zone ^ nf_conntrack_hash_rnd);
129 return ((u64)hash * net->ct.nat_htable_size) >> 32; 129
130 return reciprocal_scale(hash, net->ct.nat_htable_size);
130} 131}
131 132
132/* Is this tuple already taken? (not by us) */ 133/* Is this tuple already taken? (not by us) */
@@ -274,7 +275,7 @@ find_best_ips_proto(u16 zone, struct nf_conntrack_tuple *tuple,
274 } 275 }
275 276
276 var_ipp->all[i] = (__force __u32) 277 var_ipp->all[i] = (__force __u32)
277 htonl(minip + (((u64)j * dist) >> 32)); 278 htonl(minip + reciprocal_scale(j, dist));
278 if (var_ipp->all[i] != range->max_addr.all[i]) 279 if (var_ipp->all[i] != range->max_addr.all[i])
279 full_range = true; 280 full_range = true;
280 281
diff --git a/net/netfilter/xt_HMARK.c b/net/netfilter/xt_HMARK.c
index 73b73f687c58..02afaf48a729 100644
--- a/net/netfilter/xt_HMARK.c
+++ b/net/netfilter/xt_HMARK.c
@@ -126,7 +126,7 @@ hmark_hash(struct hmark_tuple *t, const struct xt_hmark_info *info)
126 hash = jhash_3words(src, dst, t->uports.v32, info->hashrnd); 126 hash = jhash_3words(src, dst, t->uports.v32, info->hashrnd);
127 hash = hash ^ (t->proto & info->proto_mask); 127 hash = hash ^ (t->proto & info->proto_mask);
128 128
129 return (((u64)hash * info->hmodulus) >> 32) + info->hoffset; 129 return reciprocal_scale(hash, info->hmodulus) + info->hoffset;
130} 130}
131 131
132static void 132static void
diff --git a/net/netfilter/xt_cluster.c b/net/netfilter/xt_cluster.c
index f4af1bfafb1c..96fa26b20b67 100644
--- a/net/netfilter/xt_cluster.c
+++ b/net/netfilter/xt_cluster.c
@@ -55,7 +55,8 @@ xt_cluster_hash(const struct nf_conn *ct,
55 WARN_ON(1); 55 WARN_ON(1);
56 break; 56 break;
57 } 57 }
58 return (((u64)hash * info->total_nodes) >> 32); 58
59 return reciprocal_scale(hash, info->total_nodes);
59} 60}
60 61
61static inline bool 62static inline bool
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 47dc6836830a..52eb3e03458d 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -135,7 +135,7 @@ hash_dst(const struct xt_hashlimit_htable *ht, const struct dsthash_dst *dst)
135 * give results between [0 and cfg.size-1] and same hash distribution, 135 * give results between [0 and cfg.size-1] and same hash distribution,
136 * but using a multiply, less expensive than a divide 136 * but using a multiply, less expensive than a divide
137 */ 137 */
138 return ((u64)hash * ht->cfg.size) >> 32; 138 return reciprocal_scale(hash, ht->cfg.size);
139} 139}
140 140
141static struct dsthash_ent * 141static struct dsthash_ent *
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index 063b726bf1f8..cc56c8bb9bed 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -77,7 +77,8 @@ static unsigned int fq_codel_hash(const struct fq_codel_sched_data *q,
77 hash = jhash_3words((__force u32)keys.dst, 77 hash = jhash_3words((__force u32)keys.dst,
78 (__force u32)keys.src ^ keys.ip_proto, 78 (__force u32)keys.src ^ keys.ip_proto,
79 (__force u32)keys.ports, q->perturbation); 79 (__force u32)keys.ports, q->perturbation);
80 return ((u64)hash * q->flows_cnt) >> 32; 80
81 return reciprocal_scale(hash, q->flows_cnt);
81} 82}
82 83
83static unsigned int fq_codel_classify(struct sk_buff *skb, struct Qdisc *sch, 84static unsigned int fq_codel_classify(struct sk_buff *skb, struct Qdisc *sch,