crash.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. */
  9. #include <linux/init.h>
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/smp.h>
  13. #include <linux/reboot.h>
  14. #include <linux/kexec.h>
  15. #include <linux/delay.h>
  16. #include <asm/processor.h>
  17. #include <asm/hardirq.h>
  18. #include <asm/nmi.h>
  19. #include <asm/hw_irq.h>
  20. #include <asm/mach_apic.h>
  21. /* This keeps a track of which one is crashing cpu. */
  22. static int crashing_cpu;
  23. #ifdef CONFIG_SMP
  24. static atomic_t waiting_for_crash_ipi;
  25. static int crash_nmi_callback(struct pt_regs *regs, int cpu)
  26. {
  27. /*
  28. * Don't do anything if this handler is invoked on crashing cpu.
  29. * Otherwise, system will completely hang. Crashing cpu can get
  30. * an NMI if system was initially booted with nmi_watchdog parameter.
  31. */
  32. if (cpu == crashing_cpu)
  33. return 1;
  34. local_irq_disable();
  35. disable_local_APIC();
  36. atomic_dec(&waiting_for_crash_ipi);
  37. /* Assume hlt works */
  38. for(;;)
  39. asm("hlt");
  40. return 1;
  41. }
  42. static void smp_send_nmi_allbutself(void)
  43. {
  44. send_IPI_allbutself(APIC_DM_NMI);
  45. }
  46. /*
  47. * This code is a best effort heuristic to get the
  48. * other cpus to stop executing. So races with
  49. * cpu hotplug shouldn't matter.
  50. */
  51. static void nmi_shootdown_cpus(void)
  52. {
  53. unsigned long msecs;
  54. atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
  55. set_nmi_callback(crash_nmi_callback);
  56. /*
  57. * Ensure the new callback function is set before sending
  58. * out the NMI
  59. */
  60. wmb();
  61. smp_send_nmi_allbutself();
  62. msecs = 1000; /* Wait at most a second for the other cpus to stop */
  63. while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
  64. mdelay(1);
  65. msecs--;
  66. }
  67. /* Leave the nmi callback set */
  68. disable_local_APIC();
  69. }
  70. #else
  71. static void nmi_shootdown_cpus(void)
  72. {
  73. /* There are no cpus to shootdown */
  74. }
  75. #endif
  76. void machine_crash_shutdown(struct pt_regs *regs)
  77. {
  78. /*
  79. * This function is only called after the system
  80. * has paniced or is otherwise in a critical state.
  81. * The minimum amount of code to allow a kexec'd kernel
  82. * to run successfully needs to happen here.
  83. *
  84. * In practice this means shooting down the other cpus in
  85. * an SMP system.
  86. */
  87. /* The kernel is broken so disable interrupts */
  88. local_irq_disable();
  89. /* Make a note of crashing cpu. Will be used in NMI callback.*/
  90. crashing_cpu = smp_processor_id();
  91. nmi_shootdown_cpus();
  92. if(cpu_has_apic)
  93. disable_local_APIC();
  94. #if defined(CONFIG_X86_IO_APIC)
  95. disable_IO_APIC();
  96. #endif
  97. }