[RFC][PATCHv5 07/13] printk: register syscore notifier

From: Sergey Senozhatsky
Date: Mon Aug 14 2017 - 23:00:32 EST


We need to switch to emergency printk mode in kernel_kexec(). One
kernel_kexec() branch calls kernel_restart_prepare(), which updates
`system_state', however, the other one, when user requested to
->preserve_context, does not and we are lacking the information
in printk about kexec being executed. Register a syscore notifier
so printk will be notified by syscore_suspend().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
---
kernel/printk/printk.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d3f149fad85c..b14e35f94596 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -50,6 +50,7 @@
#include <linux/sched/task_stack.h>
#include <linux/kthread.h>
#include <linux/suspend.h>
+#include <linux/syscore_ops.h>

#include <linux/uaccess.h>
#include <asm/sections.h>
@@ -2941,6 +2942,22 @@ static struct notifier_block printk_pm_nb = {
.notifier_call = printk_pm_notify,
};

+static int printk_syscore_suspend(void)
+{
+ printk_emergency_begin();
+ return 0;
+}
+
+static void printk_syscore_resume(void)
+{
+ printk_emergency_end();
+}
+
+static struct syscore_ops printk_syscore_ops = {
+ .suspend = printk_syscore_suspend,
+ .resume = printk_syscore_resume,
+};
+
static int printk_kthread_func(void *data)
{
while (1) {
@@ -2994,6 +3011,8 @@ static int __init init_printk_kthread(void)
return -EINVAL;
}

+ register_syscore_ops(&printk_syscore_ops);
+
thread = kthread_run(printk_kthread_func, NULL, "printk");
if (IS_ERR(thread)) {
pr_err("printk: unable to create printing thread\n");
--
2.14.1