From: Petr Mladek Date: Fri, 26 Sep 2025 12:49:11 +0000 (+0200) Subject: printk/nbcon/panic: Allow printk kthread to sleep when the system is in panic X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c3ba0d5925685d27490078bf2d54ff9c0a0e67b;p=thirdparty%2Flinux.git printk/nbcon/panic: Allow printk kthread to sleep when the system is in panic The printk kthread might be running when there is a panic in progress. But it is not able to acquire the console ownership any longer. Prevent the desperate attempts to acquire the ownership and allow sleeping in panic. It would make it behave the same as when there is any CPU in an emergency context. Reviewed-by: Andrew Murray Reviewed-by: John Ogness Link: https://patch.msgid.link/20250926124912.243464-3-pmladek@suse.com [pmladek@suse.com: Rebased on top of 6.18-rc1 (panic_in_progress() moved to panic.c)] Signed-off-by: Petr Mladek --- diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index dda336ffabdd..2fd2f906e134 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1173,7 +1173,8 @@ static bool nbcon_kthread_should_wakeup(struct console *con, struct nbcon_contex * where the context with a higher priority takes over the nbcon console * ownership in the middle of a message. */ - if (unlikely(atomic_read(&nbcon_cpu_emergency_cnt))) + if (unlikely(atomic_read(&nbcon_cpu_emergency_cnt)) || + unlikely(panic_in_progress())) return false; cookie = console_srcu_read_lock(); @@ -1231,7 +1232,8 @@ wait_for_event: * Block the kthread when the system is in an emergency or panic * mode. See nbcon_kthread_should_wakeup() for more details. */ - if (unlikely(atomic_read(&nbcon_cpu_emergency_cnt))) + if (unlikely(atomic_read(&nbcon_cpu_emergency_cnt)) || + unlikely(panic_in_progress())) goto wait_for_event; backlog = false;