diff options
author | Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com> | 2015-12-14 05:19:09 -0500 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2015-12-19 05:07:00 -0500 |
commit | 1717f2096b543cede7a380c858c765c41936bc35 (patch) | |
tree | fdf2498aadd9a6706c8af5e964591956e3a69101 /kernel/panic.c | |
parent | d267b8d6c65ed7636a412ca479b96df7c0f5b27b (diff) |
panic, x86: Fix re-entrance problem due to panic on NMI
If panic on NMI happens just after panic() on the same CPU, panic() is
recursively called. Kernel stalls, as a result, after failing to acquire
panic_lock.
To avoid this problem, don't call panic() in NMI context if we've
already entered panic().
For that, introduce nmi_panic() macro to reduce code duplication. In
the case of panic on NMI, don't return from NMI handlers if another CPU
already panicked.
Signed-off-by: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Aaron Tomlin <atomlin@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Gobinda Charan Maji <gobinda.cemk07@gmail.com>
Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Javi Merino <javi.merino@arm.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: kexec@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Cc: lkml <linux-kernel@vger.kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ulrich Obergfell <uobergfe@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Link: http://lkml.kernel.org/r/20151210014626.25437.13302.stgit@softrs
[ Cleanup comments, fixup formatting. ]
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/panic.c')
-rw-r--r-- | kernel/panic.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/kernel/panic.c b/kernel/panic.c index 4b150bc0c6c1..3344524cf6ff 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
@@ -61,6 +61,8 @@ void __weak panic_smp_self_stop(void) | |||
61 | cpu_relax(); | 61 | cpu_relax(); |
62 | } | 62 | } |
63 | 63 | ||
64 | atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); | ||
65 | |||
64 | /** | 66 | /** |
65 | * panic - halt the system | 67 | * panic - halt the system |
66 | * @fmt: The text string to print | 68 | * @fmt: The text string to print |
@@ -71,17 +73,17 @@ void __weak panic_smp_self_stop(void) | |||
71 | */ | 73 | */ |
72 | void panic(const char *fmt, ...) | 74 | void panic(const char *fmt, ...) |
73 | { | 75 | { |
74 | static DEFINE_SPINLOCK(panic_lock); | ||
75 | static char buf[1024]; | 76 | static char buf[1024]; |
76 | va_list args; | 77 | va_list args; |
77 | long i, i_next = 0; | 78 | long i, i_next = 0; |
78 | int state = 0; | 79 | int state = 0; |
80 | int old_cpu, this_cpu; | ||
79 | 81 | ||
80 | /* | 82 | /* |
81 | * Disable local interrupts. This will prevent panic_smp_self_stop | 83 | * Disable local interrupts. This will prevent panic_smp_self_stop |
82 | * from deadlocking the first cpu that invokes the panic, since | 84 | * from deadlocking the first cpu that invokes the panic, since |
83 | * there is nothing to prevent an interrupt handler (that runs | 85 | * there is nothing to prevent an interrupt handler (that runs |
84 | * after the panic_lock is acquired) from invoking panic again. | 86 | * after setting panic_cpu) from invoking panic() again. |
85 | */ | 87 | */ |
86 | local_irq_disable(); | 88 | local_irq_disable(); |
87 | 89 | ||
@@ -94,8 +96,16 @@ void panic(const char *fmt, ...) | |||
94 | * multiple parallel invocations of panic, all other CPUs either | 96 | * multiple parallel invocations of panic, all other CPUs either |
95 | * stop themself or will wait until they are stopped by the 1st CPU | 97 | * stop themself or will wait until they are stopped by the 1st CPU |
96 | * with smp_send_stop(). | 98 | * with smp_send_stop(). |
99 | * | ||
100 | * `old_cpu == PANIC_CPU_INVALID' means this is the 1st CPU which | ||
101 | * comes here, so go ahead. | ||
102 | * `old_cpu == this_cpu' means we came from nmi_panic() which sets | ||
103 | * panic_cpu to this CPU. In this case, this is also the 1st CPU. | ||
97 | */ | 104 | */ |
98 | if (!spin_trylock(&panic_lock)) | 105 | this_cpu = raw_smp_processor_id(); |
106 | old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu); | ||
107 | |||
108 | if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu) | ||
99 | panic_smp_self_stop(); | 109 | panic_smp_self_stop(); |
100 | 110 | ||
101 | console_verbose(); | 111 | console_verbose(); |