Skip to content

Commit 28bc55f

Browse files
author
Peter Zijlstra
committed
sched: Constrain locks in sched_submit_work()
Even though sched_submit_work() is ran from preemptible context, it is discouraged to have it use blocking locks due to the recursion potential. Enforce this. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20230908162254.999499-2-bigeasy@linutronix.de
1 parent a432b7c commit 28bc55f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/sched/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6720,11 +6720,18 @@ void __noreturn do_task_dead(void)
67206720

67216721
static inline void sched_submit_work(struct task_struct *tsk)
67226722
{
6723+
static DEFINE_WAIT_OVERRIDE_MAP(sched_map, LD_WAIT_CONFIG);
67236724
unsigned int task_flags;
67246725

67256726
if (task_is_running(tsk))
67266727
return;
67276728

6729+
/*
6730+
* Establish LD_WAIT_CONFIG context to ensure none of the code called
6731+
* will use a blocking primitive -- which would lead to recursion.
6732+
*/
6733+
lock_map_acquire_try(&sched_map);
6734+
67286735
task_flags = tsk->flags;
67296736
/*
67306737
* If a worker goes to sleep, notify and ask workqueue whether it
@@ -6749,6 +6756,8 @@ static inline void sched_submit_work(struct task_struct *tsk)
67496756
* make sure to submit it to avoid deadlocks.
67506757
*/
67516758
blk_flush_plug(tsk->plug, true);
6759+
6760+
lock_map_release(&sched_map);
67526761
}
67536762

67546763
static void sched_update_worker(struct task_struct *tsk)

0 commit comments

Comments
 (0)