All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-7.1-fixes 1/2] rhashtable: add no_sync_grow option
@ 2026-04-17  0:24 Tejun Heo
  2026-04-17  0:24 ` [PATCH for-7.1-fixes 2/2] sched_ext: mark scx_sched_hash and dsq_hash no_sync_grow Tejun Heo
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Tejun Heo @ 2026-04-17  0:24 UTC (permalink / raw)
  To: Herbert Xu, Thomas Graf, David Vernet, Andrea Righi, Changwoo Min
  Cc: Emil Tsalapatis, linux-crypto, sched-ext, linux-kernel

The sync grow path on insert calls get_random_u32() and kvmalloc(), both of
which take regular spinlocks and are unsafe under raw_spinlock_t. Add an
opt-in flag that skips the >100% grow check; inserts always succeed by
appending to the chain, and the deferred worker still grows at >75% load.

sched_ext already uses rhashtable under raw_spinlock_t and is technically
broken, though hard to hit in practice because the tables stay small.

Cc: stable@vger.kernel.org # prerequisite for the next sched_ext fix
Signed-off-by: Tejun Heo <tj@kernel.org>
---
Hello,

The follow-up sched_ext patch is a fix targeting sched_ext/for-7.1-fixes
which I'd like to send Linus's way sooner than later. Would it be okay
to route both patches through sched_ext/for-7.1-fixes? If you'd prefer
to route the rhashtable change differently, that works too. Please let
me know, thanks.

Based on linus/master (3cd8b194bf34).

 include/linux/rhashtable-types.h | 2 ++
 include/linux/rhashtable.h       | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/rhashtable-types.h b/include/linux/rhashtable-types.h
index 015c8298bebc..555eea6077f8 100644
--- a/include/linux/rhashtable-types.h
+++ b/include/linux/rhashtable-types.h
@@ -50,6 +50,7 @@ typedef int (*rht_obj_cmpfn_t)(struct rhashtable_compare_arg *arg,
  * @max_size: Maximum size while expanding
  * @min_size: Minimum size while shrinking
  * @automatic_shrinking: Enable automatic shrinking of tables
+ * @no_sync_grow: Skip sync grow on insert (allows inserts under raw_spinlock_t)
  * @hashfn: Hash function (default: jhash2 if !(key_len % 4), or jhash)
  * @obj_hashfn: Function to hash object
  * @obj_cmpfn: Function to compare key with object
@@ -62,6 +63,7 @@ struct rhashtable_params {
 	unsigned int		max_size;
 	u16			min_size;
 	bool			automatic_shrinking;
+	bool			no_sync_grow;
 	rht_hashfn_t		hashfn;
 	rht_obj_hashfn_t	obj_hashfn;
 	rht_obj_cmpfn_t		obj_cmpfn;
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 0480509a6339..a977a597d288 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -197,11 +197,14 @@ static inline bool rht_shrink_below_30(const struct rhashtable *ht,
  * rht_grow_above_100 - returns true if nelems > table-size
  * @ht:		hash table
  * @tbl:	current table
+ *
+ * Returns false if the caller opted out of synchronous grow.
  */
 static inline bool rht_grow_above_100(const struct rhashtable *ht,
 				      const struct bucket_table *tbl)
 {
-	return atomic_read(&ht->nelems) > tbl->size &&
+	return !ht->p.no_sync_grow &&
+		atomic_read(&ht->nelems) > tbl->size &&
 		(!ht->p.max_size || tbl->size < ht->p.max_size);
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-04-20 17:23 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17  0:24 [PATCH for-7.1-fixes 1/2] rhashtable: add no_sync_grow option Tejun Heo
2026-04-17  0:24 ` [PATCH for-7.1-fixes 2/2] sched_ext: mark scx_sched_hash and dsq_hash no_sync_grow Tejun Heo
2026-04-17  0:43 ` [PATCH for-7.1-fixes 1/2] rhashtable: add no_sync_grow option Herbert Xu
2026-04-17  0:53   ` Tejun Heo
2026-04-17  1:11     ` Herbert Xu
2026-04-17  7:38       ` Tejun Heo
2026-04-17  7:51         ` Herbert Xu
2026-04-17 16:25           ` Tejun Heo
2026-04-18  0:44             ` Herbert Xu
2026-04-18  0:52               ` Tejun Heo
2026-04-18  0:53                 ` Herbert Xu
2026-04-18  1:38                   ` [PATCH] rhashtable: Restore insecure_elasticity toggle Herbert Xu
2026-04-18  1:41                     ` [v2 PATCH] " Herbert Xu
2026-04-19 15:33                       ` [PATCH v2 sched_ext/for-7.1-fixes] sched_ext: Mark scx_sched_hash insecure_elasticity Tejun Heo
2026-04-19 15:34                         ` Tejun Heo
2026-04-20  1:46                     ` [PATCH] rhashtable: Restore insecure_elasticity toggle kernel test robot
2026-04-20  1:46                     ` kernel test robot
2026-04-20 17:22                     ` kernel test robot
2026-04-17  1:22 ` [PATCH for-7.1-fixes 1/2] rhashtable: add no_sync_grow option Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.