crash.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/smp.h>
  12. #include <linux/reboot.h>
  13. #include <linux/kexec.h>
  14. #include <linux/delay.h>
  15. #include <linux/elf.h>
  16. #include <linux/elfcore.h>
  17. #include <linux/module.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. /*
  30. * This is used to VMCLEAR all VMCSs loaded on the
  31. * processor. And when loading kvm_intel module, the
  32. * callback function pointer will be assigned.
  33. *
  34. * protected by rcu.
  35. */
  36. crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL;
  37. EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
  38. static inline void cpu_crash_vmclear_loaded_vmcss(void)
  39. {
  40. crash_vmclear_fn *do_vmclear_operation = NULL;
  41. rcu_read_lock();
  42. do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
  43. if (do_vmclear_operation)
  44. do_vmclear_operation();
  45. rcu_read_unlock();
  46. }
  47. #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
  48. static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
  49. {
  50. #ifdef CONFIG_X86_32
  51. struct pt_regs fixed_regs;
  52. #endif
  53. #ifdef CONFIG_X86_32
  54. if (!user_mode_vm(regs)) {
  55. crash_fixup_ss_esp(&fixed_regs, regs);
  56. regs = &fixed_regs;
  57. }
  58. #endif
  59. crash_save_cpu(regs, cpu);
  60. /*
  61. * VMCLEAR VMCSs loaded on all cpus if needed.
  62. */
  63. cpu_crash_vmclear_loaded_vmcss();
  64. /* Disable VMX or SVM if needed.
  65. *
  66. * We need to disable virtualization on all CPUs.
  67. * Having VMX or SVM enabled on any CPU may break rebooting
  68. * after the kdump kernel has finished its task.
  69. */
  70. cpu_emergency_vmxoff();
  71. cpu_emergency_svm_disable();
  72. disable_local_APIC();
  73. }
  74. static void kdump_nmi_shootdown_cpus(void)
  75. {
  76. in_crash_kexec = 1;
  77. nmi_shootdown_cpus(kdump_nmi_callback);
  78. disable_local_APIC();
  79. }
  80. #else
  81. static void kdump_nmi_shootdown_cpus(void)
  82. {
  83. /* There are no cpus to shootdown */
  84. }
  85. #endif
  86. void native_machine_crash_shutdown(struct pt_regs *regs)
  87. {
  88. /* This function is only called after the system
  89. * has panicked or is otherwise in a critical state.
  90. * The minimum amount of code to allow a kexec'd kernel
  91. * to run successfully needs to happen here.
  92. *
  93. * In practice this means shooting down the other cpus in
  94. * an SMP system.
  95. */
  96. /* The kernel is broken so disable interrupts */
  97. local_irq_disable();
  98. kdump_nmi_shootdown_cpus();
  99. /*
  100. * VMCLEAR VMCSs loaded on this cpu if needed.
  101. */
  102. cpu_crash_vmclear_loaded_vmcss();
  103. /* Booting kdump kernel with VMX or SVM enabled won't work,
  104. * because (among other limitations) we can't disable paging
  105. * with the virt flags.
  106. */
  107. cpu_emergency_vmxoff();
  108. cpu_emergency_svm_disable();
  109. #ifdef CONFIG_X86_IO_APIC
  110. /* Prevent crash_kexec() from deadlocking on ioapic_lock. */
  111. ioapic_zap_locks();
  112. disable_IO_APIC();
  113. #endif
  114. lapic_shutdown();
  115. #ifdef CONFIG_HPET_TIMER
  116. hpet_disable();
  117. #endif
  118. crash_save_cpu(regs, safe_smp_processor_id());
  119. }