Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754871AbcCBKme (ORCPT ); Wed, 2 Mar 2016 05:42:34 -0500 Received: from mail7.hitachi.co.jp ([133.145.228.42]:51182 "EHLO mail7.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753332AbcCBKm1 (ORCPT ); Wed, 2 Mar 2016 05:42:27 -0500 X-AuditID: 85900ec0-9ebcbb9000001a57-e0-56d6c2e84d06 X-Mailbox-Line: From nobody Wed Mar 2 19:36:29 2016 Subject: [v2 PATCH 1/3] panic: Change nmi_panic from macro to function To: Andrew Morton , Thomas Mingarelli , Wim Van Sebroeck , Corey Minyard From: Hidehiro Kawai Cc: Javi Merino , Michal Hocko , linux-watchdog@vger.kernel.org, "Steven Rostedt \(Red Hat\)" , Rasmus Villemoes , linux-kernel@vger.kernel.org, Michal Nazarewicz , Michal Hocko , Vitaly Kuznetsov , HATAYAMA Daisuke , Borislav Petkov , Gobinda Charan Maji , Tejun Heo , Nicolas Iooss , openipmi-developer@lists.sourceforge.net, Borislav Petkov , Thomas Gleixner , Guenter Roeck Date: Wed, 02 Mar 2016 19:36:26 +0900 Message-ID: <20160302103626.5058.74361.stgit@softrs> In-Reply-To: <20160302103624.5058.35844.stgit@softrs> References: <20160302103624.5058.35844.stgit@softrs> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3308 Lines: 100 Change nmi_panic() macro to a normal function for the portability. Also, export it for modules. Signed-off-by: Hidehiro Kawai Cc: Andrew Morton Cc: Borislav Petkov Cc: Michal Nazarewicz Cc: Michal Hocko Cc: Rasmus Villemoes Cc: Nicolas Iooss Cc: Javi Merino Cc: Gobinda Charan Maji Cc: "Steven Rostedt (Red Hat)" Cc: Thomas Gleixner Cc: Vitaly Kuznetsov Cc: HATAYAMA Daisuke Cc: Tejun Heo --- include/linux/kernel.h | 22 ++-------------------- kernel/panic.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index f31638c..daf233f 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -255,7 +255,8 @@ extern long (*panic_blink)(int state); __printf(1, 2) void panic(const char *fmt, ...) __noreturn __cold; -void nmi_panic_self_stop(struct pt_regs *); +__printf(2, 3) +void nmi_panic(struct pt_regs *regs, const char *fmt, ...); extern void oops_enter(void); extern void oops_exit(void); void print_oops_end_marker(void); @@ -455,25 +456,6 @@ extern atomic_t panic_cpu; #define PANIC_CPU_INVALID -1 /* - * A variant of panic() called from NMI context. We return if we've already - * panicked on this CPU. If another CPU already panicked, loop in - * nmi_panic_self_stop() which can provide architecture dependent code such - * as saving register state for crash dump. - */ -#define nmi_panic(regs, fmt, ...) \ -do { \ - int old_cpu, cpu; \ - \ - cpu = raw_smp_processor_id(); \ - old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu); \ - \ - if (old_cpu == PANIC_CPU_INVALID) \ - panic(fmt, ##__VA_ARGS__); \ - else if (old_cpu != cpu) \ - nmi_panic_self_stop(regs); \ -} while (0) - -/* * Only to be used by arch init code. If the user over-wrote the default * CONFIG_PANIC_TIMEOUT, honor it. */ diff --git a/kernel/panic.c b/kernel/panic.c index d96469d..fb61e54 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -72,6 +72,32 @@ void __weak nmi_panic_self_stop(struct pt_regs *regs) atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); +/* + * A variant of panic() called from NMI context. We return if we've already + * panicked on this CPU. If another CPU already panicked, loop in + * nmi_panic_self_stop() which can provide architecture dependent code such + * as saving register state for crash dump. + */ +void nmi_panic(struct pt_regs *regs, const char *fmt, ...) +{ + static char buf[1024]; /* protected by panic_cpu */ + va_list args; + int old_cpu, cpu; + + cpu = raw_smp_processor_id(); + old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu); + + if (old_cpu == PANIC_CPU_INVALID) { + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + panic("%s", buf); + } else if (old_cpu != cpu) + nmi_panic_self_stop(regs); +} +EXPORT_SYMBOL(nmi_panic); + /** * panic - halt the system * @fmt: The text string to print