[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160830075834.GA494@swordfish>
Date: Tue, 30 Aug 2016 16:58:34 +0900
From: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
To: Petr Mladek <pmladek@...e.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Jan Kara <jack@...e.cz>, linux-kernel@...r.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Subject: Re: [PATCH] printk/nmi: avoid direct printk()-s from
__printk_nmi_flush()
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@...il.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
Powered by blists - more mailing lists