Only allow atomic safe consoles to print in atomic areas.
Subsystems (2)
PATCH 1/1 Only allow atomic safe consoles to print in atomic areas.
Since PREEMPT_RT makes spin_locks schedule, and some consoles (namely serial) use spin locks in the write method. This patch creates a new console flag called CON_ATOMIC which is set by safe consoles that do not grab spinlocks.
On PREEMPT_RT only safe consoles will write within non atomic operations (and not in a oops).
Signed-off-by Steven Rostedt
arch/x86_64/kernel/early_printk.c +3 -3
@@ -56,7 +56,7 @@ static void early_vga_write(struct consostatic struct console early_vga_console = { .name ="earlyvga" , .write = early_vga_write, - .flags =CON_PRINTBUFFER , + .flags =CON_PRINTBUFFER |CON_ATOMIC , .index =-1 , };
@@ -152,7 +152,7 @@ static __init void early_serial_init(chastatic struct console early_serial_console = { .name ="earlyser" , .write = early_serial_write, - .flags =CON_PRINTBUFFER , + .flags =CON_PRINTBUFFER |CON_ATOMIC , .index =-1 , };
@@ -193,7 +193,7 @@ static void simnow_write(struct consolestatic struct console simnow_console = { .name ="simnow" , .write = simnow_write, - .flags =CON_PRINTBUFFER , + .flags =CON_PRINTBUFFER |CON_ATOMIC , .index =-1 , };
drivers/char/vt.c +1 -1
@@ -2317,7 +2317,7 @@ static struct console vt_console_driver .write = vt_console_print, .device = vt_console_device, .unblank = unblank_screen, - .flags = CON_PRINTBUFFER, + .flags = CON_PRINTBUFFER | CON_ATOMIC, .index = -1, };#endif
include/linux/console.h +11 -0
@@ -92,6 +92,17 @@ void give_up_console(const struct consw#define CON_ENABLED (4)#define CON_BOOT (8)#define CON_ANYTIME (16)/* Safe to call when cpu is offline */ +#define CON_ATOMIC (32)/* Safe to call in PREEMPT_RT atomic */ + +#ifdef CONFIG_PREEMPT_RT +# define console_atomic_safe (con) \ + (((con)->flags & CON_ATOMIC) || \ + (!in_atomic() && !irqs_disabled()) || \ + (system_state != SYSTEM_RUNNING) || \ + oops_in_progress) +#else +# define console_atomic_safe (con) (1) +#endif struct console {
kernel/printk.c +1 -0
@@ -328,6 +328,7 @@ static void __call_console_drivers(unsigtouch_critical_timing ();for (con = console_drivers; con; con = con->next) {if ((con->flags &CON_ENABLED ) && con->write && +console_atomic_safe (con) && (cpu_online (raw_smp_processor_id ()) || (con->flags &CON_ANYTIME ))) {/*