ia64/xen-unstable

view linux-2.6-xen-sparse/arch/x86_64/kernel/crash.c @ 13647:057c4c2991fa

32-on-64: Fix an one-off error in compat_addr_ok().
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@localhost.localdomain
date Fri Jan 26 13:36:52 2007 +0000 (2007-01-26)
parents 3adf00179a63
children
line source
1 /*
2 * Architecture specific (x86_64) 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 */
10 #include <linux/init.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/smp.h>
14 #include <linux/irq.h>
15 #include <linux/reboot.h>
16 #include <linux/kexec.h>
17 #include <linux/delay.h>
18 #include <linux/elf.h>
19 #include <linux/elfcore.h>
21 #include <asm/processor.h>
22 #include <asm/hardirq.h>
23 #include <asm/nmi.h>
24 #include <asm/hw_irq.h>
25 #include <asm/mach_apic.h>
27 /* This keeps a track of which one is crashing cpu. */
28 static int crashing_cpu;
30 static u32 *append_elf_note(u32 *buf, char *name, unsigned type,
31 void *data, size_t data_len)
32 {
33 struct elf_note note;
35 note.n_namesz = strlen(name) + 1;
36 note.n_descsz = data_len;
37 note.n_type = type;
38 memcpy(buf, &note, sizeof(note));
39 buf += (sizeof(note) +3)/4;
40 memcpy(buf, name, note.n_namesz);
41 buf += (note.n_namesz + 3)/4;
42 memcpy(buf, data, note.n_descsz);
43 buf += (note.n_descsz + 3)/4;
45 return buf;
46 }
48 static void final_note(u32 *buf)
49 {
50 struct elf_note note;
52 note.n_namesz = 0;
53 note.n_descsz = 0;
54 note.n_type = 0;
55 memcpy(buf, &note, sizeof(note));
56 }
58 static void crash_save_this_cpu(struct pt_regs *regs, int cpu)
59 {
60 struct elf_prstatus prstatus;
61 u32 *buf;
63 if ((cpu < 0) || (cpu >= NR_CPUS))
64 return;
66 /* Using ELF notes here is opportunistic.
67 * I need a well defined structure format
68 * for the data I pass, and I need tags
69 * on the data to indicate what information I have
70 * squirrelled away. ELF notes happen to provide
71 * all of that that no need to invent something new.
72 */
74 buf = (u32*)per_cpu_ptr(crash_notes, cpu);
76 if (!buf)
77 return;
79 memset(&prstatus, 0, sizeof(prstatus));
80 prstatus.pr_pid = current->pid;
81 elf_core_copy_regs(&prstatus.pr_reg, regs);
82 buf = append_elf_note(buf, "CORE", NT_PRSTATUS, &prstatus,
83 sizeof(prstatus));
84 final_note(buf);
85 }
87 static void crash_save_self(struct pt_regs *regs)
88 {
89 int cpu;
91 cpu = smp_processor_id();
92 crash_save_this_cpu(regs, cpu);
93 }
95 #ifndef CONFIG_XEN
96 #ifdef CONFIG_SMP
97 static atomic_t waiting_for_crash_ipi;
99 static int crash_nmi_callback(struct pt_regs *regs, int cpu)
100 {
101 /*
102 * Don't do anything if this handler is invoked on crashing cpu.
103 * Otherwise, system will completely hang. Crashing cpu can get
104 * an NMI if system was initially booted with nmi_watchdog parameter.
105 */
106 if (cpu == crashing_cpu)
107 return 1;
108 local_irq_disable();
110 crash_save_this_cpu(regs, cpu);
111 disable_local_APIC();
112 atomic_dec(&waiting_for_crash_ipi);
113 /* Assume hlt works */
114 for(;;)
115 halt();
117 return 1;
118 }
120 static void smp_send_nmi_allbutself(void)
121 {
122 send_IPI_allbutself(NMI_VECTOR);
123 }
125 /*
126 * This code is a best effort heuristic to get the
127 * other cpus to stop executing. So races with
128 * cpu hotplug shouldn't matter.
129 */
131 static void nmi_shootdown_cpus(void)
132 {
133 unsigned long msecs;
135 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
136 set_nmi_callback(crash_nmi_callback);
138 /*
139 * Ensure the new callback function is set before sending
140 * out the NMI
141 */
142 wmb();
144 smp_send_nmi_allbutself();
146 msecs = 1000; /* Wait at most a second for the other cpus to stop */
147 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
148 mdelay(1);
149 msecs--;
150 }
151 /* Leave the nmi callback set */
152 disable_local_APIC();
153 }
154 #else
155 static void nmi_shootdown_cpus(void)
156 {
157 /* There are no cpus to shootdown */
158 }
159 #endif
160 #endif /* CONFIG_XEN */
162 void machine_crash_shutdown(struct pt_regs *regs)
163 {
164 /*
165 * This function is only called after the system
166 * has panicked or is otherwise in a critical state.
167 * The minimum amount of code to allow a kexec'd kernel
168 * to run successfully needs to happen here.
169 *
170 * In practice this means shooting down the other cpus in
171 * an SMP system.
172 */
173 /* The kernel is broken so disable interrupts */
174 local_irq_disable();
176 /* Make a note of crashing cpu. Will be used in NMI callback.*/
177 crashing_cpu = smp_processor_id();
179 #ifndef CONFIG_XEN
180 nmi_shootdown_cpus();
182 if(cpu_has_apic)
183 disable_local_APIC();
185 #if defined(CONFIG_X86_IO_APIC)
186 disable_IO_APIC();
187 #endif
188 #endif /* CONFIG_XEN */
189 crash_save_self(regs);
190 }