[PATCH 1/5] scripts: add bit count parameter back to host hash functions
From: Julian Braha
Date: Thu Nov 26 2026 - 19:00:40 EST
This partially reverts commit f93d6bfbd2f7 ("kconfig: use hash table to
reuse expressions").
As reported by Linus [1], when the kernel's internal hash and hash table
implementations were copied over for Kconfig to use, several functions
were simplified to remove their second 'bits' parameter. But the usage of
this simplified implementation led to poor hash table performance due to
using the lower bits despite hash_32() putting the significant bits in the
high bits of the result.
Let's revert the parameter simplification: the host versions of hash_32()
and hash_ptr() will take the number of high bits, as is done in the
kernel's internal implementation.
Accordingly, adjust the callers of 'hash_32()' and 'hash_ptr()' to use
the additional parameter. This is a pure refactor (no functional changes),
so pass 32 to preserve the existing behavior.
Link: https://lore.kernel.org/all/CAHk-=wi_GuySe0L-uCAM2+nScCLYGBp5BLi6UUPR1gALmNM_3w@xxxxxxxxxxxxxx/ [1]
Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>
---
scripts/gendwarfksyms/cache.c | 4 ++--
scripts/gendwarfksyms/die.c | 2 +-
scripts/gendwarfksyms/gendwarfksyms.h | 2 +-
scripts/gendwarfksyms/kabi.c | 2 +-
scripts/gendwarfksyms/symbols.c | 2 +-
scripts/include/hash.h | 8 ++++----
scripts/kconfig/expr.c | 2 +-
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/scripts/gendwarfksyms/cache.c b/scripts/gendwarfksyms/cache.c
index 1c640db93db3..a4d18a9489e3 100644
--- a/scripts/gendwarfksyms/cache.c
+++ b/scripts/gendwarfksyms/cache.c
@@ -18,14 +18,14 @@ void cache_set(struct cache *cache, unsigned long key, int value)
ci = xmalloc(sizeof(*ci));
ci->key = key;
ci->value = value;
- hash_add(cache->cache, &ci->hash, hash_32(key));
+ hash_add(cache->cache, &ci->hash, hash_32(key, 32));
}
int cache_get(struct cache *cache, unsigned long key)
{
struct cache_item *ci;
- hash_for_each_possible(cache->cache, ci, hash, hash_32(key)) {
+ hash_for_each_possible(cache->cache, ci, hash, hash_32(key, 32)) {
if (ci->key == key)
return ci->value;
}
diff --git a/scripts/gendwarfksyms/die.c b/scripts/gendwarfksyms/die.c
index 052f7a3f975a..4e390a6295a3 100644
--- a/scripts/gendwarfksyms/die.c
+++ b/scripts/gendwarfksyms/die.c
@@ -16,7 +16,7 @@ static unsigned int map_misses;
static inline unsigned int die_hash(uintptr_t addr, enum die_state state)
{
- return hash_32(addr_hash(addr) ^ (unsigned int)state);
+ return hash_32(addr_hash(addr) ^ (unsigned int)state, 32);
}
static void init_die(struct die *cd)
diff --git a/scripts/gendwarfksyms/gendwarfksyms.h b/scripts/gendwarfksyms/gendwarfksyms.h
index 32cec8f7695a..f4f21d6090e7 100644
--- a/scripts/gendwarfksyms/gendwarfksyms.h
+++ b/scripts/gendwarfksyms/gendwarfksyms.h
@@ -95,7 +95,7 @@ extern int symtypes;
static inline unsigned int addr_hash(uintptr_t addr)
{
- return hash_ptr((const void *)addr);
+ return hash_ptr((const void *)addr, 32);
}
enum symbol_state {
diff --git a/scripts/gendwarfksyms/kabi.c b/scripts/gendwarfksyms/kabi.c
index e3c2a3ccf51a..2d941ee13c9b 100644
--- a/scripts/gendwarfksyms/kabi.c
+++ b/scripts/gendwarfksyms/kabi.c
@@ -92,7 +92,7 @@ static HASHTABLE_DEFINE(rules, 1 << RULE_HASH_BITS);
static inline unsigned int rule_values_hash(enum kabi_rule_type type,
const char *target)
{
- return hash_32(type) ^ hash_str(target);
+ return hash_32(type, 32) ^ hash_str(target);
}
static inline unsigned int rule_hash(const struct rule *rule)
diff --git a/scripts/gendwarfksyms/symbols.c b/scripts/gendwarfksyms/symbols.c
index 42cd27c9cec4..b4110b0e12ce 100644
--- a/scripts/gendwarfksyms/symbols.c
+++ b/scripts/gendwarfksyms/symbols.c
@@ -15,7 +15,7 @@ static HASHTABLE_DEFINE(symbol_names, 1 << SYMBOL_HASH_BITS);
static inline unsigned int symbol_addr_hash(const struct symbol_addr *addr)
{
- return hash_32(addr->section ^ addr_hash(addr->address));
+ return hash_32(addr->section ^ addr_hash(addr->address), 32);
}
static unsigned int __for_each_addr(struct symbol *sym, symbol_callback_t func,
diff --git a/scripts/include/hash.h b/scripts/include/hash.h
index efa904368a62..ae0d3fc8d470 100644
--- a/scripts/include/hash.h
+++ b/scripts/include/hash.h
@@ -15,14 +15,14 @@ static inline unsigned int hash_str(const char *s)
/* simplified version of functions from include/linux/hash.h */
#define GOLDEN_RATIO_32 0x61C88647
-static inline unsigned int hash_32(unsigned int val)
+static inline unsigned int hash_32(unsigned int val, unsigned int bits)
{
- return 0x61C88647 * val;
+ return bits ? (val * GOLDEN_RATIO_32) >> (32 - bits) : 0;
}
-static inline unsigned int hash_ptr(const void *ptr)
+static inline unsigned int hash_ptr(const void *ptr, unsigned int bits)
{
- return hash_32((unsigned int)(unsigned long)ptr);
+ return hash_32((unsigned int)(unsigned long)ptr, bits);
}
#endif /* HASH_H */
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 2b91d16bf14f..ea93016b68d4 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -35,7 +35,7 @@ static struct expr *expr_lookup(enum expr_type type, void *l, void *r)
struct expr *e;
int hash;
- hash = hash_32((unsigned int)type ^ hash_ptr(l) ^ hash_ptr(r));
+ hash = hash_32((unsigned int)type ^ hash_ptr(l, 32) ^ hash_ptr(r, 32), 32);
hash_for_each_possible(expr_hashtable, e, node, hash) {
if (e->type == type && e->left._initdata == l &&
--
2.56.0