crash.c 2.4 KB

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