crash.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <linux/kernel.h>
  2. #include <linux/smp.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>
  8. #include <linux/irq.h>
  9. #include <linux/types.h>
  10. #include <linux/sched.h>
  11. /* This keeps a track of which one is crashing cpu. */
  12. static int crashing_cpu = -1;
  13. static cpumask_t cpus_in_crash = CPU_MASK_NONE;
  14. #ifdef CONFIG_SMP
  15. static void crash_shutdown_secondary(void *passed_regs)
  16. {
  17. struct pt_regs *regs = passed_regs;
  18. int cpu = smp_processor_id();
  19. /*
  20. * If we are passed registers, use those. Otherwise get the
  21. * regs from the last interrupt, which should be correct, as
  22. * we are in an interrupt. But if the regs are not there,
  23. * pull them from the top of the stack. They are probably
  24. * wrong, but we need something to keep from crashing again.
  25. */
  26. if (!regs)
  27. regs = get_irq_regs();
  28. if (!regs)
  29. regs = task_pt_regs(current);
  30. if (!cpu_online(cpu))
  31. return;
  32. /* We won't be sent IPIs any more. */
  33. set_cpu_online(cpu, false);
  34. local_irq_disable();
  35. if (!cpumask_test_cpu(cpu, &cpus_in_crash))
  36. crash_save_cpu(regs, cpu);
  37. cpumask_set_cpu(cpu, &cpus_in_crash);
  38. while (!atomic_read(&kexec_ready_to_reboot))
  39. cpu_relax();
  40. relocated_kexec_smp_wait(NULL);
  41. /* NOTREACHED */
  42. }
  43. static void crash_kexec_prepare_cpus(void)
  44. {
  45. unsigned int msecs;
  46. unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
  47. dump_send_ipi(crash_shutdown_secondary);
  48. smp_wmb();
  49. /*
  50. * The crash CPU sends an IPI and wait for other CPUs to
  51. * respond. Delay of at least 10 seconds.
  52. */
  53. pr_emerg("Sending IPI to other cpus...\n");
  54. msecs = 10000;
  55. while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) {
  56. cpu_relax();
  57. mdelay(1);
  58. }
  59. }
  60. #else /* !defined(CONFIG_SMP) */
  61. static void crash_kexec_prepare_cpus(void) {}
  62. #endif /* !defined(CONFIG_SMP) */
  63. void default_machine_crash_shutdown(struct pt_regs *regs)
  64. {
  65. local_irq_disable();
  66. crashing_cpu = smp_processor_id();
  67. crash_save_cpu(regs, crashing_cpu);
  68. crash_kexec_prepare_cpus();
  69. cpumask_set_cpu(crashing_cpu, &cpus_in_crash);
  70. }