Skip to content

Commit 8754589

Browse files
Daniel Borkmanndavem330
authored andcommitted
net: replace remaining users of arch_fast_hash with jhash
This patch effectively reverts commit 500f808 ("net: ovs: use CRC32 accelerated flow hash if available"), and other remaining arch_fast_hash() users such as from nfsd via commit 6282cd5 ("NFSD: Don't hand out delegations for 30 seconds after recalling them.") where it has been used as a hash function for bloom filtering. While we think that these users are actually not much of concern, it has been requested to remove the arch_fast_hash() library bits that arose from [1] entirely as per recent discussion [2]. The main argument is that using it as a hash may introduce bias due to its linearity (see avalanche criterion) and thus makes it less clear (though we tried to document that) when this security/performance trade-off is actually acceptable for a general purpose library function. Lets therefore avoid any further confusion on this matter and remove it to prevent any future accidental misuse of it. For the time being, this is going to make hashing of flow keys a bit more expensive in the ovs case, but future work could reevaluate a different hashing discipline. [1] https://patchwork.ozlabs.org/patch/299369/ [2] https://patchwork.ozlabs.org/patch/418756/ Cc: Neil Brown <neilb@suse.de> Cc: Francesco Fusco <fusco@ntop.org> Cc: Jesse Gross <jesse@nicira.com> Cc: Thomas Graf <tgraf@suug.ch> Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7f19fc5 commit 8754589

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

fs/nfsd/nfs4state.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <linux/ratelimit.h>
4242
#include <linux/sunrpc/svcauth_gss.h>
4343
#include <linux/sunrpc/addr.h>
44-
#include <linux/hash.h>
44+
#include <linux/jhash.h>
4545
#include "xdr4.h"
4646
#include "xdr4cb.h"
4747
#include "vfs.h"
@@ -594,7 +594,7 @@ static int delegation_blocked(struct knfsd_fh *fh)
594594
}
595595
spin_unlock(&blocked_delegations_lock);
596596
}
597-
hash = arch_fast_hash(&fh->fh_base, fh->fh_size, 0);
597+
hash = jhash(&fh->fh_base, fh->fh_size, 0);
598598
if (test_bit(hash&255, bd->set[0]) &&
599599
test_bit((hash>>8)&255, bd->set[0]) &&
600600
test_bit((hash>>16)&255, bd->set[0]))
@@ -613,7 +613,7 @@ static void block_delegations(struct knfsd_fh *fh)
613613
u32 hash;
614614
struct bloom_pair *bd = &blocked_delegations;
615615

616-
hash = arch_fast_hash(&fh->fh_base, fh->fh_size, 0);
616+
hash = jhash(&fh->fh_base, fh->fh_size, 0);
617617

618618
spin_lock(&blocked_delegations_lock);
619619
__set_bit(hash&255, bd->set[bd->new]);

lib/rhashtable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <linux/slab.h>
2121
#include <linux/vmalloc.h>
2222
#include <linux/mm.h>
23-
#include <linux/hash.h>
23+
#include <linux/jhash.h>
2424
#include <linux/random.h>
2525
#include <linux/rhashtable.h>
2626

@@ -524,7 +524,7 @@ static size_t rounded_hashtable_size(struct rhashtable_params *params)
524524
* .head_offset = offsetof(struct test_obj, node),
525525
* .key_offset = offsetof(struct test_obj, key),
526526
* .key_len = sizeof(int),
527-
* .hashfn = arch_fast_hash,
527+
* .hashfn = jhash,
528528
* #ifdef CONFIG_PROVE_LOCKING
529529
* .mutex_is_held = &my_mutex_is_held,
530530
* #endif
@@ -545,7 +545,7 @@ static size_t rounded_hashtable_size(struct rhashtable_params *params)
545545
*
546546
* struct rhashtable_params params = {
547547
* .head_offset = offsetof(struct test_obj, node),
548-
* .hashfn = arch_fast_hash,
548+
* .hashfn = jhash,
549549
* .obj_hashfn = my_hash_fn,
550550
* #ifdef CONFIG_PROVE_LOCKING
551551
* .mutex_is_held = &my_mutex_is_held,
@@ -778,7 +778,7 @@ static int __init test_rht_init(void)
778778
.head_offset = offsetof(struct test_obj, node),
779779
.key_offset = offsetof(struct test_obj, value),
780780
.key_len = sizeof(int),
781-
.hashfn = arch_fast_hash,
781+
.hashfn = jhash,
782782
#ifdef CONFIG_PROVE_LOCKING
783783
.mutex_is_held = &test_mutex_is_held,
784784
#endif

net/openvswitch/flow_table.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <linux/if_vlan.h>
2626
#include <net/llc_pdu.h>
2727
#include <linux/kernel.h>
28-
#include <linux/hash.h>
28+
#include <linux/jhash.h>
2929
#include <linux/jiffies.h>
3030
#include <linux/llc.h>
3131
#include <linux/module.h>
@@ -366,7 +366,7 @@ static u32 flow_hash(const struct sw_flow_key *key, int key_start,
366366
/* Make sure number of hash bytes are multiple of u32. */
367367
BUILD_BUG_ON(sizeof(long) % sizeof(u32));
368368

369-
return arch_fast_hash2(hash_key, hash_u32s, 0);
369+
return jhash2(hash_key, hash_u32s, 0);
370370
}
371371

372372
static int flow_key_start(const struct sw_flow_key *key)

0 commit comments

Comments
 (0)