2022-02-09 23:26:27

by Stephen Brennan

[permalink] [raw]
Subject: [PATCH 1/1] sched: Use printk_deferred during __schedule()

When the rq lock is held and a printk occurs, some console drivers may
trigger a deadlock by calling into scheduler functions (e.g. scheduling
work). Though printk() is avoided in these contexts, there are some WARN
or WARN_ONCE statements which can trigger deadlocks during context
switch operations. These warnings should not trigger deadlocks. Use the
printk_deferred helper to ensure console drivers aren't called until
after the critical section is over.

Signed-off-by: Stephen Brennan <[email protected]>
---
kernel/sched/core.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 848eaa0efe0e..bc8afc3020a4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4861,6 +4861,7 @@ static struct rq *finish_task_switch(struct task_struct *prev)
perf_event_task_sched_in(prev, current);
finish_task(prev);
tick_nohz_task_switch();
+ printk_deferred_exit();
finish_lock_switch(rq);
finish_arch_post_lock_switch();
kcov_finish_switch(current);
@@ -6208,6 +6209,7 @@ static void __sched notrace __schedule(unsigned int sched_mode)
*/
rq_lock(rq, &rf);
smp_mb__after_spinlock();
+ printk_deferred_enter();

/* Promote REQ to ACT */
rq->clock_update_flags <<= 1;
@@ -6298,6 +6300,7 @@ static void __sched notrace __schedule(unsigned int sched_mode)

rq_unpin_lock(rq, &rf);
__balance_callbacks(rq);
+ printk_deferred_exit();
raw_spin_rq_unlock_irq(rq);
}
}
--
2.30.2