crash.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Architecture specific (i386/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 <linux/elf.h>
  17. #include <linux/elfcore.h>
  18. #include <asm/processor.h>
  19. #include <asm/hardirq.h>
  20. #include <asm/nmi.h>
  21. #include <asm/hw_irq.h>
  22. #include <asm/apic.h>
  23. #include <asm/hpet.h>
  24. #include <linux/kdebug.h>
  25. #include <asm/cpu.h>
  26. #include <asm/reboot.h>
  27. #include <asm/virtext.h>
  28. int in_crash_kexec;
  29. #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
  30. static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
  31. {
  32. #ifdef CONFIG_X86_32
  33. struct pt_regs fixed_regs;
  34. #endif
  35. #ifdef CONFIG_X86_32
  36. if (!user_mode_vm(regs)) {
  37. crash_fixup_ss_esp(&fixed_regs, regs);
  38. regs = &fixed_regs;
  39. }
  40. #endif
  41. crash_save_cpu(regs, cpu);
  42. /* Disable VMX or SVM if needed.
  43. *
  44. * We need to disable virtualization on all CPUs.
  45. * Having VMX or SVM enabled on any CPU may break rebooting
  46. * after the kdump kernel has finished its task.
  47. */
  48. cpu_emergency_vmxoff();
  49. cpu_emergency_svm_disable();
  50. disable_local_APIC();
  51. }
  52. static void kdump_nmi_shootdown_cpus(void)
  53. {
  54. in_crash_kexec = 1;
  55. nmi_shootdown_cpus(kdump_nmi_callback);
  56. disable_local_APIC();
  57. }
  58. #else
  59. static void kdump_nmi_shootdown_cpus(void)
  60. {
  61. /* There are no cpus to shootdown */
  62. }
  63. #endif
  64. void native_machine_crash_shutdown(struct pt_regs *regs)
  65. {
  66. /* This function is only called after the system
  67. * has panicked or is otherwise in a critical state.
  68. * The minimum amount of code to allow a kexec'd kernel
  69. * to run successfully needs to happen here.
  70. *
  71. * In practice this means shooting down the other cpus in
  72. * an SMP system.
  73. */
  74. /* The kernel is broken so disable interrupts */
  75. local_irq_disable();
  76. kdump_nmi_shootdown_cpus();
  77. /* Booting kdump kernel with VMX or SVM enabled won't work,
  78. * because (among other limitations) we can't disable paging
  79. * with the virt flags.
  80. */
  81. cpu_emergency_vmxoff();
  82. cpu_emergency_svm_disable();
  83. #if defined(CONFIG_X86_IO_APIC)
  84. disable_IO_APIC();
  85. #endif
  86. lapic_shutdown();
  87. #ifdef CONFIG_HPET_TIMER
  88. hpet_disable();
  89. #endif
  90. crash_save_cpu(regs, safe_smp_processor_id());
  91. }