]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/kernel/crash.c
x86, vdso: Clean up 32-bit vs 64-bit vdso params
[mirror_ubuntu-artful-kernel.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
5033cba0
EB
10#include <linux/types.h>
11#include <linux/kernel.h>
12#include <linux/smp.h>
5033cba0
EB
13#include <linux/reboot.h>
14#include <linux/kexec.h>
5033cba0
EB
15#include <linux/delay.h>
16#include <linux/elf.h>
17#include <linux/elfcore.h>
f23d1f4a 18#include <linux/module.h>
5033cba0
EB
19
20#include <asm/processor.h>
21#include <asm/hardirq.h>
22#include <asm/nmi.h>
23#include <asm/hw_irq.h>
19842d67 24#include <asm/apic.h>
0c1b2724 25#include <asm/hpet.h>
1eeb66a1 26#include <linux/kdebug.h>
96b89dc6 27#include <asm/cpu.h>
ed23dc6f 28#include <asm/reboot.h>
2340b62f 29#include <asm/virtext.h>
8e294786 30
5edd19af
CW
31int in_crash_kexec;
32
f23d1f4a
ZY
33/*
34 * This is used to VMCLEAR all VMCSs loaded on the
35 * processor. And when loading kvm_intel module, the
36 * callback function pointer will be assigned.
37 *
38 * protected by rcu.
39 */
0ca0d818 40crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL;
f23d1f4a
ZY
41EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
42
43static inline void cpu_crash_vmclear_loaded_vmcss(void)
44{
0ca0d818 45 crash_vmclear_fn *do_vmclear_operation = NULL;
f23d1f4a
ZY
46
47 rcu_read_lock();
48 do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
49 if (do_vmclear_operation)
50 do_vmclear_operation();
51 rcu_read_unlock();
52}
53
b2bbe71b
EH
54#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
55
9c48f1c6 56static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
c4ac4263 57{
1fb473d8 58#ifdef CONFIG_X86_32
4d55476c 59 struct pt_regs fixed_regs;
a7d41820 60
a7d41820
EH
61 if (!user_mode_vm(regs)) {
62 crash_fixup_ss_esp(&fixed_regs, regs);
63 regs = &fixed_regs;
64 }
65#endif
66 crash_save_cpu(regs, cpu);
67
f23d1f4a
ZY
68 /*
69 * VMCLEAR VMCSs loaded on all cpus if needed.
70 */
71 cpu_crash_vmclear_loaded_vmcss();
72
2340b62f
EH
73 /* Disable VMX or SVM if needed.
74 *
75 * We need to disable virtualization on all CPUs.
76 * Having VMX or SVM enabled on any CPU may break rebooting
77 * after the kdump kernel has finished its task.
78 */
79 cpu_emergency_vmxoff();
80 cpu_emergency_svm_disable();
81
a7d41820
EH
82 disable_local_APIC();
83}
84
d1e7b91c
EH
85static void kdump_nmi_shootdown_cpus(void)
86{
5edd19af 87 in_crash_kexec = 1;
8e294786 88 nmi_shootdown_cpus(kdump_nmi_callback);
d1e7b91c 89
19842d67 90 disable_local_APIC();
c4ac4263 91}
d1e7b91c 92
c4ac4263 93#else
d1e7b91c 94static void kdump_nmi_shootdown_cpus(void)
c4ac4263
EB
95{
96 /* There are no cpus to shootdown */
97}
98#endif
99
ed23dc6f 100void native_machine_crash_shutdown(struct pt_regs *regs)
5033cba0
EB
101{
102 /* This function is only called after the system
f18190bd 103 * has panicked or is otherwise in a critical state.
5033cba0
EB
104 * The minimum amount of code to allow a kexec'd kernel
105 * to run successfully needs to happen here.
106 *
107 * In practice this means shooting down the other cpus in
108 * an SMP system.
109 */
c4ac4263
EB
110 /* The kernel is broken so disable interrupts */
111 local_irq_disable();
a3ea8ac8 112
d1e7b91c 113 kdump_nmi_shootdown_cpus();
2340b62f 114
f23d1f4a
ZY
115 /*
116 * VMCLEAR VMCSs loaded on this cpu if needed.
117 */
118 cpu_crash_vmclear_loaded_vmcss();
119
2340b62f
EH
120 /* Booting kdump kernel with VMX or SVM enabled won't work,
121 * because (among other limitations) we can't disable paging
122 * with the virt flags.
123 */
124 cpu_emergency_vmxoff();
125 cpu_emergency_svm_disable();
126
17405453
YY
127#ifdef CONFIG_X86_IO_APIC
128 /* Prevent crash_kexec() from deadlocking on ioapic_lock. */
129 ioapic_zap_locks();
19842d67 130 disable_IO_APIC();
0c1b2724 131#endif
522e6646 132 lapic_shutdown();
0c1b2724
OH
133#ifdef CONFIG_HPET_TIMER
134 hpet_disable();
19842d67 135#endif
85916f81 136 crash_save_cpu(regs, safe_smp_processor_id());
5033cba0 137}