Re: [PATCH v3] rhashtable: Bounce deferred worker kick through irq_work
From: Herbert Xu
Date: Tue Apr 21 2026 - 02:09:17 EST
On Mon, Apr 20, 2026 at 08:03:26PM -1000, Tejun Heo wrote:
> Inserts past 75% load call schedule_work(&ht->run_work) to kick an
> async resize. If a caller holds a raw spinlock (e.g. an
> insecure_elasticity user), schedule_work() under that lock records
>
> caller_lock -> pool->lock -> pi_lock -> rq->__lock
>
> A cycle forms if any of these locks is acquired in the reverse
> direction elsewhere. sched_ext, the only current insecure_elasticity
> user, hits this: it holds scx_sched_lock across rhashtable inserts of
> sub-schedulers, while scx_bypass() takes rq->__lock -> scx_sched_lock.
> Exercising the resize path produces:
>
> Chain exists of:
> &pool->lock --> &rq->__lock --> scx_sched_lock
>
> Bounce the kick from the insert paths through irq_work so
> schedule_work() runs from hard IRQ context with the caller's lock no
> longer held. rht_deferred_worker()'s self-rearm on error stays on
> schedule_work(&ht->run_work) - the worker runs in process context with
> no caller lock held, and keeping the self-requeue on @run_work lets
> cancel_work_sync() in rhashtable_free_and_destroy() drain it.
>
> v3: Keep rht_deferred_worker()'s self-rearm on schedule_work(&run_work).
> Routing it through irq_work in v2 broke cancel_work_sync()'s
> self-requeue handling - an irq_work queued after irq_work_sync()
> returned but while cancel_work_sync() was still waiting could fire
> post-teardown.
>
> v2: Bounce unconditionally instead of gating on insecure_elasticity,
> as suggested by Herbert.
>
> Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
> ---
> Herbert, dropped your Ack on v2. v2 routed rht_deferred_worker()'s
> self-rearm through irq_work, which would race with
> cancel_work_sync() in rhashtable_free_and_destroy(). v3 keeps only
> the insert-path kicks on irq_work; the worker's self-rearm stays on
> schedule_work(&ht->run_work).
>
> include/linux/rhashtable-types.h | 3 +++
> include/linux/rhashtable.h | 3 ++-
> lib/rhashtable.c | 31 ++++++++++++++++++++++++++++---
> 3 files changed, 33 insertions(+), 4 deletions(-)
Acked-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt