Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 1 | /* |
Hiroshi Shimamoto | 62a31a0 | 2007-10-19 18:24:20 -0700 | [diff] [blame] | 2 | * Architecture specific (i386/x86_64) functions for kexec based crash dumps. |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 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> |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 14 | #include <linux/reboot.h> |
| 15 | #include <linux/kexec.h> |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/elf.h> |
| 18 | #include <linux/elfcore.h> |
Zhang Yanfei | f23d1f4 | 2012-12-06 23:40:47 +0800 | [diff] [blame] | 19 | #include <linux/module.h> |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/processor.h> |
| 22 | #include <asm/hardirq.h> |
| 23 | #include <asm/nmi.h> |
| 24 | #include <asm/hw_irq.h> |
Vivek Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 25 | #include <asm/apic.h> |
OGAWA Hirofumi | 0c1b272 | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 26 | #include <asm/hpet.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 27 | #include <linux/kdebug.h> |
Jaswinder Singh Rajput | 96b89dc6 | 2009-01-07 21:35:48 +0530 | [diff] [blame] | 28 | #include <asm/cpu.h> |
Glauber Costa | ed23dc6 | 2008-03-17 16:08:38 -0300 | [diff] [blame] | 29 | #include <asm/reboot.h> |
Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 30 | #include <asm/virtext.h> |
Eduardo Habkost | 8e29478 | 2008-11-12 11:34:40 -0200 | [diff] [blame] | 31 | |
Cliff Wickman | 5edd19a | 2010-07-20 18:09:05 -0500 | [diff] [blame] | 32 | int in_crash_kexec; |
| 33 | |
Zhang Yanfei | f23d1f4 | 2012-12-06 23:40:47 +0800 | [diff] [blame] | 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 | */ |
Zhang Yanfei | 0ca0d81 | 2012-12-11 17:11:34 +0800 | [diff] [blame] | 41 | crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL; |
Zhang Yanfei | f23d1f4 | 2012-12-06 23:40:47 +0800 | [diff] [blame] | 42 | EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss); |
| 43 | |
| 44 | static inline void cpu_crash_vmclear_loaded_vmcss(void) |
| 45 | { |
Zhang Yanfei | 0ca0d81 | 2012-12-11 17:11:34 +0800 | [diff] [blame] | 46 | crash_vmclear_fn *do_vmclear_operation = NULL; |
Zhang Yanfei | f23d1f4 | 2012-12-06 23:40:47 +0800 | [diff] [blame] | 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 | |
Eduardo Habkost | b2bbe71 | 2008-11-12 11:34:38 -0200 | [diff] [blame] | 55 | #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC) |
| 56 | |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 57 | static void kdump_nmi_callback(int cpu, struct pt_regs *regs) |
Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 58 | { |
Mike Galbraith | 1fb473d | 2007-10-24 12:58:01 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_X86_32 |
Vivek Goyal | 4d55476 | 2005-06-25 14:58:13 -0700 | [diff] [blame] | 60 | struct pt_regs fixed_regs; |
Hiroshi Shimamoto | 62a31a0 | 2007-10-19 18:24:20 -0700 | [diff] [blame] | 61 | #endif |
Eduardo Habkost | a7d4182 | 2008-11-12 11:34:37 -0200 | [diff] [blame] | 62 | |
Eduardo Habkost | a7d4182 | 2008-11-12 11:34:37 -0200 | [diff] [blame] | 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 | |
Zhang Yanfei | f23d1f4 | 2012-12-06 23:40:47 +0800 | [diff] [blame] | 71 | /* |
| 72 | * VMCLEAR VMCSs loaded on all cpus if needed. |
| 73 | */ |
| 74 | cpu_crash_vmclear_loaded_vmcss(); |
| 75 | |
Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 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 | |
Eduardo Habkost | a7d4182 | 2008-11-12 11:34:37 -0200 | [diff] [blame] | 85 | disable_local_APIC(); |
| 86 | } |
| 87 | |
Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 88 | static void kdump_nmi_shootdown_cpus(void) |
| 89 | { |
Cliff Wickman | 5edd19a | 2010-07-20 18:09:05 -0500 | [diff] [blame] | 90 | in_crash_kexec = 1; |
Eduardo Habkost | 8e29478 | 2008-11-12 11:34:40 -0200 | [diff] [blame] | 91 | nmi_shootdown_cpus(kdump_nmi_callback); |
Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 92 | |
Vivek Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 93 | disable_local_APIC(); |
Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 94 | } |
Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 95 | |
Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 96 | #else |
Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 97 | static void kdump_nmi_shootdown_cpus(void) |
Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 98 | { |
| 99 | /* There are no cpus to shootdown */ |
| 100 | } |
| 101 | #endif |
| 102 | |
Glauber Costa | ed23dc6 | 2008-03-17 16:08:38 -0300 | [diff] [blame] | 103 | void native_machine_crash_shutdown(struct pt_regs *regs) |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 104 | { |
| 105 | /* This function is only called after the system |
Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 106 | * has panicked or is otherwise in a critical state. |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 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 | */ |
Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 113 | /* The kernel is broken so disable interrupts */ |
| 114 | local_irq_disable(); |
Vivek Goyal | a3ea8ac | 2005-06-25 14:58:14 -0700 | [diff] [blame] | 115 | |
Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 116 | kdump_nmi_shootdown_cpus(); |
Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 117 | |
Zhang Yanfei | f23d1f4 | 2012-12-06 23:40:47 +0800 | [diff] [blame] | 118 | /* |
| 119 | * VMCLEAR VMCSs loaded on this cpu if needed. |
| 120 | */ |
| 121 | cpu_crash_vmclear_loaded_vmcss(); |
| 122 | |
Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 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 | |
Vivek Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 130 | lapic_shutdown(); |
Yoshihiro YUNOMAE | 1740545 | 2013-08-20 16:01:07 +0900 | [diff] [blame^] | 131 | #ifdef CONFIG_X86_IO_APIC |
| 132 | /* Prevent crash_kexec() from deadlocking on ioapic_lock. */ |
| 133 | ioapic_zap_locks(); |
Vivek Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 134 | disable_IO_APIC(); |
| 135 | #endif |
OGAWA Hirofumi | 0c1b272 | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 136 | #ifdef CONFIG_HPET_TIMER |
| 137 | hpet_disable(); |
| 138 | #endif |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 139 | crash_save_cpu(regs, safe_smp_processor_id()); |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 140 | } |