[tip:sched/urgent] sched/core: Schedule new worker even if PI-blocked

From: tip-bot for Sebastian Andrzej Siewior
Date: Mon Aug 19 2019 - 05:53:09 EST

Commit-ID: b0fdc01354f45d43f082025636ef808968a27b36
Gitweb: https://git.kernel.org/tip/b0fdc01354f45d43f082025636ef808968a27b36
Author: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
AuthorDate: Fri, 16 Aug 2019 18:06:26 +0200
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitDate: Mon, 19 Aug 2019 10:57:26 +0200

sched/core: Schedule new worker even if PI-blocked

If a task is PI-blocked (blocking on sleeping spinlock) then we don't want to
schedule a new kworker if we schedule out due to lock contention because !RT
does not do that as well. A spinning spinlock disables preemption and a worker
does not schedule out on lock contention (but spin).

On RT the RW-semaphore implementation uses an rtmutex so
tsk_is_pi_blocked() will return true if a task blocks on it. In this case we
will now start a new worker which may deadlock if one worker is waiting on
progress from another worker. Since a RW-semaphore starts a new worker on !RT,
we should do the same on RT.

XFS is able to trigger this deadlock.

Allow to schedule new worker if the current worker is PI-blocked.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/20190816160626.12742-1-bigeasy@xxxxxxxxxxxxx
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
kernel/sched/core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2b037f195473..010d578118d6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3904,7 +3904,7 @@ void __noreturn do_task_dead(void)

static inline void sched_submit_work(struct task_struct *tsk)
- if (!tsk->state || tsk_is_pi_blocked(tsk))
+ if (!tsk->state)

@@ -3920,6 +3920,9 @@ static inline void sched_submit_work(struct task_struct *tsk)

+ if (tsk_is_pi_blocked(tsk))
+ return;
* If we are going to sleep and we have plugged IO queued,
* make sure to submit it to avoid deadlocks.