]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
sched_ext: Add scx_task_iter_relock() and use it in scx_root_enable_workfn()
authorTejun Heo <tj@kernel.org>
Sun, 10 May 2026 22:21:58 +0000 (12:21 -1000)
committerTejun Heo <tj@kernel.org>
Sun, 10 May 2026 22:43:24 +0000 (12:43 -1000)
commitf25ad1e3cbaa4c87bb2b11496786f79db54c294f
tree5befa4d2b1285dc8acd8a9faeaaf62b2420701bb
parent03d958da4f355c380819a3baf339123c25db8e54
sched_ext: Add scx_task_iter_relock() and use it in scx_root_enable_workfn()

scx_root_enable_workfn()'s post-init block re-acquires scx_tasks_lock
briefly via a scoped_guard() for the tid hash insertion. c941d7391f25
("sched_ext: Close root-enable vs sched_ext_dead() race with
SCX_TASK_INIT_BEGIN") on for-7.1-fixes adds a post-init DEAD recheck that
holds the task's rq lock across the state-machine updates in the same
region. A naive merge would acquire scx_tasks_lock while the rq lock is
held, inverting the iter's outer/inner order (scx_tasks_lock then rq lock).

Add scx_task_iter_relock(iter, p), the counterpart to
scx_task_iter_unlock(), that re-acquires scx_tasks_lock and, if @p is
non-NULL, @p's rq lock. The locks are tracked in @iter so subsequent
iteration releases them.

Use it in scx_root_enable_workfn()'s post-init block and drop the
now-redundant scoped_guard on the hash insertion. The post-init region now
runs with both scx_tasks_lock and the task's rq lock held across the init
failure check, the state-machine updates and the hash insert.

v2: Move scx_task_iter_relock() earlier to ease the for-7.1-fixes merge.

Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext.c