crash.c 2.4 KB
Newer Older
1
/*
H
Hiroshi Shimamoto 已提交
2
 * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
 *
 * Copyright (C) IBM Corporation, 2004. All rights reserved.
 *
 */

#include <linux/init.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/reboot.h>
#include <linux/kexec.h>
#include <linux/delay.h>
#include <linux/elf.h>
#include <linux/elfcore.h>

#include <asm/processor.h>
#include <asm/hardirq.h>
#include <asm/nmi.h>
#include <asm/hw_irq.h>
24
#include <asm/apic.h>
25
#include <asm/hpet.h>
26
#include <linux/kdebug.h>
27
#include <asm/smp.h>
28
#include <asm/reboot.h>
29
#include <asm/virtext.h>
30

31
#include <mach_ipi.h>
32

33

34 35
#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)

36
static void kdump_nmi_callback(int cpu, struct die_args *args)
37
{
38
	struct pt_regs *regs;
39
#ifdef CONFIG_X86_32
40
	struct pt_regs fixed_regs;
H
Hiroshi Shimamoto 已提交
41
#endif
42 43 44 45 46 47 48 49 50 51 52

	regs = args->regs;

#ifdef CONFIG_X86_32
	if (!user_mode_vm(regs)) {
		crash_fixup_ss_esp(&fixed_regs, regs);
		regs = &fixed_regs;
	}
#endif
	crash_save_cpu(regs, cpu);

53 54 55 56 57 58 59 60 61
	/* Disable VMX or SVM if needed.
	 *
	 * We need to disable virtualization on all CPUs.
	 * Having VMX or SVM enabled on any CPU may break rebooting
	 * after the kdump kernel has finished its task.
	 */
	cpu_emergency_vmxoff();
	cpu_emergency_svm_disable();

62 63 64
	disable_local_APIC();
}

65 66
static void kdump_nmi_shootdown_cpus(void)
{
67
	nmi_shootdown_cpus(kdump_nmi_callback);
68

69
	disable_local_APIC();
70
}
71

72
#else
73
static void kdump_nmi_shootdown_cpus(void)
74 75 76 77 78
{
	/* There are no cpus to shootdown */
}
#endif

79
void native_machine_crash_shutdown(struct pt_regs *regs)
80 81
{
	/* This function is only called after the system
L
Lee Revell 已提交
82
	 * has panicked or is otherwise in a critical state.
83 84 85 86 87 88
	 * The minimum amount of code to allow a kexec'd kernel
	 * to run successfully needs to happen here.
	 *
	 * In practice this means shooting down the other cpus in
	 * an SMP system.
	 */
89 90
	/* The kernel is broken so disable interrupts */
	local_irq_disable();
91

92
	kdump_nmi_shootdown_cpus();
93 94 95 96 97 98 99 100

	/* Booting kdump kernel with VMX or SVM enabled won't work,
	 * because (among other limitations) we can't disable paging
	 * with the virt flags.
	 */
	cpu_emergency_vmxoff();
	cpu_emergency_svm_disable();

101 102 103
	lapic_shutdown();
#if defined(CONFIG_X86_IO_APIC)
	disable_IO_APIC();
104 105 106
#endif
#ifdef CONFIG_HPET_TIMER
	hpet_disable();
107
#endif
108
	crash_save_cpu(regs, safe_smp_processor_id());
109
}