]>
Commit | Line | Data |
---|---|---|
a7956113 ZN |
1 | /* |
2 | * arch/ia64/kernel/crash.c | |
3 | * | |
4 | * Architecture specific (ia64) functions for kexec based crash dumps. | |
5 | * | |
6 | * Created by: Khalid Aziz <khalid.aziz@hp.com> | |
7 | * Copyright (C) 2005 Hewlett-Packard Development Company, L.P. | |
8 | * Copyright (C) 2005 Intel Corp Zou Nan hai <nanhai.zou@intel.com> | |
9 | * | |
10 | */ | |
11 | #include <linux/smp.h> | |
12 | #include <linux/delay.h> | |
13 | #include <linux/crash_dump.h> | |
14 | #include <linux/bootmem.h> | |
15 | #include <linux/kexec.h> | |
16 | #include <linux/elfcore.h> | |
17 | #include <linux/sysctl.h> | |
18 | #include <linux/init.h> | |
1eeb66a1 | 19 | #include <linux/kdebug.h> |
a7956113 | 20 | |
a7956113 | 21 | #include <asm/mca.h> |
a7956113 ZN |
22 | |
23 | int kdump_status[NR_CPUS]; | |
0ac1faca | 24 | static atomic_t kdump_cpu_frozen; |
a7956113 | 25 | atomic_t kdump_in_progress; |
1726b088 | 26 | static int kdump_freeze_monarch; |
0ac1faca | 27 | static int kdump_on_init = 1; |
b0247a55 | 28 | static int kdump_on_fatal_mca = 1; |
a7956113 | 29 | |
a7956113 ZN |
30 | extern void ia64_dump_cpu_regs(void *); |
31 | ||
32 | static DEFINE_PER_CPU(struct elf_prstatus, elf_prstatus); | |
33 | ||
34 | void | |
ccbebdac | 35 | crash_save_this_cpu(void) |
a7956113 ZN |
36 | { |
37 | void *buf; | |
38 | unsigned long cfm, sof, sol; | |
39 | ||
40 | int cpu = smp_processor_id(); | |
41 | struct elf_prstatus *prstatus = &per_cpu(elf_prstatus, cpu); | |
42 | ||
43 | elf_greg_t *dst = (elf_greg_t *)&(prstatus->pr_reg); | |
44 | memset(prstatus, 0, sizeof(*prstatus)); | |
45 | prstatus->pr_pid = current->pid; | |
46 | ||
47 | ia64_dump_cpu_regs(dst); | |
48 | cfm = dst[43]; | |
49 | sol = (cfm >> 7) & 0x7f; | |
50 | sof = cfm & 0x7f; | |
51 | dst[46] = (unsigned long)ia64_rse_skip_regs((unsigned long *)dst[46], | |
52 | sof - sol); | |
53 | ||
54 | buf = (u64 *) per_cpu_ptr(crash_notes, cpu); | |
55 | if (!buf) | |
56 | return; | |
6672f76a | 57 | buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS, prstatus, |
a7956113 ZN |
58 | sizeof(*prstatus)); |
59 | final_note(buf); | |
60 | } | |
61 | ||
bcb9b99d | 62 | #ifdef CONFIG_SMP |
a7956113 ZN |
63 | static int |
64 | kdump_wait_cpu_freeze(void) | |
65 | { | |
66 | int cpu_num = num_online_cpus() - 1; | |
67 | int timeout = 1000; | |
68 | while(timeout-- > 0) { | |
0ac1faca | 69 | if (atomic_read(&kdump_cpu_frozen) == cpu_num) |
a7956113 ZN |
70 | return 0; |
71 | udelay(1000); | |
72 | } | |
73 | return 1; | |
74 | } | |
bcb9b99d | 75 | #endif |
a7956113 ZN |
76 | |
77 | void | |
78 | machine_crash_shutdown(struct pt_regs *pt) | |
79 | { | |
80 | /* This function is only called after the system | |
81 | * has paniced or is otherwise in a critical state. | |
82 | * The minimum amount of code to allow a kexec'd kernel | |
83 | * to run successfully needs to happen here. | |
84 | * | |
85 | * In practice this means shooting down the other cpus in | |
86 | * an SMP system. | |
87 | */ | |
88 | kexec_disable_iosapic(); | |
89 | #ifdef CONFIG_SMP | |
1726b088 HS |
90 | /* |
91 | * If kdump_on_init is set and an INIT is asserted here, kdump will | |
92 | * be started again via INIT monarch. | |
93 | */ | |
94 | local_irq_disable(); | |
95 | ia64_set_psr_mc(); /* mask MCA/INIT */ | |
96 | if (atomic_inc_return(&kdump_in_progress) != 1) | |
97 | unw_init_running(kdump_cpu_freeze, NULL); | |
98 | ||
99 | /* | |
100 | * Now this cpu is ready for kdump. | |
101 | * Stop all others by IPI or INIT. They could receive INIT from | |
102 | * outside and might be INIT monarch, but only thing they have to | |
103 | * do is falling into kdump_cpu_freeze(). | |
104 | * | |
105 | * If an INIT is asserted here: | |
106 | * - All receivers might be slaves, since some of cpus could already | |
107 | * be frozen and INIT might be masked on monarch. In this case, | |
0cced40e HS |
108 | * all slaves will be frozen soon since kdump_in_progress will let |
109 | * them into DIE_INIT_SLAVE_LEAVE. | |
1726b088 HS |
110 | * - One might be a monarch, but INIT rendezvous will fail since |
111 | * at least this cpu already have INIT masked so it never join | |
112 | * to the rendezvous. In this case, all slaves and monarch will | |
0cced40e HS |
113 | * be frozen soon with no wait since the INIT rendezvous is skipped |
114 | * by kdump_in_progress. | |
1726b088 | 115 | */ |
a7956113 | 116 | kdump_smp_send_stop(); |
0ac1faca | 117 | /* not all cpu response to IPI, send INIT to freeze them */ |
5959906e | 118 | if (kdump_wait_cpu_freeze()) { |
a7956113 | 119 | kdump_smp_send_init(); |
5959906e HS |
120 | /* wait again, don't go ahead if possible */ |
121 | kdump_wait_cpu_freeze(); | |
a7956113 ZN |
122 | } |
123 | #endif | |
124 | } | |
125 | ||
126 | static void | |
127 | machine_kdump_on_init(void) | |
128 | { | |
072f042d | 129 | crash_save_vmcoreinfo(); |
a7956113 ZN |
130 | local_irq_disable(); |
131 | kexec_disable_iosapic(); | |
132 | machine_kexec(ia64_kimage); | |
133 | } | |
134 | ||
135 | void | |
136 | kdump_cpu_freeze(struct unw_frame_info *info, void *arg) | |
137 | { | |
138 | int cpuid; | |
4295ab34 | 139 | |
a7956113 ZN |
140 | local_irq_disable(); |
141 | cpuid = smp_processor_id(); | |
142 | crash_save_this_cpu(); | |
143 | current->thread.ksp = (__u64)info->sw - 16; | |
4295ab34 HS |
144 | |
145 | ia64_set_psr_mc(); /* mask MCA/INIT and stop reentrance */ | |
146 | ||
0ac1faca | 147 | atomic_inc(&kdump_cpu_frozen); |
a7956113 ZN |
148 | kdump_status[cpuid] = 1; |
149 | mb(); | |
bcb9b99d MD |
150 | for (;;) |
151 | cpu_relax(); | |
a7956113 ZN |
152 | } |
153 | ||
154 | static int | |
155 | kdump_init_notifier(struct notifier_block *self, unsigned long val, void *data) | |
156 | { | |
157 | struct ia64_mca_notify_die *nd; | |
158 | struct die_args *args = data; | |
159 | ||
5959906e HS |
160 | if (atomic_read(&kdump_in_progress)) { |
161 | switch (val) { | |
162 | case DIE_INIT_MONARCH_LEAVE: | |
163 | if (!kdump_freeze_monarch) | |
164 | break; | |
165 | /* fall through */ | |
166 | case DIE_INIT_SLAVE_LEAVE: | |
0cced40e | 167 | case DIE_INIT_MONARCH_ENTER: |
5959906e HS |
168 | case DIE_MCA_RENDZVOUS_LEAVE: |
169 | unw_init_running(kdump_cpu_freeze, NULL); | |
170 | break; | |
171 | } | |
172 | } | |
173 | ||
b0247a55 | 174 | if (!kdump_on_init && !kdump_on_fatal_mca) |
a7956113 ZN |
175 | return NOTIFY_DONE; |
176 | ||
2010d7fe KK |
177 | if (!ia64_kimage) { |
178 | if (val == DIE_INIT_MONARCH_LEAVE) | |
179 | ia64_mca_printk(KERN_NOTICE | |
180 | "%s: kdump not configured\n", | |
d4ed8084 | 181 | __func__); |
2010d7fe KK |
182 | return NOTIFY_DONE; |
183 | } | |
184 | ||
311f594d | 185 | if (val != DIE_INIT_MONARCH_LEAVE && |
311f594d | 186 | val != DIE_INIT_MONARCH_PROCESS && |
a7956113 ZN |
187 | val != DIE_MCA_MONARCH_LEAVE) |
188 | return NOTIFY_DONE; | |
189 | ||
190 | nd = (struct ia64_mca_notify_die *)args->err; | |
a7956113 ZN |
191 | |
192 | switch (val) { | |
3975afff | 193 | case DIE_INIT_MONARCH_PROCESS: |
5959906e HS |
194 | /* Reason code 1 means machine check rendezvous*/ |
195 | if (kdump_on_init && (nd->sos->rv_rc != 1)) { | |
1726b088 HS |
196 | if (atomic_inc_return(&kdump_in_progress) != 1) |
197 | kdump_freeze_monarch = 1; | |
3975afff HS |
198 | } |
199 | break; | |
200 | case DIE_INIT_MONARCH_LEAVE: | |
5959906e HS |
201 | /* Reason code 1 means machine check rendezvous*/ |
202 | if (kdump_on_init && (nd->sos->rv_rc != 1)) | |
203 | machine_kdump_on_init(); | |
3975afff HS |
204 | break; |
205 | case DIE_MCA_MONARCH_LEAVE: | |
4fa2f0e6 HS |
206 | /* *(nd->data) indicate if MCA is recoverable */ |
207 | if (kdump_on_fatal_mca && !(*(nd->data))) { | |
0cced40e | 208 | if (atomic_inc_return(&kdump_in_progress) == 1) |
1726b088 | 209 | machine_kdump_on_init(); |
1726b088 | 210 | /* We got fatal MCA while kdump!? No way!! */ |
3975afff HS |
211 | } |
212 | break; | |
a7956113 ZN |
213 | } |
214 | return NOTIFY_DONE; | |
215 | } | |
216 | ||
217 | #ifdef CONFIG_SYSCTL | |
2841efa6 | 218 | static struct ctl_table kdump_ctl_table[] = { |
a7956113 | 219 | { |
a7956113 ZN |
220 | .procname = "kdump_on_init", |
221 | .data = &kdump_on_init, | |
222 | .maxlen = sizeof(int), | |
223 | .mode = 0644, | |
6d456111 | 224 | .proc_handler = proc_dointvec, |
a7956113 | 225 | }, |
b0247a55 | 226 | { |
b0247a55 HS |
227 | .procname = "kdump_on_fatal_mca", |
228 | .data = &kdump_on_fatal_mca, | |
229 | .maxlen = sizeof(int), | |
230 | .mode = 0644, | |
6d456111 | 231 | .proc_handler = proc_dointvec, |
b0247a55 | 232 | }, |
d00faf81 | 233 | { } |
a7956113 ZN |
234 | }; |
235 | ||
2841efa6 | 236 | static struct ctl_table sys_table[] = { |
a7956113 | 237 | { |
a7956113 ZN |
238 | .procname = "kernel", |
239 | .mode = 0555, | |
b0247a55 | 240 | .child = kdump_ctl_table, |
a7956113 | 241 | }, |
d00faf81 | 242 | { } |
a7956113 ZN |
243 | }; |
244 | #endif | |
245 | ||
246 | static int | |
247 | machine_crash_setup(void) | |
248 | { | |
311f594d | 249 | /* be notified before default_monarch_init_process */ |
a7956113 ZN |
250 | static struct notifier_block kdump_init_notifier_nb = { |
251 | .notifier_call = kdump_init_notifier, | |
311f594d | 252 | .priority = 1, |
a7956113 ZN |
253 | }; |
254 | int ret; | |
a7956113 ZN |
255 | if((ret = register_die_notifier(&kdump_init_notifier_nb)) != 0) |
256 | return ret; | |
257 | #ifdef CONFIG_SYSCTL | |
0b4d4147 | 258 | register_sysctl_table(sys_table); |
a7956113 ZN |
259 | #endif |
260 | return 0; | |
261 | } | |
262 | ||
263 | __initcall(machine_crash_setup); | |
264 |