[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250926124912.243464-3-pmladek@suse.com>
Date: Fri, 26 Sep 2025 14:49:11 +0200
From: Petr Mladek <pmladek@...e.com>
To: John Ogness <john.ogness@...utronix.de>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jirislaby@...nel.org>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Steven Rostedt <rostedt@...dmis.org>,
Thomas Gleixner <tglx@...utronix.de>,
Esben Haabendal <esben@...nix.com>,
linux-serial@...r.kernel.org,
linux-kernel@...r.kernel.org,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Arnd Bergmann <arnd@...db.de>,
Tony Lindgren <tony@...mide.com>,
Niklas Schnelle <schnelle@...ux.ibm.com>,
Serge Semin <fancer.lancer@...il.com>,
Andrew Murray <amurray@...goodpenguin.co.uk>,
Petr Mladek <pmladek@...e.com>
Subject: [PATCH 2/3] 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.
Signed-off-by: Petr Mladek <pmladek@...e.com>
---
kernel/printk/internal.h | 1 +
kernel/printk/nbcon.c | 6 ++++--
kernel/printk/printk.c | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index ef282001f200..6e8578102fb3 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -332,6 +332,7 @@ struct printk_message {
unsigned long dropped;
};
+bool panic_in_progress(void);
bool other_cpu_in_panic(void);
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
bool is_extended, bool may_supress);
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 08b196e898cd..219ae0c8b5ed 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1178,7 +1178,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();
@@ -1236,7 +1237,8 @@ static int nbcon_kthread_func(void *__console)
* 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;
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ebf10352736f..174d42041594 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -345,7 +345,7 @@ static void __up_console_sem(unsigned long ip)
}
#define up_console_sem() __up_console_sem(_RET_IP_)
-static bool panic_in_progress(void)
+bool panic_in_progress(void)
{
return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
}
--
2.51.0
Powered by blists - more mailing lists