Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Architecture specific (PPC64) functions for kexec based crash dumps. |
| 3 | * |
| 4 | * Copyright (C) 2005, IBM Corp. |
| 5 | * |
| 6 | * Created by: Haren Myneni |
| 7 | * |
| 8 | * This source code is licensed under the GNU General Public License, |
| 9 | * Version 2. See the file COPYING for more details. |
| 10 | * |
| 11 | */ |
| 12 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/smp.h> |
| 15 | #include <linux/reboot.h> |
| 16 | #include <linux/kexec.h> |
Paul Gortmaker | 66b15db | 2011-05-27 10:46:24 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 18 | #include <linux/crash_dump.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 19 | #include <linux/delay.h> |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 20 | #include <linux/irq.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 21 | #include <linux/types.h> |
| 22 | |
| 23 | #include <asm/processor.h> |
| 24 | #include <asm/machdep.h> |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 25 | #include <asm/kexec.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 26 | #include <asm/kdump.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 27 | #include <asm/prom.h> |
Haren Myneni | f6cc82f | 2006-01-10 19:25:25 -0800 | [diff] [blame] | 28 | #include <asm/smp.h> |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 29 | #include <asm/setjmp.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 30 | #include <asm/debug.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 31 | |
Anton Blanchard | 549e88a | 2011-11-30 00:23:16 +0000 | [diff] [blame] | 32 | /* |
| 33 | * The primary CPU waits a while for all secondary CPUs to enter. This is to |
| 34 | * avoid sending an IPI if the secondary CPUs are entering |
| 35 | * crash_kexec_secondary on their own (eg via a system reset). |
| 36 | * |
| 37 | * The secondary timeout has to be longer than the primary. Both timeouts are |
| 38 | * in milliseconds. |
| 39 | */ |
| 40 | #define PRIMARY_TIMEOUT 500 |
| 41 | #define SECONDARY_TIMEOUT 1000 |
| 42 | |
| 43 | #define IPI_TIMEOUT 10000 |
| 44 | #define REAL_MODE_TIMEOUT 10000 |
| 45 | |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 46 | static int time_to_dump; |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 47 | |
Anton Blanchard | 158d5b5e | 2011-01-21 13:43:59 +1100 | [diff] [blame] | 48 | #define CRASH_HANDLER_MAX 3 |
Suraj Jitindar Singh | 1d14516 | 2016-05-11 10:57:32 +1000 | [diff] [blame] | 49 | /* List of shutdown handles */ |
| 50 | static crash_shutdown_t crash_shutdown_handles[CRASH_HANDLER_MAX]; |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 51 | static DEFINE_SPINLOCK(crash_handlers_lock); |
| 52 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 53 | static unsigned long crash_shutdown_buf[JMP_BUF_LEN]; |
| 54 | static int crash_shutdown_cpu = -1; |
| 55 | |
| 56 | static int handle_fault(struct pt_regs *regs) |
| 57 | { |
| 58 | if (crash_shutdown_cpu == smp_processor_id()) |
| 59 | longjmp(crash_shutdown_buf, 1); |
| 60 | return 0; |
| 61 | } |
| 62 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 63 | #ifdef CONFIG_SMP |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 64 | |
Christian Kujau | 897e01a | 2012-01-17 19:13:05 +0000 | [diff] [blame] | 65 | static atomic_t cpus_in_crash; |
Daniel Axtens | 34852ed | 2016-05-18 11:16:49 +1000 | [diff] [blame] | 66 | static void crash_ipi_callback(struct pt_regs *regs) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 67 | { |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 68 | static cpumask_t cpus_state_saved = CPU_MASK_NONE; |
| 69 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 70 | int cpu = smp_processor_id(); |
| 71 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 72 | if (!cpu_online(cpu)) |
| 73 | return; |
| 74 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 75 | hard_irq_disable(); |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 76 | if (!cpumask_test_cpu(cpu, &cpus_state_saved)) { |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 77 | crash_save_cpu(regs, cpu); |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 78 | cpumask_set_cpu(cpu, &cpus_state_saved); |
| 79 | } |
| 80 | |
| 81 | atomic_inc(&cpus_in_crash); |
Peter Zijlstra | c645073 | 2014-03-13 19:00:35 +0100 | [diff] [blame] | 82 | smp_mb__after_atomic(); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 83 | |
| 84 | /* |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 85 | * Starting the kdump boot. |
| 86 | * This barrier is needed to make sure that all CPUs are stopped. |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 87 | */ |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 88 | while (!time_to_dump) |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 89 | cpu_relax(); |
| 90 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 91 | if (ppc_md.kexec_cpu_down) |
| 92 | ppc_md.kexec_cpu_down(1, 1); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 93 | |
| 94 | #ifdef CONFIG_PPC64 |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 95 | kexec_smp_wait(); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 96 | #else |
| 97 | for (;;); /* FIXME */ |
| 98 | #endif |
| 99 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 100 | /* NOTREACHED */ |
| 101 | } |
| 102 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 103 | static void crash_kexec_prepare_cpus(int cpu) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 104 | { |
| 105 | unsigned int msecs; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 106 | unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */ |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 107 | int tries = 0; |
| 108 | int (*old_handler)(struct pt_regs *regs); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 109 | |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 110 | printk(KERN_EMERG "Sending IPI to other CPUs\n"); |
| 111 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 112 | crash_send_ipi(crash_ipi_callback); |
| 113 | smp_wmb(); |
| 114 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 115 | again: |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 116 | /* |
Anton Blanchard | 158d5b5e | 2011-01-21 13:43:59 +1100 | [diff] [blame] | 117 | * FIXME: Until we will have the way to stop other CPUs reliably, |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 118 | * the crash CPU will send an IPI and wait for other CPUs to |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 119 | * respond. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 120 | */ |
Anton Blanchard | 549e88a | 2011-11-30 00:23:16 +0000 | [diff] [blame] | 121 | msecs = IPI_TIMEOUT; |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 122 | while ((atomic_read(&cpus_in_crash) < ncpus) && (--msecs > 0)) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 123 | mdelay(1); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 124 | |
| 125 | /* Would it be better to replace the trap vector here? */ |
| 126 | |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 127 | if (atomic_read(&cpus_in_crash) >= ncpus) { |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 128 | printk(KERN_EMERG "IPI complete\n"); |
| 129 | return; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 130 | } |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 131 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 132 | printk(KERN_EMERG "ERROR: %d cpu(s) not responding\n", |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 133 | ncpus - atomic_read(&cpus_in_crash)); |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * If we have a panic timeout set then we can't wait indefinitely |
| 137 | * for someone to activate system reset. We also give up on the |
| 138 | * second time through if system reset fail to work. |
| 139 | */ |
| 140 | if ((panic_timeout > 0) || (tries > 0)) |
| 141 | return; |
| 142 | |
| 143 | /* |
| 144 | * A system reset will cause all CPUs to take an 0x100 exception. |
| 145 | * The primary CPU returns here via setjmp, and the secondary |
| 146 | * CPUs reexecute the crash_kexec_secondary path. |
| 147 | */ |
| 148 | old_handler = __debugger; |
| 149 | __debugger = handle_fault; |
| 150 | crash_shutdown_cpu = smp_processor_id(); |
| 151 | |
| 152 | if (setjmp(crash_shutdown_buf) == 0) { |
| 153 | printk(KERN_EMERG "Activate system reset (dumprestart) " |
| 154 | "to stop other cpu(s)\n"); |
| 155 | |
| 156 | /* |
| 157 | * A system reset will force all CPUs to execute the |
| 158 | * crash code again. We need to reset cpus_in_crash so we |
| 159 | * wait for everyone to do this. |
| 160 | */ |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 161 | atomic_set(&cpus_in_crash, 0); |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 162 | smp_mb(); |
| 163 | |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 164 | while (atomic_read(&cpus_in_crash) < ncpus) |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame] | 165 | cpu_relax(); |
| 166 | } |
| 167 | |
| 168 | crash_shutdown_cpu = -1; |
| 169 | __debugger = old_handler; |
| 170 | |
| 171 | tries++; |
| 172 | goto again; |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 173 | } |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 174 | |
| 175 | /* |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 176 | * This function will be called by secondary cpus. |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 177 | */ |
| 178 | void crash_kexec_secondary(struct pt_regs *regs) |
| 179 | { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 180 | unsigned long flags; |
Anton Blanchard | 549e88a | 2011-11-30 00:23:16 +0000 | [diff] [blame] | 181 | int msecs = SECONDARY_TIMEOUT; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 182 | |
| 183 | local_irq_save(flags); |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 184 | |
Anton Blanchard | 549e88a | 2011-11-30 00:23:16 +0000 | [diff] [blame] | 185 | /* Wait for the primary crash CPU to signal its progress */ |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 186 | while (crashing_cpu < 0) { |
| 187 | if (--msecs < 0) { |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 188 | /* No response, kdump image may not have been loaded */ |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 189 | local_irq_restore(flags); |
| 190 | return; |
| 191 | } |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 192 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 193 | mdelay(1); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 194 | } |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 195 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 196 | crash_ipi_callback(regs); |
| 197 | } |
| 198 | |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 199 | #else /* ! CONFIG_SMP */ |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 200 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 201 | static void crash_kexec_prepare_cpus(int cpu) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 202 | { |
| 203 | /* |
Anton Blanchard | 8c27474 | 2011-11-30 00:23:12 +0000 | [diff] [blame] | 204 | * move the secondaries to us so that we can copy |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 205 | * the new kernel 0-0x100 safely |
| 206 | * |
| 207 | * do this if kexec in setup.c ? |
| 208 | */ |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 209 | #ifdef CONFIG_PPC64 |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 210 | smp_release_cpus(); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 211 | #else |
| 212 | /* FIXME */ |
| 213 | #endif |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 214 | } |
| 215 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 216 | void crash_kexec_secondary(struct pt_regs *regs) |
| 217 | { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 218 | } |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 219 | #endif /* CONFIG_SMP */ |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 220 | |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 221 | /* wait for all the CPUs to hit real mode but timeout if they don't come in */ |
Scott Wood | eeaab66 | 2015-10-06 22:48:16 -0500 | [diff] [blame] | 222 | #if defined(CONFIG_SMP) && defined(CONFIG_PPC64) |
| 223 | static void __maybe_unused crash_kexec_wait_realmode(int cpu) |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 224 | { |
| 225 | unsigned int msecs; |
| 226 | int i; |
| 227 | |
Anton Blanchard | 549e88a | 2011-11-30 00:23:16 +0000 | [diff] [blame] | 228 | msecs = REAL_MODE_TIMEOUT; |
Milton Miller | bd9e5ee | 2011-05-10 19:28:41 +0000 | [diff] [blame] | 229 | for (i=0; i < nr_cpu_ids && msecs > 0; i++) { |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 230 | if (i == cpu) |
| 231 | continue; |
| 232 | |
| 233 | while (paca[i].kexec_state < KEXEC_STATE_REAL_MODE) { |
| 234 | barrier(); |
Michael Neuling | 63f21a5 | 2011-07-04 20:40:10 +0000 | [diff] [blame] | 235 | if (!cpu_possible(i) || !cpu_online(i) || (msecs <= 0)) |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 236 | break; |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 237 | msecs--; |
| 238 | mdelay(1); |
| 239 | } |
| 240 | } |
| 241 | mb(); |
| 242 | } |
| 243 | #else |
| 244 | static inline void crash_kexec_wait_realmode(int cpu) {} |
Scott Wood | eeaab66 | 2015-10-06 22:48:16 -0500 | [diff] [blame] | 245 | #endif /* CONFIG_SMP && CONFIG_PPC64 */ |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 246 | |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 247 | /* |
| 248 | * Register a function to be called on shutdown. Only use this if you |
| 249 | * can't reset your device in the second kernel. |
| 250 | */ |
| 251 | int crash_shutdown_register(crash_shutdown_t handler) |
| 252 | { |
| 253 | unsigned int i, rc; |
| 254 | |
| 255 | spin_lock(&crash_handlers_lock); |
| 256 | for (i = 0 ; i < CRASH_HANDLER_MAX; i++) |
| 257 | if (!crash_shutdown_handles[i]) { |
| 258 | /* Insert handle at first empty entry */ |
| 259 | crash_shutdown_handles[i] = handler; |
| 260 | rc = 0; |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | if (i == CRASH_HANDLER_MAX) { |
| 265 | printk(KERN_ERR "Crash shutdown handles full, " |
| 266 | "not registered.\n"); |
| 267 | rc = 1; |
| 268 | } |
| 269 | |
| 270 | spin_unlock(&crash_handlers_lock); |
| 271 | return rc; |
| 272 | } |
| 273 | EXPORT_SYMBOL(crash_shutdown_register); |
| 274 | |
| 275 | int crash_shutdown_unregister(crash_shutdown_t handler) |
| 276 | { |
| 277 | unsigned int i, rc; |
| 278 | |
| 279 | spin_lock(&crash_handlers_lock); |
| 280 | for (i = 0 ; i < CRASH_HANDLER_MAX; i++) |
| 281 | if (crash_shutdown_handles[i] == handler) |
| 282 | break; |
| 283 | |
| 284 | if (i == CRASH_HANDLER_MAX) { |
| 285 | printk(KERN_ERR "Crash shutdown handle not found\n"); |
| 286 | rc = 1; |
| 287 | } else { |
| 288 | /* Shift handles down */ |
Suraj Jitindar Singh | 1d14516 | 2016-05-11 10:57:32 +1000 | [diff] [blame] | 289 | for (; i < (CRASH_HANDLER_MAX - 1); i++) |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 290 | crash_shutdown_handles[i] = |
| 291 | crash_shutdown_handles[i+1]; |
Suraj Jitindar Singh | 1d14516 | 2016-05-11 10:57:32 +1000 | [diff] [blame] | 292 | /* |
| 293 | * Reset last entry to NULL now that it has been shifted down, |
| 294 | * this will allow new handles to be added here. |
| 295 | */ |
| 296 | crash_shutdown_handles[i] = NULL; |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 297 | rc = 0; |
| 298 | } |
| 299 | |
| 300 | spin_unlock(&crash_handlers_lock); |
| 301 | return rc; |
| 302 | } |
| 303 | EXPORT_SYMBOL(crash_shutdown_unregister); |
| 304 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 305 | void default_machine_crash_shutdown(struct pt_regs *regs) |
| 306 | { |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 307 | unsigned int i; |
| 308 | int (*old_handler)(struct pt_regs *regs); |
| 309 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 310 | /* |
| 311 | * This function is only called after the system |
Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 312 | * has panicked or is otherwise in a critical state. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 313 | * The minimum amount of code to allow a kexec'd kernel |
| 314 | * to run successfully needs to happen here. |
| 315 | * |
| 316 | * In practice this means stopping other cpus in |
| 317 | * an SMP system. |
| 318 | * The kernel is broken so disable interrupts. |
| 319 | */ |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 320 | hard_irq_disable(); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 321 | |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 322 | /* |
| 323 | * Make a note of crashing cpu. Will be used in machine_kexec |
| 324 | * such that another IPI will not be sent. |
| 325 | */ |
| 326 | crashing_cpu = smp_processor_id(); |
Anton Blanchard | 549e88a | 2011-11-30 00:23:16 +0000 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * If we came in via system reset, wait a while for the secondary |
| 330 | * CPUs to enter. |
| 331 | */ |
| 332 | if (TRAP(regs) == 0x100) |
| 333 | mdelay(PRIMARY_TIMEOUT); |
| 334 | |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 335 | crash_kexec_prepare_cpus(crashing_cpu); |
Anton Blanchard | 2440c01 | 2011-11-30 00:23:17 +0000 | [diff] [blame] | 336 | |
| 337 | crash_save_cpu(regs, crashing_cpu); |
| 338 | |
| 339 | time_to_dump = 1; |
| 340 | |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 341 | crash_kexec_wait_realmode(crashing_cpu); |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 342 | |
Matthew McClintock | c71635d | 2010-09-16 17:58:23 -0500 | [diff] [blame] | 343 | machine_kexec_mask_interrupts(); |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 344 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 345 | /* |
Anton Blanchard | 8c27474 | 2011-11-30 00:23:12 +0000 | [diff] [blame] | 346 | * Call registered shutdown routines safely. Swap out |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 347 | * __debugger_fault_handler, and replace on exit. |
| 348 | */ |
| 349 | old_handler = __debugger_fault_handler; |
| 350 | __debugger_fault_handler = handle_fault; |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 351 | crash_shutdown_cpu = smp_processor_id(); |
Suraj Jitindar Singh | a7d6392 | 2016-07-11 14:17:31 +1000 | [diff] [blame] | 352 | for (i = 0; i < CRASH_HANDLER_MAX && crash_shutdown_handles[i]; i++) { |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 353 | if (setjmp(crash_shutdown_buf) == 0) { |
| 354 | /* |
| 355 | * Insert syncs and delay to ensure |
| 356 | * instructions in the dangerous region don't |
| 357 | * leak away from this protected region. |
| 358 | */ |
| 359 | asm volatile("sync; isync"); |
| 360 | /* dangerous region */ |
| 361 | crash_shutdown_handles[i](); |
| 362 | asm volatile("sync; isync"); |
| 363 | } |
| 364 | } |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 365 | crash_shutdown_cpu = -1; |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 366 | __debugger_fault_handler = old_handler; |
| 367 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 368 | if (ppc_md.kexec_cpu_down) |
| 369 | ppc_md.kexec_cpu_down(1, 0); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 370 | } |