diff --git a/kernel/printk/printk_nobkl.c b/kernel/printk/printk_nobkl.c index 421c007003f7..cab8c35e598e 100644 --- a/kernel/printk/printk_nobkl.c +++ b/kernel/printk/printk_nobkl.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "printk_ringbuffer.h" #include "internal.h" /* @@ -1766,3 +1767,33 @@ void cons_nobkl_cleanup(struct console *con) cons_state_set(con, CON_STATE_REQ, &state); cons_free_percpu_data(con); } + +/** + * printk_kthread_shutdown - shutdown all threaded printers + * + * On system shutdown all threaded printers are stopped. This allows printk + * to transition back to atomic printing, thus providing a robust mechanism + * for the final shutdown/reboot messages to be output. + */ +static void printk_kthread_shutdown(void) +{ + struct console *con; + + console_list_lock(); + for_each_console(con) { + if (con->flags & CON_NO_BKL) + cons_kthread_stop(con); + } + console_list_unlock(); +} + +static struct syscore_ops printk_syscore_ops = { + .shutdown = printk_kthread_shutdown, +}; + +static int __init printk_init_ops(void) +{ + register_syscore_ops(&printk_syscore_ops); + return 0; +} +device_initcall(printk_init_ops);