From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Petr Mladek <pmladek@suse.com>, Steven Rostedt <rostedt@goodmis.org>
Cc: Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
"Rafael J . Wysocki" <rjw@rjwysocki.net>,
Eric Biederman <ebiederm@xmission.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>, Pavel Machek <pavel@ucw.cz>,
Andreas Mohr <andi@lisas.de>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: [RFC][PATCHv4 5/7] printk: register PM notifier
Date: Fri, 2 Jun 2017 18:03:43 +0900 [thread overview]
Message-ID: <20170602090345.624-6-sergey.senozhatsky@gmail.com> (raw)
In-Reply-To: <20170602090345.624-1-sergey.senozhatsky@gmail.com>
It's not always possible/safe to wake_up() printk kernel
thread. For example, late suspend/early resume may printk()
while timekeeping is not initialized yet, so calling into the
scheduler may result in recursive warnings.
Another thing to notice is the fact PM at some point
freezes user space and kernel threads: freeze_processes()
and freeze_kernel_threads(), correspondingly. Thus we need
printk() to operate in emergency mode there and attempt to
immediately flush pending kernel message to the console.
This patch registers PM notifier, so PM can switch printk
to emergency mode from PM_FOO_PREPARE notifiers and return
back to printk threaded mode from PM_POST_FOO notifiers.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Suggested-by: Andreas Mohr <andi@lisas.de>
---
kernel/printk/printk.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ed0df3d21215..5b2b97ee3440 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/smpboot.h>
+#include <linux/suspend.h>
#include <linux/uaccess.h>
#include <asm/sections.h>
@@ -2942,6 +2943,33 @@ static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = {
.flags = IRQ_WORK_LAZY,
};
+static int printk_pm_notify(struct notifier_block *notify_block,
+ unsigned long mode, void *unused)
+{
+ switch (mode) {
+ case PM_HIBERNATION_PREPARE:
+ case PM_SUSPEND_PREPARE:
+ case PM_RESTORE_PREPARE:
+ printk_emergency_begin();
+ break;
+
+ case PM_POST_SUSPEND:
+ case PM_POST_HIBERNATION:
+ case PM_POST_RESTORE:
+ printk_emergency_end();
+ break;
+
+ default:
+ return NOTIFY_DONE;
+ }
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block printk_pm_nb = {
+ .notifier_call = printk_pm_notify,
+};
+
static void printk_kthread_func(unsigned int cpu)
{
while (1) {
@@ -2992,6 +3020,13 @@ static int __init init_printk_kthreads(void)
return -EINVAL;
}
+ if (register_pm_notifier(&printk_pm_nb) != 0) {
+ printk_enforce_emergency = true;
+ smpboot_unregister_percpu_thread(&printk_kthreads);
+ pr_err("printk: unable to register PM notifier\n");
+ return -EINVAL;
+ }
+
return 0;
}
late_initcall(init_printk_kthreads);
--
2.13.0
next prev parent reply other threads:[~2017-06-02 9:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-02 9:03 [RFC][PATCHv4 0/7] printk: introduce printing kernel threads Sergey Senozhatsky
2017-06-02 9:03 ` [RFC][PATCHv4 1/7] printk: move printk_pending out of per-cpu Sergey Senozhatsky
2017-06-02 9:03 ` [RFC][PATCHv4 2/7] printk: introduce printing kernel SMP threads Sergey Senozhatsky
2017-06-02 9:03 ` [RFC][PATCHv4 3/7] printk: add enforce_emergency parameter Sergey Senozhatsky
2017-06-02 9:03 ` [RFC][PATCHv4 4/7] printk: enable printk offloading Sergey Senozhatsky
2017-06-02 9:03 ` Sergey Senozhatsky [this message]
2017-06-02 9:03 ` [RFC][PATCHv4 6/7] printk: register syscore notifier Sergey Senozhatsky
2017-06-02 9:03 ` [RFC][PATCHv4 7/7] printk: add printk cpumask sysctl Sergey Senozhatsky
2017-06-08 8:18 ` [RFC][PATCHv4 0/7] printk: introduce printing kernel threads Sergey Senozhatsky
2017-06-28 13:42 ` Petr Mladek
2017-06-29 7:56 ` Sergey Senozhatsky
2017-06-30 12:11 ` Petr Mladek
2017-06-30 12:45 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170602090345.624-6-sergey.senozhatsky@gmail.com \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andi@lisas.de \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=jack@suse.cz \
--cc=jslaby@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rjw@rjwysocki.net \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®