Skip to content

Commit

Permalink
Merge tag 'printk-for-6.15' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/git/printk/linux

Pull printk updates from Petr Mladek:

 - New option "printk.debug_non_panic_cpus" allows to store printk
   messages from non-panic CPUs during panic. It might be useful when
   panic() fails. It is disabled by default because it increases the
   chance to see the messages printed before panic() and on the
   panic-CPU.

 - New build option "CONFIG_NULL_TTY_DEFAULT_CONSOLE" allows to build
   kernel without the virtual terminal support which prefers ttynull
   over serial console.

 - Do not unblank suspended consoles.

 - Some code clean up.

* tag 'printk-for-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
  printk/panic: Add option to allow non-panic CPUs to write to the ring buffer.
  printk: Add an option to allow ttynull to be a default console device
  printk: Check CON_SUSPEND when unblanking a console
  printk: Rename console_start to console_resume
  printk: Rename console_stop to console_suspend
  printk: Rename resume_console to console_resume_all
  printk: Rename suspend_console to console_suspend_all
  • Loading branch information
Linus Torvalds committed Mar 28, 2025
2 parents a10c794 + f49040c commit 9605081
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 46 deletions.
8 changes: 8 additions & 0 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5020,6 +5020,14 @@
Format: <bool>
default: 0 (auto_verbose is enabled)

printk.debug_non_panic_cpus=
Allows storing messages from non-panic CPUs into
the printk log buffer during panic(). They are
flushed to consoles by the panic-CPU on
a best-effort basis.
Format: <bool> (1/Y/y=enable, 0/N/n=disable)
Default: disabled

printk.devkmsg={on,off,ratelimit}
Control writing to /dev/kmsg.
on - unlimited logging to /dev/kmsg from userspace
Expand Down
4 changes: 3 additions & 1 deletion Documentation/admin-guide/serial-console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ If no console device is specified, the first device found capable of
acting as a system console will be used. At this time, the system
first looks for a VGA card and then for a serial port. So if you don't
have a VGA card in your system the first serial port will automatically
become the console.
become the console, unless the kernel is configured with the
CONFIG_NULL_TTY_DEFAULT_CONSOLE option, then it will default to using the
ttynull device.

You will need to create a new device to use ``/dev/console``. The official
``/dev/console`` is now character device 5,1.
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/clients/drm_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static int drm_log_client_suspend(struct drm_client_dev *client, bool _console_l
{
struct drm_log *dlog = client_to_drm_log(client);

console_stop(&dlog->con);
console_suspend(&dlog->con);

return 0;
}
Expand All @@ -332,7 +332,7 @@ static int drm_log_client_resume(struct drm_client_dev *client, bool _console_lo
{
struct drm_log *dlog = client_to_drm_log(client);

console_start(&dlog->con);
console_resume(&dlog->con);

return 0;
}
Expand Down
19 changes: 18 additions & 1 deletion drivers/tty/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,24 @@ config NULL_TTY
available or desired.

In order to use this driver, you should redirect the console to this
TTY, or boot the kernel with console=ttynull.
TTY, boot the kernel with console=ttynull, or enable
NULL_TTY_DEFAULT_CONSOLE.

If unsure, say N.

config NULL_TTY_DEFAULT_CONSOLE
bool "Support for console on ttynull"
depends on NULL_TTY=y && !VT_CONSOLE
help
Say Y here if you want the NULL TTY to be used as a /dev/console
device by default.

For example, it might be useful to prevent a VT-less kernel from
writing the system log to a random device connected to the serial
port.

Another console driver still might get preferred via the command
line, SPCR, or the device tree.

If unsure, say N.

Expand Down
6 changes: 3 additions & 3 deletions drivers/tty/serial/serial_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2426,10 +2426,10 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
}

/*
* Disable the console device before suspending.
* Suspend the console device before suspending the port.
*/
if (uart_console(uport))
console_stop(uport->cons);
console_suspend(uport->cons);

uart_change_pm(state, UART_PM_STATE_OFF);

Expand Down Expand Up @@ -2484,7 +2484,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
uart_port_unlock_irq(uport);
}
if (console_suspend_enabled)
console_start(uport->cons);
console_resume(uport->cons);
}

if (tty_port_suspended(port)) {
Expand Down
8 changes: 4 additions & 4 deletions include/linux/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ extern void console_conditional_schedule(void);
extern void console_unblank(void);
extern void console_flush_on_panic(enum con_flush_mode mode);
extern struct tty_driver *console_device(int *);
extern void console_stop(struct console *);
extern void console_start(struct console *);
extern void console_suspend(struct console *);
extern void console_resume(struct console *);
extern int is_console_locked(void);
extern int braille_register_console(struct console *, int index,
char *console_options, char *braille_options);
Expand All @@ -648,8 +648,8 @@ static inline void console_sysfs_notify(void)
extern bool console_suspend_enabled;

/* Suspend and resume console messages over PM events */
extern void suspend_console(void);
extern void resume_console(void);
extern void console_suspend_all(void);
extern void console_resume_all(void);

int mda_console_init(void);

Expand Down
4 changes: 2 additions & 2 deletions kernel/kexec_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ int kernel_kexec(void)
error = -EBUSY;
goto Restore_console;
}
suspend_console();
console_suspend_all();
error = dpm_suspend_start(PMSG_FREEZE);
if (error)
goto Resume_console;
Expand Down Expand Up @@ -1072,7 +1072,7 @@ int kernel_kexec(void)
Resume_devices:
dpm_resume_end(PMSG_RESTORE);
Resume_console:
resume_console();
console_resume_all();
thaw_processes();
Restore_console:
pm_restore_console();
Expand Down
16 changes: 8 additions & 8 deletions kernel/power/hibernate.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int hibernation_snapshot(int platform_mode)
goto Thaw;
}

suspend_console();
console_suspend_all();
pm_restrict_gfp_mask();

error = dpm_suspend(PMSG_FREEZE);
Expand All @@ -437,7 +437,7 @@ int hibernation_snapshot(int platform_mode)
if (error || !in_suspend)
pm_restore_gfp_mask();

resume_console();
console_resume_all();
dpm_complete(msg);

Close:
Expand Down Expand Up @@ -547,7 +547,7 @@ int hibernation_restore(int platform_mode)
int error;

pm_prepare_console();
suspend_console();
console_suspend_all();
pm_restrict_gfp_mask();
error = dpm_suspend_start(PMSG_QUIESCE);
if (!error) {
Expand All @@ -561,7 +561,7 @@ int hibernation_restore(int platform_mode)
}
dpm_resume_end(PMSG_RECOVER);
pm_restore_gfp_mask();
resume_console();
console_resume_all();
pm_restore_console();
return error;
}
Expand All @@ -586,7 +586,7 @@ int hibernation_platform_enter(void)
goto Close;

entering_platform_hibernation = true;
suspend_console();
console_suspend_all();
error = dpm_suspend_start(PMSG_HIBERNATE);
if (error) {
if (hibernation_ops->recover)
Expand Down Expand Up @@ -639,7 +639,7 @@ int hibernation_platform_enter(void)
Resume_devices:
entering_platform_hibernation = false;
dpm_resume_end(PMSG_RESTORE);
resume_console();
console_resume_all();

Close:
hibernation_ops->end();
Expand Down Expand Up @@ -901,7 +901,7 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data)
if (error)
goto dpm_complete;

suspend_console();
console_suspend_all();

error = dpm_suspend(PMSG_FREEZE);
if (error)
Expand All @@ -925,7 +925,7 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data)
dpm_resume:
dpm_resume(PMSG_THAW);

resume_console();
console_resume_all();

dpm_complete:
dpm_complete(PMSG_THAW);
Expand Down
8 changes: 4 additions & 4 deletions kernel/power/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ int suspend_devices_and_enter(suspend_state_t state)
if (error)
goto Close;

suspend_console();
console_suspend_all();
suspend_test_start();
error = dpm_suspend_start(PMSG_SUSPEND);
if (error) {
Expand All @@ -527,9 +527,9 @@ int suspend_devices_and_enter(suspend_state_t state)
suspend_test_start();
dpm_resume_end(PMSG_RESUME);
suspend_test_finish("resume devices");
trace_suspend_resume(TPS("resume_console"), state, true);
resume_console();
trace_suspend_resume(TPS("resume_console"), state, false);
trace_suspend_resume(TPS("console_resume_all"), state, true);
console_resume_all();
trace_suspend_resume(TPS("console_resume_all"), state, false);

Close:
platform_resume_end(state);
Expand Down
1 change: 1 addition & 0 deletions kernel/printk/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct dev_printk_info;

extern struct printk_ringbuffer *prb;
extern bool printk_kthreads_running;
extern bool debug_non_panic_cpus;

__printf(4, 0)
int vprintk_store(int facility, int level,
Expand Down
55 changes: 44 additions & 11 deletions kernel/printk/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,22 @@ void printk_legacy_allow_panic_sync(void)
}
}

bool __read_mostly debug_non_panic_cpus;

#ifdef CONFIG_PRINTK_CALLER
static int __init debug_non_panic_cpus_setup(char *str)
{
debug_non_panic_cpus = true;
pr_info("allow messages from non-panic CPUs in panic()\n");

return 0;
}
early_param("debug_non_panic_cpus", debug_non_panic_cpus_setup);
module_param(debug_non_panic_cpus, bool, 0644);
MODULE_PARM_DESC(debug_non_panic_cpus,
"allow messages from non-panic CPUs in panic()");
#endif

asmlinkage int vprintk_emit(int facility, int level,
const struct dev_printk_info *dev_info,
const char *fmt, va_list args)
Expand All @@ -2391,7 +2407,9 @@ 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() && !panic_triggering_all_cpu_backtrace)
if (other_cpu_in_panic() &&
!debug_non_panic_cpus &&
!panic_triggering_all_cpu_backtrace)
return 0;

printk_get_console_flush_type(&ft);
Expand Down Expand Up @@ -2731,11 +2749,11 @@ module_param_named(console_no_auto_verbose, printk_console_no_auto_verbose, bool
MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to highest on oops/panic/etc");

/**
* suspend_console - suspend the console subsystem
* console_suspend_all - suspend the console subsystem
*
* This disables printk() while we go into suspend states
*/
void suspend_console(void)
void console_suspend_all(void)
{
struct console *con;

Expand All @@ -2758,7 +2776,7 @@ void suspend_console(void)
synchronize_srcu(&console_srcu);
}

void resume_console(void)
void console_resume_all(void)
{
struct console_flush_type ft;
struct console *con;
Expand Down Expand Up @@ -3340,7 +3358,12 @@ void console_unblank(void)
*/
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
if ((console_srcu_read_flags(c) & CON_ENABLED) && c->unblank) {
short flags = console_srcu_read_flags(c);

if (flags & CON_SUSPENDED)
continue;

if ((flags & CON_ENABLED) && c->unblank) {
found_unblank = true;
break;
}
Expand Down Expand Up @@ -3377,7 +3400,12 @@ void console_unblank(void)

cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
if ((console_srcu_read_flags(c) & CON_ENABLED) && c->unblank)
short flags = console_srcu_read_flags(c);

if (flags & CON_SUSPENDED)
continue;

if ((flags & CON_ENABLED) && c->unblank)
c->unblank();
}
console_srcu_read_unlock(cookie);
Expand Down Expand Up @@ -3495,10 +3523,10 @@ struct tty_driver *console_device(int *index)

/*
* Prevent further output on the passed console device so that (for example)
* serial drivers can disable console output before suspending a port, and can
* serial drivers can suspend console output before suspending a port, and can
* re-enable output afterwards.
*/
void console_stop(struct console *console)
void console_suspend(struct console *console)
{
__pr_flush(console, 1000, true);
console_list_lock();
Expand All @@ -3513,9 +3541,9 @@ void console_stop(struct console *console)
*/
synchronize_srcu(&console_srcu);
}
EXPORT_SYMBOL(console_stop);
EXPORT_SYMBOL(console_suspend);

void console_start(struct console *console)
void console_resume(struct console *console)
{
struct console_flush_type ft;
bool is_nbcon;
Expand All @@ -3540,7 +3568,7 @@ void console_start(struct console *console)

__pr_flush(console, 1000, true);
}
EXPORT_SYMBOL(console_start);
EXPORT_SYMBOL(console_resume);

#ifdef CONFIG_PRINTK
static int unregister_console_locked(struct console *console);
Expand Down Expand Up @@ -4275,6 +4303,11 @@ void __init console_init(void)
initcall_t call;
initcall_entry_t *ce;

#ifdef CONFIG_NULL_TTY_DEFAULT_CONSOLE
if (!console_set_on_cmdline)
add_preferred_console("ttynull", 0, NULL);
#endif

/* Setup the default TTY line discipline. */
n_tty_init();

Expand Down
13 changes: 8 additions & 5 deletions kernel/printk/printk_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2133,20 +2133,23 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq,
* there may be other finalized records beyond that
* need to be printed for a panic situation. If this
* is the panic CPU, skip this
* non-existent/non-finalized record unless it is
* at or beyond the head, in which case it is not
* possible to continue.
* non-existent/non-finalized record unless non-panic
* CPUs are still running and their debugging is
* explicitly enabled.
*
* Note that new messages printed on panic CPU are
* finalized when we are here. The only exception
* might be the last message without trailing newline.
* But it would have the sequence number returned
* by "prb_next_reserve_seq() - 1".
*/
if (this_cpu_in_panic() && ((*seq + 1) < prb_next_reserve_seq(rb)))
if (this_cpu_in_panic() &&
(!debug_non_panic_cpus || legacy_allow_panic_sync) &&
((*seq + 1) < prb_next_reserve_seq(rb))) {
(*seq)++;
else
} else {
return false;
}
}
}

Expand Down
Loading

0 comments on commit 9605081

Please sign in to comment.