From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH] printk/nmi: avoid direct printk()-s from __printk_nmi_flush()
Date: Tue, 30 Aug 2016 16:58:34 +0900 [thread overview]
Message-ID: <20160830075834.GA494@swordfish> (raw)
In-Reply-To: <20160829151600.GM4866@pathway.suse.cz>
Petr,
one more question. Not related to the patch, but still related to NMI.
can NMI nest?
CPU0
-> NMI#0
printk_nmi_enter()
this_cpu_write(printk_func, vprintk_nmi)
...
=> NMI#1
: printk_nmi_enter()
: this_cpu_write(printk_func, vprintk_nmi)
: this_cpu_read(printk_func)(fmt, args)
: ^^^^^^^^^^^^^ OK, vprintk_nmi() from NMI
: printk_nmi_exit()
: this_cpu_write(printk_func, vprintk_default) <<
return NMI#1
this_cpu_read(printk_func)(fmt, args)
^^^^^^^^^^^^^ vprintk_default() from NMI?
printk_nmi_exit()
this_cpu_write(printk_func, vprintk_default)
return NMI#0
can this happen?
shouldn't we do something like this then? /* not tested */
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
kernel/printk/internal.h | 2 ++
kernel/printk/nmi.c | 9 ++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 7fd2838..5b7508f 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -31,6 +31,8 @@ extern raw_spinlock_t logbuf_lock;
* via per-CPU variable.
*/
DECLARE_PER_CPU(printk_func_t, printk_func);
+DECLARE_PER_CPU(printk_func_t, printk_func_saved);
+
static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
{
return this_cpu_read(printk_func)(fmt, args);
diff --git a/kernel/printk/nmi.c b/kernel/printk/nmi.c
index 16bab47..9d83929 100644
--- a/kernel/printk/nmi.c
+++ b/kernel/printk/nmi.c
@@ -39,6 +39,7 @@
* were handled or when IRQs are blocked.
*/
DEFINE_PER_CPU(printk_func_t, printk_func) = vprintk_default;
+DEFINE_PER_CPU(printk_func_t, printk_func_saved);
static int printk_nmi_irq_ready;
atomic_t nmi_message_lost;
@@ -259,10 +260,16 @@ void __init printk_nmi_init(void)
void printk_nmi_enter(void)
{
+ printk_func_t func = this_cpu_read(printk_func);
+
+ if (func != vprintk_nmi)
+ this_cpu_write(printk_func_saved, func);
this_cpu_write(printk_func, vprintk_nmi);
}
void printk_nmi_exit(void)
{
- this_cpu_write(printk_func, vprintk_default);
+ printk_func_t func = this_cpu_read(printk_func_saved);
+
+ this_cpu_write(printk_func, func);
}
--
2.9.3
next prev parent reply other threads:[~2016-08-30 7:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-29 12:32 [PATCH] printk/nmi: avoid direct printk()-s from __printk_nmi_flush() Sergey Senozhatsky
2016-08-29 15:16 ` Petr Mladek
2016-08-30 1:07 ` Sergey Senozhatsky
2016-08-30 7:58 ` Sergey Senozhatsky [this message]
2016-08-30 9:04 ` Petr Mladek
2016-08-30 9:39 ` Sergey Senozhatsky
2016-08-30 11:19 ` Petr Mladek
2016-08-31 4:00 ` Sergey Senozhatsky
2016-09-01 7:55 ` Sergey Senozhatsky
2016-09-01 8:17 ` Petr Mladek
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=20160830075834.GA494@swordfish \
--to=sergey.senozhatsky.work@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=sergey.senozhatsky@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