From: Thomas Gleixner Date: Sun, 8 Mar 2020 18:07:17 +0000 (+0100) Subject: futex: Unbreak futex hashing X-Git-Tag: MMI-RSBS31.Q1-48-36-26~34 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=10887969a11071ece522e6fdd0cc9121b1a637b6;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git 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 regression. 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 Link: https://lkml.kernel.org/r/87h7yy90ve.fsf@nanos.tec.linutronix.de Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 25963a6606d3180b308425a402075a4bb9d07e01) Signed-off-by: Gajjala Chakradhar Change-Id: I25295391b13ba6e408afccfcd8d35724c94c39e0 Reviewed-on: https://gerrit.mot.com/2085476 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Xiangpo Zhao Submit-Approved: Jira Key (cherry picked from commit 1960ccb04d18ca01bac28207884984fd20bf65ea) --- diff --git a/kernel/futex.c b/kernel/futex.c index 1cd0b330b82e..4c172bba0b8a 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -392,9 +392,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, key->both.offset); + return &futex_queues[hash & (futex_hashsize - 1)]; }