x86 kdump: create kdump_nmi_shootdown_cpus()
[deliverable/linux.git] / arch / x86 / kernel / crash.c
CommitLineData
5033cba0 1/*
62a31a03 2 * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
5033cba0
EB
3 *
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
5 *
6 * Copyright (C) IBM Corporation, 2004. All rights reserved.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/smp.h>
5033cba0
EB
14#include <linux/reboot.h>
15#include <linux/kexec.h>
5033cba0
EB
16#include <linux/delay.h>
17#include <linux/elf.h>
18#include <linux/elfcore.h>
19
20#include <asm/processor.h>
21#include <asm/hardirq.h>
22#include <asm/nmi.h>
23#include <asm/hw_irq.h>
19842d67 24#include <asm/apic.h>
0c1b2724 25#include <asm/hpet.h>
1eeb66a1 26#include <linux/kdebug.h>
ce53af94 27#include <asm/smp.h>
ed23dc6f 28#include <asm/reboot.h>
2fbe7b25 29
c4ac4263 30#include <mach_ipi.h>
5033cba0 31
b2bbe71b
EH
32#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
33
a3ea8ac8
VG
34/* This keeps a track of which one is crashing cpu. */
35static int crashing_cpu;
5033cba0 36
c4ac4263
EB
37static atomic_t waiting_for_crash_ipi;
38
a7d41820 39static void kdump_nmi_callback(int cpu, struct die_args *args)
c4ac4263 40{
2fbe7b25 41 struct pt_regs *regs;
1fb473d8 42#ifdef CONFIG_X86_32
4d55476c 43 struct pt_regs fixed_regs;
62a31a03 44#endif
a7d41820
EH
45
46 regs = args->regs;
47
48#ifdef CONFIG_X86_32
49 if (!user_mode_vm(regs)) {
50 crash_fixup_ss_esp(&fixed_regs, regs);
51 regs = &fixed_regs;
52 }
53#endif
54 crash_save_cpu(regs, cpu);
55
56 disable_local_APIC();
57}
58
59static int crash_nmi_callback(struct notifier_block *self,
60 unsigned long val, void *data)
61{
2fbe7b25
DZ
62 int cpu;
63
260d6790 64 if (val != DIE_NMI_IPI)
2fbe7b25
DZ
65 return NOTIFY_OK;
66
2fbe7b25 67 cpu = raw_smp_processor_id();
a3ea8ac8
VG
68
69 /* Don't do anything if this handler is invoked on crashing cpu.
70 * Otherwise, system will completely hang. Crashing cpu can get
71 * an NMI if system was initially booted with nmi_watchdog parameter.
72 */
73 if (cpu == crashing_cpu)
260d6790 74 return NOTIFY_STOP;
c4ac4263 75 local_irq_disable();
4d55476c 76
a7d41820
EH
77 kdump_nmi_callback(cpu, (struct die_args *)data);
78
c4ac4263
EB
79 atomic_dec(&waiting_for_crash_ipi);
80 /* Assume hlt works */
f2ab4461 81 halt();
caad3c2a
CE
82 for (;;)
83 cpu_relax();
72414d3f 84
c4ac4263
EB
85 return 1;
86}
87
c4ac4263
EB
88static void smp_send_nmi_allbutself(void)
89{
bc03613d
FV
90 cpumask_t mask = cpu_online_map;
91 cpu_clear(safe_smp_processor_id(), mask);
92 if (!cpus_empty(mask))
93 send_IPI_mask(mask, NMI_VECTOR);
c4ac4263
EB
94}
95
2fbe7b25
DZ
96static struct notifier_block crash_nmi_nb = {
97 .notifier_call = crash_nmi_callback,
98};
99
c4ac4263
EB
100static void nmi_shootdown_cpus(void)
101{
102 unsigned long msecs;
c4ac4263 103
b2bbe71b
EH
104 /* Make a note of crashing cpu. Will be used in NMI callback.*/
105 crashing_cpu = safe_smp_processor_id();
106
72414d3f 107 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
c4ac4263 108 /* Would it be better to replace the trap vector here? */
2fbe7b25
DZ
109 if (register_die_notifier(&crash_nmi_nb))
110 return; /* return what? */
c4ac4263
EB
111 /* Ensure the new callback function is set before sending
112 * out the NMI
113 */
114 wmb();
115
116 smp_send_nmi_allbutself();
117
118 msecs = 1000; /* Wait at most a second for the other cpus to stop */
119 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
120 mdelay(1);
121 msecs--;
122 }
123
124 /* Leave the nmi callback set */
d1e7b91c
EH
125}
126
127static void kdump_nmi_shootdown_cpus(void)
128{
129 nmi_shootdown_cpus();
130
19842d67 131 disable_local_APIC();
c4ac4263 132}
d1e7b91c 133
c4ac4263 134#else
d1e7b91c 135static void kdump_nmi_shootdown_cpus(void)
c4ac4263
EB
136{
137 /* There are no cpus to shootdown */
138}
139#endif
140
ed23dc6f 141void native_machine_crash_shutdown(struct pt_regs *regs)
5033cba0
EB
142{
143 /* This function is only called after the system
f18190bd 144 * has panicked or is otherwise in a critical state.
5033cba0
EB
145 * The minimum amount of code to allow a kexec'd kernel
146 * to run successfully needs to happen here.
147 *
148 * In practice this means shooting down the other cpus in
149 * an SMP system.
150 */
c4ac4263
EB
151 /* The kernel is broken so disable interrupts */
152 local_irq_disable();
a3ea8ac8 153
d1e7b91c 154 kdump_nmi_shootdown_cpus();
19842d67
VG
155 lapic_shutdown();
156#if defined(CONFIG_X86_IO_APIC)
157 disable_IO_APIC();
0c1b2724
OH
158#endif
159#ifdef CONFIG_HPET_TIMER
160 hpet_disable();
19842d67 161#endif
85916f81 162 crash_save_cpu(regs, safe_smp_processor_id());
5033cba0 163}
This page took 0.377961 seconds and 5 git commands to generate.