[PATCH 4/4] printk: Drop console_sem during panic

From: Stephen Brennan
Date: Fri Jan 21 2022 - 14:03:10 EST


If another CPU is in panic, we are about to be halted. Try to gracefully
drop console_sem and allow the panic CPU to grab it easily.

Suggested-by: Petr Mladek <pmladek@xxxxxxxx>
Signed-off-by: Stephen Brennan <stephen.s.brennan@xxxxxxxxxx>
---
kernel/printk/printk.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ca253ac07615..c2dc8ebd9509 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2668,7 +2668,7 @@ void console_unlock(void)

for (;;) {
size_t ext_len = 0;
- int handover;
+ int handover, pcpu;
size_t len;

skip:
@@ -2739,6 +2739,12 @@ void console_unlock(void)
if (handover)
return;

+ /* Allow panic_cpu to take over the consoles safely */
+ pcpu = atomic_read(&panic_cpu);
+ if (unlikely(pcpu != PANIC_CPU_INVALID &&
+ pcpu != raw_smp_processor_id()))
+ break;
+
if (do_cond_resched)
cond_resched();
}
--
2.30.2