crash.c 3.1 KB

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