2 * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
6 * Copyright (C) IBM Corporation, 2004. All rights reserved.
10 #include <linux/init.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/smp.h>
14 #include <linux/reboot.h>
15 #include <linux/kexec.h>
16 #include <linux/delay.h>
17 #include <linux/elf.h>
18 #include <linux/elfcore.h>
19 #include <linux/module.h>
21 #include <asm/processor.h>
22 #include <asm/hardirq.h>
24 #include <asm/hw_irq.h>
27 #include <linux/kdebug.h>
29 #include <asm/reboot.h>
30 #include <asm/virtext.h>
35 * This is used to VMCLEAR all VMCSs loaded on the
36 * processor. And when loading kvm_intel module, the
37 * callback function pointer will be assigned.
41 crash_vmclear_fn __rcu
*crash_vmclear_loaded_vmcss
= NULL
;
42 EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss
);
44 static inline void cpu_crash_vmclear_loaded_vmcss(void)
46 crash_vmclear_fn
*do_vmclear_operation
= NULL
;
49 do_vmclear_operation
= rcu_dereference(crash_vmclear_loaded_vmcss
);
50 if (do_vmclear_operation
)
51 do_vmclear_operation();
55 #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
57 static void kdump_nmi_callback(int cpu
, struct pt_regs
*regs
)
60 struct pt_regs fixed_regs
;
64 if (!user_mode_vm(regs
)) {
65 crash_fixup_ss_esp(&fixed_regs
, regs
);
69 crash_save_cpu(regs
, cpu
);
72 * VMCLEAR VMCSs loaded on all cpus if needed.
74 cpu_crash_vmclear_loaded_vmcss();
76 /* Disable VMX or SVM if needed.
78 * We need to disable virtualization on all CPUs.
79 * Having VMX or SVM enabled on any CPU may break rebooting
80 * after the kdump kernel has finished its task.
82 cpu_emergency_vmxoff();
83 cpu_emergency_svm_disable();
88 static void kdump_nmi_shootdown_cpus(void)
91 nmi_shootdown_cpus(kdump_nmi_callback
);
97 static void kdump_nmi_shootdown_cpus(void)
99 /* There are no cpus to shootdown */
103 void native_machine_crash_shutdown(struct pt_regs
*regs
)
105 /* This function is only called after the system
106 * has panicked or is otherwise in a critical state.
107 * The minimum amount of code to allow a kexec'd kernel
108 * to run successfully needs to happen here.
110 * In practice this means shooting down the other cpus in
113 /* The kernel is broken so disable interrupts */
116 kdump_nmi_shootdown_cpus();
119 * VMCLEAR VMCSs loaded on this cpu if needed.
121 cpu_crash_vmclear_loaded_vmcss();
123 /* Booting kdump kernel with VMX or SVM enabled won't work,
124 * because (among other limitations) we can't disable paging
125 * with the virt flags.
127 cpu_emergency_vmxoff();
128 cpu_emergency_svm_disable();
131 #if defined(CONFIG_X86_IO_APIC)
134 #ifdef CONFIG_HPET_TIMER
137 crash_save_cpu(regs
, safe_smp_processor_id());