printk: nobkl: Stop threads on shutdown/reboot

Register a syscore_ops shutdown function to stop all threaded
printers on shutdown/reboot. This allows printk to transition back
to atomic printing in order to provide a robust mechanism for
outputting the final messages.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
This commit is contained in:
John Ogness
2023-02-27 17:59:01 +01:00
committed by Sebastian Andrzej Siewior
parent ab8a7d8f04
commit cf3b42a10d
+31
View File
@@ -7,6 +7,7 @@
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/slab.h>
#include <linux/syscore_ops.h>
#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);