move die notifier handling to common code
[deliverable/linux.git] / arch / i386 / kernel / crash.c
CommitLineData
5033cba0
EB
1/*
2 * Architecture specific (i386) functions for kexec based crash dumps.
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>
1eeb66a1 25#include <linux/kdebug.h>
ce53af94 26#include <asm/smp.h>
2fbe7b25 27
c4ac4263 28#include <mach_ipi.h>
5033cba0 29
5033cba0 30
a3ea8ac8
VG
31/* This keeps a track of which one is crashing cpu. */
32static int crashing_cpu;
5033cba0 33
e78a887a 34#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
c4ac4263
EB
35static atomic_t waiting_for_crash_ipi;
36
2fbe7b25
DZ
37static int crash_nmi_callback(struct notifier_block *self,
38 unsigned long val, void *data)
c4ac4263 39{
2fbe7b25 40 struct pt_regs *regs;
4d55476c 41 struct pt_regs fixed_regs;
2fbe7b25
DZ
42 int cpu;
43
260d6790 44 if (val != DIE_NMI_IPI)
2fbe7b25
DZ
45 return NOTIFY_OK;
46
47 regs = ((struct die_args *)data)->regs;
48 cpu = raw_smp_processor_id();
a3ea8ac8
VG
49
50 /* Don't do anything if this handler is invoked on crashing cpu.
51 * Otherwise, system will completely hang. Crashing cpu can get
52 * an NMI if system was initially booted with nmi_watchdog parameter.
53 */
54 if (cpu == crashing_cpu)
260d6790 55 return NOTIFY_STOP;
c4ac4263 56 local_irq_disable();
4d55476c 57
db753bdf 58 if (!user_mode_vm(regs)) {
e996e581 59 crash_fixup_ss_esp(&fixed_regs, regs);
4d55476c
VG
60 regs = &fixed_regs;
61 }
85916f81 62 crash_save_cpu(regs, cpu);
19842d67 63 disable_local_APIC();
c4ac4263
EB
64 atomic_dec(&waiting_for_crash_ipi);
65 /* Assume hlt works */
f2ab4461 66 halt();
caad3c2a
CE
67 for (;;)
68 cpu_relax();
72414d3f 69
c4ac4263
EB
70 return 1;
71}
72
c4ac4263
EB
73static void smp_send_nmi_allbutself(void)
74{
bc03613d
FV
75 cpumask_t mask = cpu_online_map;
76 cpu_clear(safe_smp_processor_id(), mask);
77 if (!cpus_empty(mask))
78 send_IPI_mask(mask, NMI_VECTOR);
c4ac4263
EB
79}
80
2fbe7b25
DZ
81static struct notifier_block crash_nmi_nb = {
82 .notifier_call = crash_nmi_callback,
83};
84
c4ac4263
EB
85static void nmi_shootdown_cpus(void)
86{
87 unsigned long msecs;
c4ac4263 88
72414d3f 89 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
c4ac4263 90 /* Would it be better to replace the trap vector here? */
2fbe7b25
DZ
91 if (register_die_notifier(&crash_nmi_nb))
92 return; /* return what? */
c4ac4263
EB
93 /* Ensure the new callback function is set before sending
94 * out the NMI
95 */
96 wmb();
97
98 smp_send_nmi_allbutself();
99
100 msecs = 1000; /* Wait at most a second for the other cpus to stop */
101 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
102 mdelay(1);
103 msecs--;
104 }
105
106 /* Leave the nmi callback set */
19842d67 107 disable_local_APIC();
c4ac4263
EB
108}
109#else
110static void nmi_shootdown_cpus(void)
111{
112 /* There are no cpus to shootdown */
113}
114#endif
115
6e274d14 116void machine_crash_shutdown(struct pt_regs *regs)
5033cba0
EB
117{
118 /* This function is only called after the system
f18190bd 119 * has panicked or is otherwise in a critical state.
5033cba0
EB
120 * The minimum amount of code to allow a kexec'd kernel
121 * to run successfully needs to happen here.
122 *
123 * In practice this means shooting down the other cpus in
124 * an SMP system.
125 */
c4ac4263
EB
126 /* The kernel is broken so disable interrupts */
127 local_irq_disable();
a3ea8ac8
VG
128
129 /* Make a note of crashing cpu. Will be used in NMI callback.*/
ce53af94 130 crashing_cpu = safe_smp_processor_id();
c4ac4263 131 nmi_shootdown_cpus();
19842d67
VG
132 lapic_shutdown();
133#if defined(CONFIG_X86_IO_APIC)
134 disable_IO_APIC();
135#endif
85916f81 136 crash_save_cpu(regs, safe_smp_processor_id());
5033cba0 137}
This page took 0.217022 seconds and 5 git commands to generate.