1 #include <linux/kernel.h>
3 #include <linux/reboot.h>
4 #include <linux/kexec.h>
5 #include <linux/bootmem.h>
6 #include <linux/crash_dump.h>
7 #include <linux/delay.h>
9 #include <linux/types.h>
10 #include <linux/sched.h>
12 /* This keeps a track of which one is crashing cpu. */
13 static int crashing_cpu = -1;
14 static cpumask_t cpus_in_crash = CPU_MASK_NONE;
17 static void crash_shutdown_secondary(void *passed_regs)
19 struct pt_regs *regs = passed_regs;
20 int cpu = smp_processor_id();
23 * If we are passed registers, use those. Otherwise get the
24 * regs from the last interrupt, which should be correct, as
25 * we are in an interrupt. But if the regs are not there,
26 * pull them from the top of the stack. They are probably
27 * wrong, but we need something to keep from crashing again.
30 regs = get_irq_regs();
32 regs = task_pt_regs(current);
38 if (!cpumask_test_cpu(cpu, &cpus_in_crash))
39 crash_save_cpu(regs, cpu);
40 cpumask_set_cpu(cpu, &cpus_in_crash);
42 while (!atomic_read(&kexec_ready_to_reboot))
44 relocated_kexec_smp_wait(NULL);
48 static void crash_kexec_prepare_cpus(void)
50 static int cpus_stopped;
57 ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
59 dump_send_ipi(crash_shutdown_secondary);
63 * The crash CPU sends an IPI and wait for other CPUs to
64 * respond. Delay of at least 10 seconds.
66 pr_emerg("Sending IPI to other cpus...\n");
68 while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) {
76 /* Override the weak function in kernel/panic.c */
77 void crash_smp_send_stop(void)
79 if (_crash_smp_send_stop)
80 _crash_smp_send_stop();
82 crash_kexec_prepare_cpus();
85 #else /* !defined(CONFIG_SMP) */
86 static void crash_kexec_prepare_cpus(void) {}
87 #endif /* !defined(CONFIG_SMP) */
89 void default_machine_crash_shutdown(struct pt_regs *regs)
92 crashing_cpu = smp_processor_id();
93 crash_save_cpu(regs, crashing_cpu);
94 crash_kexec_prepare_cpus();
95 cpumask_set_cpu(crashing_cpu, &cpus_in_crash);