Skip to content

Commit c1aa3da

Browse files
DonghyeokChoepmladek
authored andcommitted
printk/panic: Add option to allow non-panic CPUs to write to the ring buffer.
Commit 779dbc2 ("printk: Avoid non-panic CPUs writing to ringbuffer") aimed to isolate panic-related messages. However, when panic() itself malfunctions, messages from non-panic CPUs become crucial for debugging. While commit bcc954c ("printk/panic: Allow cpu backtraces to be written into ringbuffer during panic") enables non-panic CPU backtraces, it may not provide sufficient diagnostic information. Introduce the "debug_non_panic_cpus" command-line option, enabling non-panic CPU messages to be stored in the ring buffer during a panic. This also prevents discarding non-finalized messages from non-panic CPUs during console flushing, providing a more comprehensive view of system state during critical failures. Link: https://lore.kernel.org/all/Z8cLEkqLL2IOyNIj@pathway/ Signed-off-by: Donghyeok Choe <d7271.choe@samsung.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20250318022320.2428155-1-d7271.choe@samsung.com [pmladek@suse.com: Added documentation, added module_parameter, removed printk_ prefix.] Tested-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent 2f1f778 commit c1aa3da

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,14 @@
50135013
Format: <bool>
50145014
default: 0 (auto_verbose is enabled)
50155015

5016+
printk.debug_non_panic_cpus=
5017+
Allows storing messages from non-panic CPUs into
5018+
the printk log buffer during panic(). They are
5019+
flushed to consoles by the panic-CPU on
5020+
a best-effort basis.
5021+
Format: <bool> (1/Y/y=enable, 0/N/n=disable)
5022+
Default: disabled
5023+
50165024
printk.devkmsg={on,off,ratelimit}
50175025
Control writing to /dev/kmsg.
50185026
on - unlimited logging to /dev/kmsg from userspace

kernel/printk/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct dev_printk_info;
6464

6565
extern struct printk_ringbuffer *prb;
6666
extern bool printk_kthreads_running;
67+
extern bool debug_non_panic_cpus;
6768

6869
__printf(4, 0)
6970
int vprintk_store(int facility, int level,

kernel/printk/printk.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,22 @@ void printk_legacy_allow_panic_sync(void)
23752375
}
23762376
}
23772377

2378+
bool __read_mostly debug_non_panic_cpus;
2379+
2380+
#ifdef CONFIG_PRINTK_CALLER
2381+
static int __init debug_non_panic_cpus_setup(char *str)
2382+
{
2383+
debug_non_panic_cpus = true;
2384+
pr_info("allow messages from non-panic CPUs in panic()\n");
2385+
2386+
return 0;
2387+
}
2388+
early_param("debug_non_panic_cpus", debug_non_panic_cpus_setup);
2389+
module_param(debug_non_panic_cpus, bool, 0644);
2390+
MODULE_PARM_DESC(debug_non_panic_cpus,
2391+
"allow messages from non-panic CPUs in panic()");
2392+
#endif
2393+
23782394
asmlinkage int vprintk_emit(int facility, int level,
23792395
const struct dev_printk_info *dev_info,
23802396
const char *fmt, va_list args)
@@ -2391,7 +2407,9 @@ asmlinkage int vprintk_emit(int facility, int level,
23912407
* non-panic CPUs are generating any messages, they will be
23922408
* silently dropped.
23932409
*/
2394-
if (other_cpu_in_panic() && !panic_triggering_all_cpu_backtrace)
2410+
if (other_cpu_in_panic() &&
2411+
!debug_non_panic_cpus &&
2412+
!panic_triggering_all_cpu_backtrace)
23952413
return 0;
23962414

23972415
printk_get_console_flush_type(&ft);

kernel/printk/printk_ringbuffer.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,20 +2133,23 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq,
21332133
* there may be other finalized records beyond that
21342134
* need to be printed for a panic situation. If this
21352135
* is the panic CPU, skip this
2136-
* non-existent/non-finalized record unless it is
2137-
* at or beyond the head, in which case it is not
2138-
* possible to continue.
2136+
* non-existent/non-finalized record unless non-panic
2137+
* CPUs are still running and their debugging is
2138+
* explicitly enabled.
21392139
*
21402140
* Note that new messages printed on panic CPU are
21412141
* finalized when we are here. The only exception
21422142
* might be the last message without trailing newline.
21432143
* But it would have the sequence number returned
21442144
* by "prb_next_reserve_seq() - 1".
21452145
*/
2146-
if (this_cpu_in_panic() && ((*seq + 1) < prb_next_reserve_seq(rb)))
2146+
if (this_cpu_in_panic() &&
2147+
(!debug_non_panic_cpus || legacy_allow_panic_sync) &&
2148+
((*seq + 1) < prb_next_reserve_seq(rb))) {
21472149
(*seq)++;
2148-
else
2150+
} else {
21492151
return false;
2152+
}
21502153
}
21512154
}
21522155

0 commit comments

Comments
 (0)