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