blob: e0e0841eef45dcf4381e28a9618a9c1db203df05 [file] [log] [blame]
Eric W. Biederman5033cba2005-06-25 14:57:56 -07001/*
Hiroshi Shimamoto62a31a02007-10-19 18:24:20 -07002 * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
Eric W. Biederman5033cba2005-06-25 14:57:56 -07003 *
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>
Eric W. Biederman5033cba2005-06-25 14:57:56 -070014#include <linux/reboot.h>
15#include <linux/kexec.h>
Eric W. Biederman5033cba2005-06-25 14:57:56 -070016#include <linux/delay.h>
17#include <linux/elf.h>
18#include <linux/elfcore.h>
Zhang Yanfeif23d1f42012-12-06 23:40:47 +080019#include <linux/module.h>
Eric W. Biederman5033cba2005-06-25 14:57:56 -070020
21#include <asm/processor.h>
22#include <asm/hardirq.h>
23#include <asm/nmi.h>
24#include <asm/hw_irq.h>
Vivek Goyal19842d62005-11-15 00:09:04 -080025#include <asm/apic.h>
OGAWA Hirofumi0c1b2722007-12-03 17:17:10 +010026#include <asm/hpet.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070027#include <linux/kdebug.h>
Jaswinder Singh Rajput96b89dc62009-01-07 21:35:48 +053028#include <asm/cpu.h>
Glauber Costaed23dc62008-03-17 16:08:38 -030029#include <asm/reboot.h>
Eduardo Habkost2340b622008-11-17 19:03:23 -020030#include <asm/virtext.h>
Eduardo Habkost8e294782008-11-12 11:34:40 -020031
Cliff Wickman5edd19a2010-07-20 18:09:05 -050032int in_crash_kexec;
33
Zhang Yanfeif23d1f42012-12-06 23:40:47 +080034/*
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 */
Zhang Yanfei0ca0d812012-12-11 17:11:34 +080041crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL;
Zhang Yanfeif23d1f42012-12-06 23:40:47 +080042EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
43
44static inline void cpu_crash_vmclear_loaded_vmcss(void)
45{
Zhang Yanfei0ca0d812012-12-11 17:11:34 +080046 crash_vmclear_fn *do_vmclear_operation = NULL;
Zhang Yanfeif23d1f42012-12-06 23:40:47 +080047
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
Eduardo Habkostb2bbe712008-11-12 11:34:38 -020055#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
56
Don Zickus9c48f1c2011-09-30 15:06:21 -040057static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070058{
Mike Galbraith1fb473d2007-10-24 12:58:01 +020059#ifdef CONFIG_X86_32
Vivek Goyal4d554762005-06-25 14:58:13 -070060 struct pt_regs fixed_regs;
Hiroshi Shimamoto62a31a02007-10-19 18:24:20 -070061#endif
Eduardo Habkosta7d41822008-11-12 11:34:37 -020062
Eduardo Habkosta7d41822008-11-12 11:34:37 -020063#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
Zhang Yanfeif23d1f42012-12-06 23:40:47 +080071 /*
72 * VMCLEAR VMCSs loaded on all cpus if needed.
73 */
74 cpu_crash_vmclear_loaded_vmcss();
75
Eduardo Habkost2340b622008-11-17 19:03:23 -020076 /* 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
Eduardo Habkosta7d41822008-11-12 11:34:37 -020085 disable_local_APIC();
86}
87
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020088static void kdump_nmi_shootdown_cpus(void)
89{
Cliff Wickman5edd19a2010-07-20 18:09:05 -050090 in_crash_kexec = 1;
Eduardo Habkost8e294782008-11-12 11:34:40 -020091 nmi_shootdown_cpus(kdump_nmi_callback);
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020092
Vivek Goyal19842d62005-11-15 00:09:04 -080093 disable_local_APIC();
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070094}
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020095
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070096#else
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020097static void kdump_nmi_shootdown_cpus(void)
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070098{
99 /* There are no cpus to shootdown */
100}
101#endif
102
Glauber Costaed23dc62008-03-17 16:08:38 -0300103void native_machine_crash_shutdown(struct pt_regs *regs)
Eric W. Biederman5033cba2005-06-25 14:57:56 -0700104{
105 /* This function is only called after the system
Lee Revellf18190b2006-06-26 18:30:00 +0200106 * has panicked or is otherwise in a critical state.
Eric W. Biederman5033cba2005-06-25 14:57:56 -0700107 * 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 */
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -0700113 /* The kernel is broken so disable interrupts */
114 local_irq_disable();
Vivek Goyala3ea8ac2005-06-25 14:58:14 -0700115
Eduardo Habkostd1e7b912008-11-12 11:34:39 -0200116 kdump_nmi_shootdown_cpus();
Eduardo Habkost2340b622008-11-17 19:03:23 -0200117
Zhang Yanfeif23d1f42012-12-06 23:40:47 +0800118 /*
119 * VMCLEAR VMCSs loaded on this cpu if needed.
120 */
121 cpu_crash_vmclear_loaded_vmcss();
122
Eduardo Habkost2340b622008-11-17 19:03:23 -0200123 /* 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
Vivek Goyal19842d62005-11-15 00:09:04 -0800130 lapic_shutdown();
Yoshihiro YUNOMAE17405452013-08-20 16:01:07 +0900131#ifdef CONFIG_X86_IO_APIC
132 /* Prevent crash_kexec() from deadlocking on ioapic_lock. */
133 ioapic_zap_locks();
Vivek Goyal19842d62005-11-15 00:09:04 -0800134 disable_IO_APIC();
135#endif
OGAWA Hirofumi0c1b2722007-12-03 17:17:10 +0100136#ifdef CONFIG_HPET_TIMER
137 hpet_disable();
138#endif
Magnus Damm85916f82006-12-06 20:40:41 -0800139 crash_save_cpu(regs, safe_smp_processor_id());
Eric W. Biederman5033cba2005-06-25 14:57:56 -0700140}