Skip to content

Commit ebc41f2

Browse files
h-kawai-eztorvalds
authored andcommitted
panic: change nmi_panic from macro to function
Commit 1717f20 ("panic, x86: Fix re-entrance problem due to panic on NMI") and commit 58c5661 ("panic, x86: Allow CPUs to save registers even if looping in NMI context") introduced nmi_panic() which prevents concurrent/recursive execution of panic(). It also saves registers for the crash dump on x86. However, there are some cases where NMI handlers still use panic(). This patch set partially replaces them with nmi_panic() in those cases. Even this patchset is applied, some NMI or similar handlers (e.g. MCE handler) continue to use panic(). This is because I can't test them well and actual problems won't happen. For example, the possibility that normal panic and panic on MCE happen simultaneously is very low. This patch (of 3): Convert nmi_panic() to a proper function and export it instead of exporting internal implementation details to modules, for obvious reasons. Signed-off-by: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com> Acked-by: Borislav Petkov <bp@suse.de> Acked-by: Michal Nazarewicz <mina86@mina86.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Nicolas Iooss <nicolas.iooss_linux@m4x.org> Cc: Javi Merino <javi.merino@arm.com> Cc: Gobinda Charan Maji <gobinda.cemk07@gmail.com> Cc: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vitaly Kuznetsov <vkuznets@redhat.com> Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a484c3d commit ebc41f2

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

‎include/linux/kernel.h‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ extern long (*panic_blink)(int state);
255255
__printf(1, 2)
256256
void panic(const char *fmt, ...)
257257
__noreturn __cold;
258-
void nmi_panic_self_stop(struct pt_regs *);
258+
void nmi_panic(struct pt_regs *regs, const char *msg);
259259
extern void oops_enter(void);
260260
extern void oops_exit(void);
261261
void print_oops_end_marker(void);
@@ -456,25 +456,6 @@ extern bool crash_kexec_post_notifiers;
456456
extern atomic_t panic_cpu;
457457
#define PANIC_CPU_INVALID -1
458458

459-
/*
460-
* A variant of panic() called from NMI context. We return if we've already
461-
* panicked on this CPU. If another CPU already panicked, loop in
462-
* nmi_panic_self_stop() which can provide architecture dependent code such
463-
* as saving register state for crash dump.
464-
*/
465-
#define nmi_panic(regs, fmt, ...) \
466-
do { \
467-
int old_cpu, cpu; \
468-
\
469-
cpu = raw_smp_processor_id(); \
470-
old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu); \
471-
\
472-
if (old_cpu == PANIC_CPU_INVALID) \
473-
panic(fmt, ##__VA_ARGS__); \
474-
else if (old_cpu != cpu) \
475-
nmi_panic_self_stop(regs); \
476-
} while (0)
477-
478459
/*
479460
* Only to be used by arch init code. If the user over-wrote the default
480461
* CONFIG_PANIC_TIMEOUT, honor it.

‎kernel/panic.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ void __weak nmi_panic_self_stop(struct pt_regs *regs)
7373

7474
atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
7575

76+
/*
77+
* A variant of panic() called from NMI context. We return if we've already
78+
* panicked on this CPU. If another CPU already panicked, loop in
79+
* nmi_panic_self_stop() which can provide architecture dependent code such
80+
* as saving register state for crash dump.
81+
*/
82+
void nmi_panic(struct pt_regs *regs, const char *msg)
83+
{
84+
int old_cpu, cpu;
85+
86+
cpu = raw_smp_processor_id();
87+
old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu);
88+
89+
if (old_cpu == PANIC_CPU_INVALID)
90+
panic("%s", msg);
91+
else if (old_cpu != cpu)
92+
nmi_panic_self_stop(regs);
93+
}
94+
EXPORT_SYMBOL(nmi_panic);
95+
7696
/**
7797
* panic - halt the system
7898
* @fmt: The text string to print

0 commit comments

Comments
 (0)