Commit c0ce7d08 authored by David Wilder's avatar David Wilder Committed by Paul Mackerras

[POWERPC] Add the use of the firmware soft-reset-nmi to kdump.

With this patch, kdump uses the firmware soft-reset NMI for two purposes:
1) Initiate the kdump (take a crash dump) by issuing a soft-reset.
2) Break a CPU out of a deadlock condition that is detected during kdump
processing.

When a soft-reset is initiated each CPU will enter
system_reset_exception() and set its corresponding bit in the global
bit-array cpus_in_sr then call die(). When die() finds the CPU's bit set
in cpu_in_sr crash_kexec() is called to initiate a crash dump. The first
CPU to enter crash_kexec() is called the "crashing CPU". All other CPUs
are "secondary CPUs". The secondary CPU's pass through to
crash_kexec_secondary() and sleep. The crashing CPU waits for all CPUs
to enter via soft-reset then boots the kdump kernel (see
crash_soft_reset_check())

When the system crashes due to a panic or exception, crash_kexec() is
called by panic() or die(). The crashing CPU sends an IPI to all other
CPUs to notify them of the pending shutdown. If a CPU is in a deadlock
or hung state with interrupts disabled, the IPI will not be delivered.
The result being, that the kdump kernel is not booted. This problem is
solved with the use of a firmware generated soft-reset. After the
crashing_cpu has issued the IPI, it waits for 10 sec for all CPUs to
enter crash_ipi_callback(). A CPU signifies its entry to
crash_ipi_callback() by setting its corresponding bit in the
cpus_in_crash bit array. After 10 sec, if one or more CPUs have not set
their bit in cpus_in_crash we assume that the CPU(s) is deadlocked. The
operator is then prompted to generate a soft-reset to break the
deadlock. Each CPU enters the soft reset handler as described above.

Two conditions must be handled at this point:
1) The system crashed because the operator generated a soft-reset. See
2) The system had crashed before the soft-reset was generated ( in the
case of a Panic or oops).

The first CPU to enter crash_kexec() uses the state of the kexec_lock to
determine this state. If kexec_lock is already held then condition 2 is
true and crash_kexec_secondary() is called, else; this CPU is flagged as
the crashing CPU, the kexec_lock is acquired and crash_kexec() proceeds
as described above.

Each additional CPUs responding to the soft-reset will pass through
crash_kexec() to kexec_secondary(). All secondary CPUs call
crash_ipi_callback() readying them self's for the shutdown. When ready
they clear their bit in cpus_in_sr. The crashing CPU waits in
kexec_secondary() until all other CPUs have cleared their bits in
cpus_in_sr. The kexec kernel boot is then started.
Signed-off-by: default avatarHaren Myneni <haren@us.ibm.com>
Signed-off-by: default avatarDavid Wilder <dwilder@us.ibm.com>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 2cd90bc8
...@@ -24,9 +24,11 @@ ...@@ -24,9 +24,11 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/irq.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/machdep.h> #include <asm/machdep.h>
#include <asm/kexec.h>
#include <asm/kdump.h> #include <asm/kdump.h>
#include <asm/lmb.h> #include <asm/lmb.h>
#include <asm/firmware.h> #include <asm/firmware.h>
...@@ -41,6 +43,7 @@ ...@@ -41,6 +43,7 @@
/* This keeps a track of which one is crashing cpu. */ /* This keeps a track of which one is crashing cpu. */
int crashing_cpu = -1; int crashing_cpu = -1;
static cpumask_t cpus_in_crash = CPU_MASK_NONE;
static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data, static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
size_t data_len) size_t data_len)
...@@ -98,34 +101,66 @@ static void crash_save_this_cpu(struct pt_regs *regs, int cpu) ...@@ -98,34 +101,66 @@ static void crash_save_this_cpu(struct pt_regs *regs, int cpu)
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
static atomic_t waiting_for_crash_ipi; static atomic_t enter_on_soft_reset = ATOMIC_INIT(0);
void crash_ipi_callback(struct pt_regs *regs) void crash_ipi_callback(struct pt_regs *regs)
{ {
int cpu = smp_processor_id(); int cpu = smp_processor_id();
if (cpu == crashing_cpu)
return;
if (!cpu_online(cpu)) if (!cpu_online(cpu))
return; return;
if (ppc_md.kexec_cpu_down)
ppc_md.kexec_cpu_down(1, 1);
local_irq_disable(); local_irq_disable();
if (!cpu_isset(cpu, cpus_in_crash))
crash_save_this_cpu(regs, cpu); crash_save_this_cpu(regs, cpu);
atomic_dec(&waiting_for_crash_ipi); cpu_set(cpu, cpus_in_crash);
/*
* Entered via soft-reset - could be the kdump
* process is invoked using soft-reset or user activated
* it if some CPU did not respond to an IPI.
* For soft-reset, the secondary CPU can enter this func
* twice. 1 - using IPI, and 2. soft-reset.
* Tell the kexec CPU that entered via soft-reset and ready
* to go down.
*/
if (cpu_isset(cpu, cpus_in_sr)) {
cpu_clear(cpu, cpus_in_sr);
atomic_inc(&enter_on_soft_reset);
}
/*
* Starting the kdump boot.
* This barrier is needed to make sure that all CPUs are stopped.
* If not, soft-reset will be invoked to bring other CPUs.
*/
while (!cpu_isset(crashing_cpu, cpus_in_crash))
cpu_relax();
if (ppc_md.kexec_cpu_down)
ppc_md.kexec_cpu_down(1, 1);
kexec_smp_wait(); kexec_smp_wait();
/* NOTREACHED */ /* NOTREACHED */
} }
static void crash_kexec_prepare_cpus(void) /*
* Wait until all CPUs are entered via soft-reset.
*/
static void crash_soft_reset_check(int cpu)
{
unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
cpu_clear(cpu, cpus_in_sr);
while (atomic_read(&enter_on_soft_reset) != ncpus)
cpu_relax();
}
static void crash_kexec_prepare_cpus(int cpu)
{ {
unsigned int msecs; unsigned int msecs;
atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
crash_send_ipi(crash_ipi_callback); crash_send_ipi(crash_ipi_callback);
smp_wmb(); smp_wmb();
...@@ -133,14 +168,13 @@ static void crash_kexec_prepare_cpus(void) ...@@ -133,14 +168,13 @@ static void crash_kexec_prepare_cpus(void)
/* /*
* FIXME: Until we will have the way to stop other CPUSs reliabally, * FIXME: Until we will have the way to stop other CPUSs reliabally,
* the crash CPU will send an IPI and wait for other CPUs to * the crash CPU will send an IPI and wait for other CPUs to
* respond. If not, proceed the kexec boot even though we failed to * respond.
* capture other CPU states.
* Delay of at least 10 seconds. * Delay of at least 10 seconds.
*/ */
printk(KERN_ALERT "Sending IPI to other cpus...\n"); printk(KERN_EMERG "Sending IPI to other cpus...\n");
msecs = 10000; msecs = 10000;
while ((atomic_read(&waiting_for_crash_ipi) > 0) && (--msecs > 0)) { while ((cpus_weight(cpus_in_crash) < ncpus) && (--msecs > 0)) {
barrier(); cpu_relax();
mdelay(1); mdelay(1);
} }
...@@ -149,18 +183,71 @@ static void crash_kexec_prepare_cpus(void) ...@@ -149,18 +183,71 @@ static void crash_kexec_prepare_cpus(void)
/* /*
* FIXME: In case if we do not get all CPUs, one possibility: ask the * FIXME: In case if we do not get all CPUs, one possibility: ask the
* user to do soft reset such that we get all. * user to do soft reset such that we get all.
* IPI handler is already set by the panic cpu initially. Therefore, * Soft-reset will be used until better mechanism is implemented.
* all cpus could invoke this handler from die() and the panic CPU */
* will call machine_kexec() directly from this handler to do if (cpus_weight(cpus_in_crash) < ncpus) {
* kexec boot. printk(KERN_EMERG "done waiting: %d cpu(s) not responding\n",
ncpus - cpus_weight(cpus_in_crash));
printk(KERN_EMERG "Activate soft-reset to stop other cpu(s)\n");
cpus_in_sr = CPU_MASK_NONE;
atomic_set(&enter_on_soft_reset, 0);
while (cpus_weight(cpus_in_crash) < ncpus)
cpu_relax();
}
/*
* Make sure all CPUs are entered via soft-reset if the kdump is
* invoked using soft-reset.
*/ */
if (atomic_read(&waiting_for_crash_ipi)) if (cpu_isset(cpu, cpus_in_sr))
printk(KERN_ALERT "done waiting: %d cpus not responding\n", crash_soft_reset_check(cpu);
atomic_read(&waiting_for_crash_ipi));
/* Leave the IPI callback set */ /* Leave the IPI callback set */
} }
/*
* This function will be called by secondary cpus or by kexec cpu
* if soft-reset is activated to stop some CPUs.
*/
void crash_kexec_secondary(struct pt_regs *regs)
{
int cpu = smp_processor_id();
unsigned long flags;
int msecs = 5;
local_irq_save(flags);
/* Wait 5ms if the kexec CPU is not entered yet. */
while (crashing_cpu < 0) {
if (--msecs < 0) {
/*
* Either kdump image is not loaded or
* kdump process is not started - Probably xmon
* exited using 'x'(exit and recover) or
* kexec_should_crash() failed for all running tasks.
*/
cpu_clear(cpu, cpus_in_sr);
local_irq_restore(flags);
return;
}
mdelay(1);
cpu_relax();
}
if (cpu == crashing_cpu) {
/*
* Panic CPU will enter this func only via soft-reset.
* Wait until all secondary CPUs entered and
* then start kexec boot.
*/
crash_soft_reset_check(cpu);
cpu_set(crashing_cpu, cpus_in_crash);
if (ppc_md.kexec_cpu_down)
ppc_md.kexec_cpu_down(1, 0);
machine_kexec(kexec_crash_image);
/* NOTREACHED */
}
crash_ipi_callback(regs);
}
#else #else
static void crash_kexec_prepare_cpus(void) static void crash_kexec_prepare_cpus(int cpu)
{ {
/* /*
* move the secondarys to us so that we can copy * move the secondarys to us so that we can copy
...@@ -171,6 +258,10 @@ static void crash_kexec_prepare_cpus(void) ...@@ -171,6 +258,10 @@ static void crash_kexec_prepare_cpus(void)
smp_release_cpus(); smp_release_cpus();
} }
void crash_kexec_secondary(struct pt_regs *regs)
{
cpus_in_sr = CPU_MASK_NONE;
}
#endif #endif
void default_machine_crash_shutdown(struct pt_regs *regs) void default_machine_crash_shutdown(struct pt_regs *regs)
...@@ -199,14 +290,14 @@ void default_machine_crash_shutdown(struct pt_regs *regs) ...@@ -199,14 +290,14 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
desc->handler->disable(irq); desc->handler->disable(irq);
} }
if (ppc_md.kexec_cpu_down)
ppc_md.kexec_cpu_down(1, 0);
/* /*
* Make a note of crashing cpu. Will be used in machine_kexec * Make a note of crashing cpu. Will be used in machine_kexec
* such that another IPI will not be sent. * such that another IPI will not be sent.
*/ */
crashing_cpu = smp_processor_id(); crashing_cpu = smp_processor_id();
crash_kexec_prepare_cpus();
crash_save_this_cpu(regs, crashing_cpu); crash_save_this_cpu(regs, crashing_cpu);
crash_kexec_prepare_cpus(crashing_cpu);
cpu_set(crashing_cpu, cpus_in_crash);
if (ppc_md.kexec_cpu_down)
ppc_md.kexec_cpu_down(1, 0);
} }
...@@ -52,9 +52,13 @@ ...@@ -52,9 +52,13 @@
#include <asm/firmware.h> #include <asm/firmware.h>
#include <asm/processor.h> #include <asm/processor.h>
#endif #endif
#include <asm/kexec.h>
#ifdef CONFIG_PPC64 /* XXX */ #ifdef CONFIG_PPC64 /* XXX */
#define _IO_BASE pci_io_base #define _IO_BASE pci_io_base
#ifdef CONFIG_KEXEC
cpumask_t cpus_in_sr = CPU_MASK_NONE;
#endif
#endif #endif
#ifdef CONFIG_DEBUGGER #ifdef CONFIG_DEBUGGER
...@@ -97,7 +101,7 @@ static DEFINE_SPINLOCK(die_lock); ...@@ -97,7 +101,7 @@ static DEFINE_SPINLOCK(die_lock);
int die(const char *str, struct pt_regs *regs, long err) int die(const char *str, struct pt_regs *regs, long err)
{ {
static int die_counter, crash_dump_start = 0; static int die_counter;
if (debugger(regs)) if (debugger(regs))
return 1; return 1;
...@@ -137,21 +141,12 @@ int die(const char *str, struct pt_regs *regs, long err) ...@@ -137,21 +141,12 @@ int die(const char *str, struct pt_regs *regs, long err)
print_modules(); print_modules();
show_regs(regs); show_regs(regs);
bust_spinlocks(0); bust_spinlocks(0);
if (!crash_dump_start && kexec_should_crash(current)) {
crash_dump_start = 1;
spin_unlock_irq(&die_lock); spin_unlock_irq(&die_lock);
if (kexec_should_crash(current) ||
kexec_sr_activated(smp_processor_id()))
crash_kexec(regs); crash_kexec(regs);
/* NOTREACHED */ crash_kexec_secondary(regs);
}
spin_unlock_irq(&die_lock);
if (crash_dump_start)
/*
* Only for soft-reset: Other CPUs will be responded to an IPI
* sent by first kexec CPU.
*/
for(;;)
;
if (in_interrupt()) if (in_interrupt())
panic("Fatal exception in interrupt"); panic("Fatal exception in interrupt");
...@@ -215,6 +210,10 @@ void system_reset_exception(struct pt_regs *regs) ...@@ -215,6 +210,10 @@ void system_reset_exception(struct pt_regs *regs)
return; return;
} }
#ifdef CONFIG_KEXEC
cpu_set(smp_processor_id(), cpus_in_sr);
#endif
die("System Reset", regs, SIGABRT); die("System Reset", regs, SIGABRT);
/* Must die if the interrupt is not recoverable */ /* Must die if the interrupt is not recoverable */
......
...@@ -114,6 +114,11 @@ extern void kexec_smp_wait(void); /* get and clear naca physid, wait for ...@@ -114,6 +114,11 @@ extern void kexec_smp_wait(void); /* get and clear naca physid, wait for
master to copy new code to 0 */ master to copy new code to 0 */
extern int crashing_cpu; extern int crashing_cpu;
extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *)); extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *));
extern cpumask_t cpus_in_sr;
static inline int kexec_sr_activated(int cpu)
{
return cpu_isset(cpu,cpus_in_sr);
}
#endif /* __powerpc64 __ */ #endif /* __powerpc64 __ */
struct kimage; struct kimage;
...@@ -123,10 +128,13 @@ extern int default_machine_kexec_prepare(struct kimage *image); ...@@ -123,10 +128,13 @@ extern int default_machine_kexec_prepare(struct kimage *image);
extern void default_machine_crash_shutdown(struct pt_regs *regs); extern void default_machine_crash_shutdown(struct pt_regs *regs);
extern void machine_kexec_simple(struct kimage *image); extern void machine_kexec_simple(struct kimage *image);
extern void crash_kexec_secondary(struct pt_regs *regs);
extern int overlaps_crashkernel(unsigned long start, unsigned long size); extern int overlaps_crashkernel(unsigned long start, unsigned long size);
extern void reserve_crashkernel(void); extern void reserve_crashkernel(void);
#else /* !CONFIG_KEXEC */ #else /* !CONFIG_KEXEC */
static inline int kexec_sr_activated(int cpu) { return 0; }
static inline void crash_kexec_secondary(struct pt_regs *regs) { }
static inline int overlaps_crashkernel(unsigned long start, unsigned long size) static inline int overlaps_crashkernel(unsigned long start, unsigned long size)
{ {
......
...@@ -1042,7 +1042,6 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry, ...@@ -1042,7 +1042,6 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
void crash_kexec(struct pt_regs *regs) void crash_kexec(struct pt_regs *regs)
{ {
struct kimage *image;
int locked; int locked;
...@@ -1056,12 +1055,11 @@ void crash_kexec(struct pt_regs *regs) ...@@ -1056,12 +1055,11 @@ void crash_kexec(struct pt_regs *regs)
*/ */
locked = xchg(&kexec_lock, 1); locked = xchg(&kexec_lock, 1);
if (!locked) { if (!locked) {
image = xchg(&kexec_crash_image, NULL); if (kexec_crash_image) {
if (image) {
struct pt_regs fixed_regs; struct pt_regs fixed_regs;
crash_setup_regs(&fixed_regs, regs); crash_setup_regs(&fixed_regs, regs);
machine_crash_shutdown(&fixed_regs); machine_crash_shutdown(&fixed_regs);
machine_kexec(image); machine_kexec(kexec_crash_image);
} }
xchg(&kexec_lock, 0); xchg(&kexec_lock, 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment