]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
printk/panic: Allow cpu backtraces to be written into ringbuffer during panic
authorRyo Takakura <takakura@valinux.co.jp>
Mon, 12 Aug 2024 07:27:03 +0000 (16:27 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Aug 2024 15:35:53 +0000 (17:35 +0200)
[ Upstream commit bcc954c6caba01fca143162d5fbb90e46aa1ad80 ]

commit 779dbc2e78d7 ("printk: Avoid non-panic CPUs writing
to ringbuffer") disabled non-panic CPUs to further write messages to
ringbuffer after panicked.

Since the commit, non-panicked CPU's are not allowed to write to
ring buffer after panicked and CPU backtrace which is triggered
after panicked to sample non-panicked CPUs' backtrace no longer
serves its function as it has nothing to print.

Fix the issue by allowing non-panicked CPUs to write into ringbuffer
while CPU backtrace is in flight.

Fixes: 779dbc2e78d7 ("printk: Avoid non-panic CPUs writing to ringbuffer")
Signed-off-by: Ryo Takakura <takakura@valinux.co.jp>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20240812072703.339690-1-takakura@valinux.co.jp
Signed-off-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/panic.h
kernel/panic.c
kernel/printk/printk.c

index 6717b15e798c38904a19ef14bb7dd84fc2a01bb6..556b4e2ad9aa511ce8352244024d87a003ce9e81 100644 (file)
@@ -16,6 +16,7 @@ extern void oops_enter(void);
 extern void oops_exit(void);
 extern bool oops_may_print(void);
 
+extern bool panic_triggering_all_cpu_backtrace;
 extern int panic_timeout;
 extern unsigned long panic_print;
 extern int panic_on_oops;
index 8bff183d6180e752a0a7ba0ea9ed1617322fb02a..30342568e935f42d112454f73f315ba3523f36a5 100644 (file)
@@ -63,6 +63,8 @@ unsigned long panic_on_taint;
 bool panic_on_taint_nousertaint = false;
 static unsigned int warn_limit __read_mostly;
 
+bool panic_triggering_all_cpu_backtrace;
+
 int panic_timeout = CONFIG_PANIC_TIMEOUT;
 EXPORT_SYMBOL_GPL(panic_timeout);
 
@@ -252,8 +254,12 @@ void check_panic_on_warn(const char *origin)
  */
 static void panic_other_cpus_shutdown(bool crash_kexec)
 {
-       if (panic_print & PANIC_PRINT_ALL_CPU_BT)
+       if (panic_print & PANIC_PRINT_ALL_CPU_BT) {
+               /* Temporary allow non-panic CPUs to write their backtraces. */
+               panic_triggering_all_cpu_backtrace = true;
                trigger_all_cpu_backtrace();
+               panic_triggering_all_cpu_backtrace = false;
+       }
 
        /*
         * Note that smp_send_stop() is the usual SMP shutdown function,
index dddb15f48d59577b0754a7ab84818022a3d01f71..c5d844f727f6351722ec8d1c4a09bf331cf02af6 100644 (file)
@@ -2316,7 +2316,7 @@ asmlinkage int vprintk_emit(int facility, int level,
         * non-panic CPUs are generating any messages, they will be
         * silently dropped.
         */
-       if (other_cpu_in_panic())
+       if (other_cpu_in_panic() && !panic_triggering_all_cpu_backtrace)
                return 0;
 
        if (level == LOGLEVEL_SCHED) {