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>
11 #include <linux/sched/task_stack.h>
13 /* This keeps a track of which one is crashing cpu. */
14 static int crashing_cpu
= -1;
15 static cpumask_t cpus_in_crash
= CPU_MASK_NONE
;
18 static void crash_shutdown_secondary(void *passed_regs
)
20 struct pt_regs
*regs
= passed_regs
;
21 int cpu
= smp_processor_id();
24 * If we are passed registers, use those. Otherwise get the
25 * regs from the last interrupt, which should be correct, as
26 * we are in an interrupt. But if the regs are not there,
27 * pull them from the top of the stack. They are probably
28 * wrong, but we need something to keep from crashing again.
31 regs
= get_irq_regs();
33 regs
= task_pt_regs(current
);
39 if (!cpumask_test_cpu(cpu
, &cpus_in_crash
))
40 crash_save_cpu(regs
, cpu
);
41 cpumask_set_cpu(cpu
, &cpus_in_crash
);
43 while (!atomic_read(&kexec_ready_to_reboot
))
45 relocated_kexec_smp_wait(NULL
);
49 static void crash_kexec_prepare_cpus(void)
51 static int cpus_stopped
;
58 ncpus
= num_online_cpus() - 1;/* Excluding the panic cpu */
60 smp_call_function(crash_shutdown_secondary
, NULL
, 0);
64 * The crash CPU sends an IPI and wait for other CPUs to
65 * respond. Delay of at least 10 seconds.
67 pr_emerg("Sending IPI to other cpus...\n");
69 while ((cpumask_weight(&cpus_in_crash
) < ncpus
) && (--msecs
> 0)) {
77 /* Override the weak function in kernel/panic.c */
78 void crash_smp_send_stop(void)
80 if (_crash_smp_send_stop
)
81 _crash_smp_send_stop();
83 crash_kexec_prepare_cpus();
86 #else /* !defined(CONFIG_SMP) */
87 static void crash_kexec_prepare_cpus(void) {}
88 #endif /* !defined(CONFIG_SMP) */
90 void default_machine_crash_shutdown(struct pt_regs
*regs
)
93 crashing_cpu
= smp_processor_id();
94 crash_save_cpu(regs
, crashing_cpu
);
95 crash_kexec_prepare_cpus();
96 cpumask_set_cpu(crashing_cpu
, &cpus_in_crash
);