crash.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. if (!user_mode_vm(regs)) {
  53. crash_fixup_ss_esp(&fixed_regs, regs);
  54. regs = &fixed_regs;
  55. }
  56. #endif
  57. crash_save_cpu(regs, cpu);
  58. /*
  59. * VMCLEAR VMCSs loaded on all cpus if needed.
  60. */
  61. cpu_crash_vmclear_loaded_vmcss();
  62. /* Disable VMX or SVM if needed.
  63. *
  64. * We need to disable virtualization on all CPUs.
  65. * Having VMX or SVM enabled on any CPU may break rebooting
  66. * after the kdump kernel has finished its task.
  67. */
  68. cpu_emergency_vmxoff();
  69. cpu_emergency_svm_disable();
  70. disable_local_APIC();
  71. }
  72. static void kdump_nmi_shootdown_cpus(void)
  73. {
  74. in_crash_kexec = 1;
  75. nmi_shootdown_cpus(kdump_nmi_callback);
  76. disable_local_APIC();
  77. }
  78. #else
  79. static void kdump_nmi_shootdown_cpus(void)
  80. {
  81. /* There are no cpus to shootdown */
  82. }
  83. #endif
  84. void native_machine_crash_shutdown(struct pt_regs *regs)
  85. {
  86. /* This function is only called after the system
  87. * has panicked or is otherwise in a critical state.
  88. * The minimum amount of code to allow a kexec'd kernel
  89. * to run successfully needs to happen here.
  90. *
  91. * In practice this means shooting down the other cpus in
  92. * an SMP system.
  93. */
  94. /* The kernel is broken so disable interrupts */
  95. local_irq_disable();
  96. kdump_nmi_shootdown_cpus();
  97. /*
  98. * VMCLEAR VMCSs loaded on this cpu if needed.
  99. */
  100. cpu_crash_vmclear_loaded_vmcss();
  101. /* Booting kdump kernel with VMX or SVM enabled won't work,
  102. * because (among other limitations) we can't disable paging
  103. * with the virt flags.
  104. */
  105. cpu_emergency_vmxoff();
  106. cpu_emergency_svm_disable();
  107. #ifdef CONFIG_X86_IO_APIC
  108. /* Prevent crash_kexec() from deadlocking on ioapic_lock. */
  109. ioapic_zap_locks();
  110. disable_IO_APIC();
  111. #endif
  112. lapic_shutdown();
  113. #ifdef CONFIG_HPET_TIMER
  114. hpet_disable();
  115. #endif
  116. crash_save_cpu(regs, safe_smp_processor_id());
  117. }