Skip to content

Commit

Permalink
sched: Constrain locks in sched_submit_work()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Peter Zijlstra committed Sep 20, 2023
1 parent a432b7c commit 28bc55f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6720,11 +6720,18 @@ void __noreturn do_task_dead(void)

static inline void sched_submit_work(struct task_struct *tsk)
{
static DEFINE_WAIT_OVERRIDE_MAP(sched_map, LD_WAIT_CONFIG);
unsigned int task_flags;

if (task_is_running(tsk))
return;

/*
* Establish LD_WAIT_CONFIG context to ensure none of the code called
* will use a blocking primitive -- which would lead to recursion.
*/
lock_map_acquire_try(&sched_map);

task_flags = tsk->flags;
/*
* If a worker goes to sleep, notify and ask workqueue whether it
Expand All @@ -6749,6 +6756,8 @@ static inline void sched_submit_work(struct task_struct *tsk)
* make sure to submit it to avoid deadlocks.
*/
blk_flush_plug(tsk->plug, true);

lock_map_release(&sched_map);
}

static void sched_update_worker(struct task_struct *tsk)
Expand Down

0 comments on commit 28bc55f

Please sign in to comment.