edit commit description
[ext4-patch-queue.git] / jbd2-use-better-hash-function
blobf602d22e583cbdf90a3f6cc7ed3bdb616cb81bf7
1 jbd2: use a better hash function for the revoke table
3 The old hash function didn't work well for 64-bit block numbers, and
4 used undefined (negative) shift right behavior.  Use the generic
5 64-bit hash function instead.
7 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 Reported-by: Andrey Ryabinin <a.ryabinin@samsung.com>
9 ---
10  fs/jbd2/revoke.c | 10 ++--------
11  1 file changed, 2 insertions(+), 8 deletions(-)
13 diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
14 index d5e95a1..c6cbaef 100644
15 --- a/fs/jbd2/revoke.c
16 +++ b/fs/jbd2/revoke.c
17 @@ -92,6 +92,7 @@
18  #include <linux/init.h>
19  #include <linux/bio.h>
20  #include <linux/log2.h>
21 +#include <linux/hash.h>
22  #endif
24  static struct kmem_cache *jbd2_revoke_record_cache;
25 @@ -130,16 +131,9 @@ static void flush_descriptor(journal_t *, struct buffer_head *, int, int);
27  /* Utility functions to maintain the revoke table */
29 -/* Borrowed from buffer.c: this is a tried and tested block hash function */
30  static inline int hash(journal_t *journal, unsigned long long block)
31  {
32 -       struct jbd2_revoke_table_s *table = journal->j_revoke;
33 -       int hash_shift = table->hash_shift;
34 -       int hash = (int)block ^ (int)((block >> 31) >> 1);
36 -       return ((hash << (hash_shift - 6)) ^
37 -               (hash >> 13) ^
38 -               (hash << (hash_shift - 12))) & (table->hash_size - 1);
39 +       return hash_64(block, journal->j_revoke->hash_shift);
40  }
42  static int insert_revoke_hash(journal_t *journal, unsigned long long blocknr,