All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: Use printk_deferred_once() instead of WARN_ONCE()
@ 2024-12-27  9:27 Maria Yu
  2025-01-13 13:12 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Maria Yu @ 2024-12-27  9:27 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: Ingo Molnar, linux-kernel, kernel, Maria Yu

A deadlock is observed when WARN_ONCE() uses printk() inside the scheduler
logic. printk_deferred_once() is a WARN_ONCE() similar special printk
facility for the scheduler to avoid unnecessary deadlocks.

One of the deadlock stacks looks like this:
queued_spin_lock_slowpath() --
//waiting on uart_port_lock which is already hold by current cpu
queued_spin_lock(inline)
do_raw_spin_lock(inline)
__raw_spin_lock_irqsave(inline)
_raw_spin_lock_irqsave()
qcom_geni_serial_console_write()
call_console_driver(inline)
console_emit_next_record()
console_flush_all(inline)
console_unlock()
vprintk_emit()
vprintk_default()
vprintk()
_printk()
__warn_printk()
rq_pin_lock(inline)
rq_lock_irqsave(inline)
.
wake_up_process(inline)
wake_up_worker(inline)
insert_work(inline)
__queue_work()
queue_work_on()
queue_work(inline)
tty_flip_buffer_push()
handle_rx_console()
qcom_geni_serial_handle_rx(inline)
qcom_geni_serial_isr() --
//acquired uart_port_lock
__handle_irq_event_percpu()
handle_irq_event_percpu(inline)
handle_irq_event()
.

After the change, the SCHED_WARN_ON(x) printout appears as follows:
[    x.xxxxxx] WARNING: ------------[ cut here ]------------
[    x.xxxxxx] WARNING: x

Fixes: 9148a3a10e0b ("sched/debug: Add SCHED_WARN_ON()")
Signed-off-by: Maria Yu <quic_aiquny@quicinc.com>
---
 kernel/sched/sched.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index aef716c41edba8a6ec7d88db121fe0a9934b5264..863004630ad793c21272566f186d2fbee7fcc95b 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -92,7 +92,16 @@ struct cpuidle_state;
 #include "cpudeadline.h"
 
 #ifdef CONFIG_SCHED_DEBUG
-# define SCHED_WARN_ON(x)      WARN_ONCE(x, #x)
+# define deferred_warn_on(fmt, ...) \
+	printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
+# define SCHED_WARN_ON(x) ({\
+	int __ret_warn_on = !!(x); \
+	if (unlikely(__ret_warn_on)) { \
+		deferred_warn_on(CUT_HERE); \
+		deferred_warn_on(#x); \
+	} \
+	unlikely(__ret_warn_on); \
+})
 #else
 # define SCHED_WARN_ON(x)      ({ (void)(x), 0; })
 #endif

---
base-commit: af98d8a36a963e758e84266d152b92c7b51d4ecb
change-id: 20241226-sched-use-printk_deferred_once-2275b3a2575e

Best regards,
-- 
Maria Yu <quic_aiquny@quicinc.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-14 10:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-27  9:27 [PATCH] sched: Use printk_deferred_once() instead of WARN_ONCE() Maria Yu
2025-01-13 13:12 ` Peter Zijlstra
2025-01-13 13:16   ` Peter Zijlstra
2025-01-14 10:01     ` Aiqun(Maria) Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.