Skip to contentSkip to conversation

kexec/kdump and kdb

PATCH New Dan Aloni 1 participant 1 message May 24, 2007

Subsystems (2)
lore
Share & tools
lore

Dan Aloni

author
#0 lore raw

PATCH 1/1 kexec/kdump and kdb

Hello,

Below is a very preliminary patch that adds kexec/kdump invocation functionality in kdb. It is currently based on 2.6.20.11 and supported only for x86_64.

The main use case is for a user who would like to make use of the interactive debugger but wants to conserve the option whether to create a crash dump interactively. It also makes it possible to dump even if the kernel hasn't crashed by manually entering kdb and entering 'kdump' (yes I know sysrq also allows you to trigger a crash dump).

There are a few issues with this patch (mainly being incomplete), I'd like to check the public interest with this feature before I develop it further.

arch/x86_64/kernel/crash.c +61 -14
index 95a7a2c..b68a0f5 100644
@@ -31,6 +31,18 @@ static int crashing_cpu;
 #ifdef CONFIG_SMP
 static atomic_t waiting_for_crash_ipi;
 
+static void halt_current_cpu(struct pt_regs *regs)
+{
+	local_irq_disable();
+
+	crash_save_cpu(regs, raw_smp_processor_id());
+	disable_local_APIC();
+	atomic_dec(&waiting_for_crash_ipi);
+	/* Assume hlt works */
+	for(;;)
+		halt();
+}
+
 static int crash_nmi_callback(struct notifier_block *self,
 				unsigned long val, void *data)
 {
@@ -50,15 +62,8 @@ static int crash_nmi_callback(struct notifier_block *self,
 	 */
 	if (cpu == crashing_cpu)
 		return NOTIFY_STOP;
-	local_irq_disable();
-
-	crash_save_cpu(regs, cpu);
-	disable_local_APIC();
-	atomic_dec(&waiting_for_crash_ipi);
-	/* Assume hlt works */
-	for(;;)
-		halt();
 
+	halt_current_cpu(regs);
 	return 1;
 }
 
@@ -77,11 +82,26 @@ static struct notifier_block crash_nmi_nb = {
 	.notifier_call = crash_nmi_callback,
 };
 
-static void nmi_shootdown_cpus(void)
+static void wait_other_cpus(void)
 {
 	unsigned long msecs;
 
+	msecs = 1000; /* Wait at most a second for the other cpus to stop */
+	while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
+		mdelay(1);
+		msecs--;
+	}
+}
+
+static void nmi_shootdown_cpus_init(void)
+{
 	atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
+}
+
+static void nmi_shootdown_cpus(void)
+{
+	nmi_shootdown_cpus_init();
+
 	if (register_die_notifier(&crash_nmi_nb))
 		return;         /* return what? */
 
@@ -93,19 +113,23 @@ static void nmi_shootdown_cpus(void)
 
 	smp_send_nmi_allbutself();
 
-	msecs = 1000; /* Wait at most a second for the other cpus to stop */
-	while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
-		mdelay(1);
-		msecs--;
-	}
+	wait_other_cpus();
 	/* Leave the nmi callback set */
+
 	disable_local_APIC();
 }
+
 #else
+
 static void nmi_shootdown_cpus(void)
 {
 	/* There are no cpus to shootdown */
 }
+
+static void nmi_shootdown_cpus_init(void) {};
+static void wait_other_cpus() {}
+static void halt_current_cpu(struct pt_regs *regs) {};
+
 #endif
 
 void machine_crash_shutdown(struct pt_regs *regs)
@@ -133,3 +157,26 @@ void machine_crash_shutdown(struct pt_regs *regs)
 
 	crash_save_cpu(regs, smp_processor_id());
 }
+
+void machine_crash_shutdown_begin(void)
+{
+	local_irq_disable();
+	nmi_shootdown_cpus_init();
+}
+
+void machine_crash_shutdown_end(struct pt_regs *regs)
+{
+	wait_other_cpus();
+
+	local_irq_disable();
+	if(cpu_has_apic)
+		disable_local_APIC();
+
+	disable_IO_APIC();
+	crash_save_cpu(regs, smp_processor_id());
+}
+
+void machine_crash_shutdown_other_cpu(struct pt_regs *regs)
+{
+	halt_current_cpu(regs);
+}
include/linux/kdb.h +7 -0
index e4340d3..1cf413e 100644
@@ -161,4 +161,11 @@ int kdb_process_cpu(const struct task_struct *p)
 
 extern const char kdb_serial_str[];
 
+#ifdef CONFIG_KEXEC
+
+void kdb_kexec_prepare(struct pt_regs *regs);
+void kexec_from_kdb(struct pt_regs *regs, int kdump);
+
+#endif
+
 #endif	/* !_KDB_H */
include/linux/kdbprivate.h +1 -0
index 50dee9f..ca2c3db 100644
@@ -162,6 +162,7 @@ volatile extern int kdb_state[ /*NR_CPUS*/ ];
 #define KDB_STATE_IP_ADJUSTED	0x00008000	/* Restart IP has been adjusted */
 #define KDB_STATE_GO1		0x00010000	/* go only releases one cpu */
 #define KDB_STATE_KEYBOARD	0x00020000	/* kdb entered via keyboard on this cpu */
+#define KDB_STATE_KEXEC   	0x00040000	/* kexec issued */
 #define KDB_STATE_ARCH		0xff000000	/* Reserved for arch specific use */
 
 #define KDB_STATE_CPU(flag,cpu)		(kdb_state[cpu] & KDB_STATE_##flag)
include/linux/reboot.h +4 -1
index 1dd1c70..f4d682c 100644
@@ -53,7 +53,10 @@ extern void machine_power_off(void);
 
 extern void machine_shutdown(void);
 struct pt_regs;
-extern void machine_crash_shutdown(struct pt_regs *);
+extern void machine_crash_shutdown(struct pt_regs *regs);
+extern void machine_crash_shutdown_begin(void);
+extern void machine_crash_shutdown_other_cpu(struct pt_regs *regs);
+extern void machine_crash_shutdown_end(struct pt_regs *regs);
 
 /* 
  * Architecture independent implemenations of sys_reboot commands.
kdb/kdbmain.c +127 -0

152 lines not on this page · raw message

kernel/kexec.c +42 -0

68 lines not on this page · raw message

Signature · 3 lines
Dan Aloni
XIV LTD, http://www.xivstorage.com
da-x (at) monatomic.org, dan (at) xiv.co.il