Merge tag 'for-3.8' of git://openrisc.net/~jonas/linux
[deliverable/linux.git] / arch / x86 / kernel / crash.c
CommitLineData
5033cba0 1/*
62a31a03 2 * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
5033cba0
EB
3 *
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
5 *
6 * Copyright (C) IBM Corporation, 2004. All rights reserved.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/smp.h>
5033cba0
EB
14#include <linux/reboot.h>
15#include <linux/kexec.h>
5033cba0
EB
16#include <linux/delay.h>
17#include <linux/elf.h>
18#include <linux/elfcore.h>
f23d1f4a 19#include <linux/module.h>
5033cba0
EB
20
21#include <asm/processor.h>
22#include <asm/hardirq.h>
23#include <asm/nmi.h>
24#include <asm/hw_irq.h>
19842d67 25#include <asm/apic.h>
0c1b2724 26#include <asm/hpet.h>
1eeb66a1 27#include <linux/kdebug.h>
96b89dc6 28#include <asm/cpu.h>
ed23dc6f 29#include <asm/reboot.h>
2340b62f 30#include <asm/virtext.h>
8e294786 31
5edd19af
CW
32int in_crash_kexec;
33
f23d1f4a
ZY
34/*
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.
38 *
39 * protected by rcu.
40 */
0ca0d818 41crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL;
f23d1f4a
ZY
42EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
43
44static inline void cpu_crash_vmclear_loaded_vmcss(void)
45{
0ca0d818 46 crash_vmclear_fn *do_vmclear_operation = NULL;
f23d1f4a
ZY
47
48 rcu_read_lock();
49 do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
50 if (do_vmclear_operation)
51 do_vmclear_operation();
52 rcu_read_unlock();
53}
54
b2bbe71b
EH
55#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
56
9c48f1c6 57static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
c4ac4263 58{
1fb473d8 59#ifdef CONFIG_X86_32
4d55476c 60 struct pt_regs fixed_regs;
62a31a03 61#endif
a7d41820 62
a7d41820
EH
63#ifdef CONFIG_X86_32
64 if (!user_mode_vm(regs)) {
65 crash_fixup_ss_esp(&fixed_regs, regs);
66 regs = &fixed_regs;
67 }
68#endif
69 crash_save_cpu(regs, cpu);
70
f23d1f4a
ZY
71 /*
72 * VMCLEAR VMCSs loaded on all cpus if needed.
73 */
74 cpu_crash_vmclear_loaded_vmcss();
75
2340b62f
EH
76 /* Disable VMX or SVM if needed.
77 *
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.
81 */
82 cpu_emergency_vmxoff();
83 cpu_emergency_svm_disable();
84
a7d41820
EH
85 disable_local_APIC();
86}
87
d1e7b91c
EH
88static void kdump_nmi_shootdown_cpus(void)
89{
5edd19af 90 in_crash_kexec = 1;
8e294786 91 nmi_shootdown_cpus(kdump_nmi_callback);
d1e7b91c 92
19842d67 93 disable_local_APIC();
c4ac4263 94}
d1e7b91c 95
c4ac4263 96#else
d1e7b91c 97static void kdump_nmi_shootdown_cpus(void)
c4ac4263
EB
98{
99 /* There are no cpus to shootdown */
100}
101#endif
102
ed23dc6f 103void native_machine_crash_shutdown(struct pt_regs *regs)
5033cba0
EB
104{
105 /* This function is only called after the system
f18190bd 106 * has panicked or is otherwise in a critical state.
5033cba0
EB
107 * The minimum amount of code to allow a kexec'd kernel
108 * to run successfully needs to happen here.
109 *
110 * In practice this means shooting down the other cpus in
111 * an SMP system.
112 */
c4ac4263
EB
113 /* The kernel is broken so disable interrupts */
114 local_irq_disable();
a3ea8ac8 115
d1e7b91c 116 kdump_nmi_shootdown_cpus();
2340b62f 117
f23d1f4a
ZY
118 /*
119 * VMCLEAR VMCSs loaded on this cpu if needed.
120 */
121 cpu_crash_vmclear_loaded_vmcss();
122
2340b62f
EH
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.
126 */
127 cpu_emergency_vmxoff();
128 cpu_emergency_svm_disable();
129
19842d67
VG
130 lapic_shutdown();
131#if defined(CONFIG_X86_IO_APIC)
132 disable_IO_APIC();
0c1b2724
OH
133#endif
134#ifdef CONFIG_HPET_TIMER
135 hpet_disable();
19842d67 136#endif
85916f81 137 crash_save_cpu(regs, safe_smp_processor_id());
5033cba0 138}
This page took 0.867874 seconds and 5 git commands to generate.