blob: a5e17fde9b7571409d6287796e0a6255706b8b51 [file] [log] [blame]
From bea736586da70f39a1e8a511ef2d6c25e956a9c3 Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <>
Date: Sun, 8 Mar 2020 19:07:17 +0100
Subject: [PATCH] futex: Unbreak futex hashing
commit 8d67743653dce5a0e7aa500fcccb237cde7ad88e upstream.
The recent futex inode life time fix changed the ordering of the futex key
union struct members, but forgot to adjust the hash function accordingly,
As a result the hashing omits the leading 64bit and even hashes beyond the
futex key causing a bad hash distribution which led to a ~100% performance
Hand in the futex key pointer instead of a random struct member and make
the size calculation based of the struct offset.
Fixes: 8019ad13ef7f ("futex: Fix inode life-time issue")
Reported-by: Rong Chen <>
Decoded-by: Linus Torvalds <>
Signed-off-by: Thomas Gleixner <>
Tested-by: Rong Chen <>
Signed-off-by: Paul Gortmaker <>
diff --git a/kernel/futex.c b/kernel/futex.c
index da5155cc51bd..5758f44c994a 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -379,9 +379,9 @@ static inline int hb_waiters_pending(struct futex_hash_bucket *hb)
static struct futex_hash_bucket *hash_futex(union futex_key *key)
- u32 hash = jhash2((u32*)&key->both.word,
- (sizeof(key->both.word)+sizeof(key->both.ptr))/4,
+ u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
return &futex_queues[hash & (futex_hashsize - 1)];