]> git.ipfire.org Git - thirdparty/linux.git/commit
rhashtable: Fix potential deadlock by moving schedule_work outside lock
authorBreno Leitao <leitao@debian.org>
Thu, 28 Nov 2024 12:16:25 +0000 (04:16 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 21 Dec 2024 09:05:29 +0000 (17:05 +0800)
commite1d3422c95f003eba241c176adfe593c33e8a8f6
treedf395caabbf4a58b29545a635c1b8ef1806ec797
parentf916e44487f56df4827069ff3a2070c0746dc511
rhashtable: Fix potential deadlock by moving schedule_work outside lock

Move the hash table growth check and work scheduling outside the
rht lock to prevent a possible circular locking dependency.

The original implementation could trigger a lockdep warning due to
a potential deadlock scenario involving nested locks between
rhashtable bucket, rq lock, and dsq lock. By relocating the
growth check and work scheduling after releasing the rth lock, we break
this potential deadlock chain.

This change expands the flexibility of rhashtable by removing
restrictive locking that previously limited its use in scheduler
and workqueue contexts.

Import to say that this calls rht_grow_above_75(), which reads from
struct rhashtable without holding the lock, if this is a problem, we can
move the check to the lock, and schedule the workqueue after the lock.

Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Modified so that atomic_inc is also moved outside of the bucket
lock along with the growth above 75% check.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
lib/rhashtable.c