Skip to contentSkip to conversation

IA64 kexec/kdump patch for INIT

PATCH In review Takao Indoh 4 participants 5 messages Sep 5, 2006 – Sep 7, 2006 Proc sysctl

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IA64 kexec/kdump patch for INIT

Hi,

Here is the IA64 kdump patch for INIT against 2.6.18-rc5
with a kexec/kdump 2.6.18-rc5 patch which was posted by Zou Nan hai on 29th Aug.

This patch includes the following two functions.

1) Stop each cpu using INIT interruption

Current kdump uses simple IPI to stop cpus, so cpu does not stop if the cpu disables interruption. INIT interruption is non-maskable and it can stop cpus surely.

2) Start kexec/kdump by INIT button

Some machines have a button to generate INIT. When a kernel hangs up, we can start kexec/kdump using INIT button. This function is enabled/disabled by /proc/sys/kernel/kdump_on_init.

TODO:
o Add delay code not to start kexec before each cpu's register is saved

Any comments are welcome!

arch/ia64/kernel/mca.c +21 -0
diff -Nurp linux-2.6.18-rc5.org/arch/ia64/kernel/mca.c linux-2.6.18-rc5/arch/ia64/kernel/mca.c
@@ -69,6 +69,7 @@
 #include <linux/smp.h>
 #include <linux/workqueue.h>
 #include <linux/cpumask.h>
+#include <linux/kexec.h>
 
 #include <asm/delay.h>
 #include <asm/kdebug.h>
@@ -136,6 +137,9 @@ extern void salinfo_log_wakeup(int type,
 
 static int mca_init __initdata;
 
+#ifdef CONFIG_CRASH_DUMP
+int kdump_on_init = 0;
+#endif
 
 static void inline
 ia64_mca_spin(const char *func)
@@ -1393,6 +1397,23 @@ ia64_init_handler(struct pt_regs *regs, 
 		sos->monarch = 0;
 	}
 
+#ifdef CONFIG_CRASH_DUMP
+	/* if reason code is not 1(reason code 1 means machine check
+	 * rendezvous), INIT was issued by kdump or INIT button.
+	 */
+	if (sos->rv_rc != 1 && (kdump_send_ipi || kdump_on_init)) {
+		local_irq_disable();
+		set_curr_task(cpu, previous_current);
+
+		/* change region of gp to region5 */
+		asm volatile ("movl gp=__gp"::: "memory");
+		crash_kexec(regs);
+
+		crash_save_this_cpu();
+		for (;;)
+			ia64_hint(ia64_hint_pause);
+	}
+#endif
 	if (!sos->monarch) {
 		ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
 		while (monarch_cpu = -1)
arch/ia64/kernel/smp.c +8 -1
diff -Nurp linux-2.6.18-rc5.org/arch/ia64/kernel/smp.c linux-2.6.18-rc5/arch/ia64/kernel/smp.c
@@ -261,10 +261,17 @@ send_IPI_self (int op)
 }
 
 #ifdef CONFIG_CRASH_DUMP
+int kdump_send_ipi = 0;
 void
 kdump_smp_send_stop()
 {
- 	send_IPI_allbutself(IPI_KDUMP_CPU_STOP);
+	unsigned int i;
+
+	kdump_send_ipi = 1;
+	for_each_online_cpu (i) {
+		if (i != smp_processor_id())
+			platform_send_ipi(i, IA64_IPI_VECTOR, IA64_IPI_DM_INIT, 0);
+	}
 }
 #endif
 /*
include/asm-ia64/kexec.h +2 -0
diff -Nurp linux-2.6.18-rc5.org/include/asm-ia64/kexec.h linux-2.6.18-rc5/include/asm-ia64/kexec.h
@@ -41,5 +41,7 @@ extern struct resource boot_param_res;
 extern void kdump_smp_send_stop(void);
 extern void kdump_disable_iosapic(void);
 extern void crash_save_this_cpu(void);
+extern int kdump_send_ipi;
+extern int kdump_on_init;
 
 #endif /* _ASM_IA64_KEXEC_H */
include/linux/sysctl.h +1 -0
diff -Nurp linux-2.6.18-rc5.org/include/linux/sysctl.h linux-2.6.18-rc5/include/linux/sysctl.h
@@ -150,6 +150,7 @@ enum
 	KERN_IA64_UNALIGNEDr, /* int: ia64 unaligned userland trap enable */
 	KERN_COMPAT_LOGs,	/* int: print compat layer  messages */
 	KERN_MAX_LOCK_DEPTHt,
+	KERN_KDUMP_ON_INITu, /* int: kdump by INIT button */
 };
 
 
kernel/sysctl.c +11 -0
diff -Nurp linux-2.6.18-rc5.org/kernel/sysctl.c linux-2.6.18-rc5/kernel/sysctl.c
@@ -45,6 +45,7 @@
 #include <linux/syscalls.h>
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
+#include <linux/kexec.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -701,6 +702,16 @@ static ctl_table kern_table[] = {
 		.proc_handler	= &proc_dointvec,
 	},
 #endif
+#if defined(CONFIG_IA64) && defined(CONFIG_CRASH_DUMP)
+	{
+		.ctl_name	= KERN_KDUMP_ON_INIT,
+		.procname	= "kdump_on_init",
+		.data		= &kdump_on_init,
+		.maxlen		= sizeof (int),
+	 	.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
+#endif
 
 	{ .ctl_name = 0 }
 };
#1 lore raw
Quoted 5 lines · Takao Indoh (on Tue, 05 Sep 2006 21:18:39 +0900) wrote:

Hi,

Here is the IA64 kdump patch for INIT against 2.6.18-rc5
with a kexec/kdump 2.6.18-rc5 patch which was posted by Zou Nan hai on 29th Aug.

Quoted 7 lines

This patch includes the following two functions.

1) Stop each cpu using INIT interruption

Current kdump uses simple IPI to stop cpus, so cpu does not stop if the cpu disables interruption. INIT interruption is non-maskable and it can stop cpus surely.

You will get better results if you send a normal IPI first, wait a bit, then send a non-maskable INIT to just those cpus that have not responded. Why? Because INIT can catch the target cpu in any state, including down in prom in physical mode or in the assembler code that is busy saving the registers. At that point you can forget about getting any useful backtrace on that cpu. Sending a normal IPI first gives the target cpu a chance to get out of any critical section which gives you a much better backtrace.

KDB has been using the dual interrupt method since March 2006 and it has significantly improved the diagnostics. I am happy to work on common code that can be used by both kdump and kdb to handle stuck cpus and still get a reasonable backtrace.

All the code below should be under if (!sos->monarch). INIT sent via IA64_IPI_DM_INIT should always appear as a slave cpu, not as a monarch. If the prom is broken so it treats IA64_IPI_DM_INIT as a monarch then the event needs to be demoted to a slave. The code sending the INIT has to be treated as the monarch, anything else will confuse the code in mca.c that handles the NMI button. Again, KDB already handles this case and I am happy to work on common code for both kdb and kexec.

None of the crash dump code should not be inline in mca.c. It should be invoked via notify_die(DIE_INIT_SLAVE_PROCESS) so we do not clutter up mca.c with add ons like debuggers and crash dump handlers. kdb is not clean in that regard, but it is on my TODO list to remove all explicit references to kdb from mca.c. Using the notify_die() callback makes mca.c less confusing and cleanly separates any additional code from the already complex MCA/INIT code.

arch/ia64/kernel/mca.c ia64_init_handler(struct pt_regs *regs, · line 1406

Quoted 7 lines
arch/ia64/kernel/mca.c +7 -0
+#ifdef CONFIG_CRASH_DUMP
+	/* if reason code is not 1(reason code 1 means machine check
+	 * rendezvous), INIT was issued by kdump or INIT button.
+	 */
+	if (sos->rv_rc != 1 && (kdump_send_ipi || kdump_on_init)) {
+		local_irq_disable();
+		set_curr_task(cpu, previous_current);

set_curr_task() is not a good idea here. If the original stack was undefined (e.g. interrupt in physical state or kernel stack overflow) then you are switching back to garbage. Do kexec using the clean INIT stack. That adds a bit of processing to get the original stack for backtrace but it is far safer than assuming that the original stack is useable.

arch/ia64/kernel/mca.c ia64_init_handler(struct pt_regs *regs, · line 1409

Quoted 2 lines
arch/ia64/kernel/mca.c +2 -0
+		/* change region of gp to region5 */
+		asm volatile ("movl gp=__gp"::: "memory");

Why? gp is already pointing at the kernel code before we enter ia64_init_handler().

arch/ia64/kernel/mca.c ia64_init_handler(struct pt_regs *regs, · line 1414

Quoted 5 lines
arch/ia64/kernel/mca.c +5 -0
+		crash_kexec(regs);
+
+		crash_save_this_cpu();
+		for (;;)
+			ia64_hint(ia64_hint_pause);

cpu_relax() is the preferred method.

arch/ia64/kernel/smp.c send_IPI_self (int op) · line 264

Quoted 7 lines
arch/ia64/kernel/smp.c +1 -0
@@ -261,10 +261,17 @@ send_IPI_self (int op)
 }
 
 #ifdef CONFIG_CRASH_DUMP
+int kdump_send_ipi = 0;

kdump_on_init should be here, not in mca.c. In fact there should be no references to kdb or kexec in mca.c, it should all be handled by local code that is invoked via notify_die().

arch/ia64/kernel/smp.c send_IPI_self (int op) · line 270

Quoted 6 lines
arch/ia64/kernel/smp.c +3 -1
 kdump_smp_send_stop()
 {
- 	send_IPI_allbutself(IPI_KDUMP_CPU_STOP);
+	unsigned int i;
+
+	kdump_send_ipi = 1;

Needs memory barrier here.

Quoted 24 lines
arch/ia64/kernel/smp.c +4 -0
+	for_each_online_cpu (i) {
+		if (i != smp_processor_id())
+			platform_send_ipi(i, IA64_IPI_VECTOR, IA64_IPI_DM_INIT, 0);
+	}
 }
 

diff -Nurp linux-2.6.18-rc5.org/kernel/sysctl.c linux-2.6.18-rc5/kernel/sysctl.c

kernel/sysctl.c +4 -0
@@ -45,6 +45,7 @@
 #include <linux/syscalls.h>
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
+#include <linux/kexec.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -701,6 +702,16 @@ static ctl_table kern_table[] = {
 		.proc_handler	= &proc_dointvec,
 	},
 #endif
+#if defined(CONFIG_IA64) && defined(CONFIG_CRASH_DUMP)
+	{
+		.ctl_name	= KERN_KDUMP_ON_INIT,

kernel/sysctl.c static ctl_table kern_table[] = { · line 717

Quoted 10 lines
kernel/sysctl.c +7 -0
+		.procname	= "kdump_on_init",
+		.data		= &kdump_on_init,
+		.maxlen		= sizeof (int),
+	 	.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
+#endif
 
 	{ .ctl_name = 0 }
 };

Do not update sysctl.c. Use register_sysctl_table() instead.

As I say, kdb has already solved this problem and I want to work on common code to be used by debuggers and crash dumpers. I am travelling until September 15 so my machine access is limited right now. I can do an example patch that moves all of kdb mca/init handling to use notify_die(), but I will not be able to test the patch.

#2 lore raw
In reply to Takao Indoh

Hi,

Thanks for comments.
I'll reflect your comments and release new patch.

Quoted 13 lines · Keith Owens
Quoted 3 lines

Current kdump uses simple IPI to stop cpus, so cpu does not stop if the cpu disables interruption. INIT interruption is non-maskable and it can stop cpus surely.

You will get better results if you send a normal IPI first, wait a bit, then send a non-maskable INIT to just those cpus that have not responded. Why? Because INIT can catch the target cpu in any state, including down in prom in physical mode or in the assembler code that is busy saving the registers. At that point you can forget about getting any useful backtrace on that cpu. Sending a normal IPI first gives the target cpu a chance to get out of any critical section which gives you a much better backtrace.

Quoted 4 lines

KDB has been using the dual interrupt method since March 2006 and it has significantly improved the diagnostics. I am happy to work on common code that can be used by both kdump and kdb to handle stuck cpus and still get a reasonable backtrace.

I agree. I'm also happy if kdb and kdump share the code. I'll check kdb code.

Quoted 5 lines

arch/ia64/kernel/mca.c ia64_init_handler(struct pt_regs *regs, · line 1409

Quoted 2 lines
arch/ia64/kernel/mca.c +2 -0
+		/* change region of gp to region5 */
+		asm volatile ("movl gp=__gp"::: "memory");

Why? gp is already pointing at the kernel code before we enter ia64_init_handler().

The purpose of this code is just changing region of gp from region7 to region5. For example, if gp is e000000004ace170, I want to change gp to a000000104ace170, but I couldn't find good method. Is there good method to change region?

Regards,
Takao Indoh

#3 lore raw
In reply to Takao Indoh
Quoted 8 lines · Takao Indoh
Quoted 5 lines

arch/ia64/kernel/mca.c ia64_init_handler(struct pt_regs *regs, · line 1409

Quoted 2 lines
arch/ia64/kernel/mca.c +2 -0
+		/* change region of gp to region5 */
+		asm volatile ("movl gp=__gp"::: "memory");

Why? gp is already pointing at the kernel code before we enter ia64_init_handler().

The purpose of this code is just changing region of gp from region7 to region5. For example, if gp is e000000004ace170, I want to change gp to

                                ~~~~~~~~~~~~~~~~e000000000ace170

Sorry, I mistook address...

Regards,
Takao Indoh

#4 lore raw
In reply to Takao Indoh
Quoted 16 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Takao Indoh
Sent: 2006Äê9ÔÂ6ÈÕ 17:23
To: Keith Owens
Cc: [email protected]; [email protected]
Subject: Re: [PATCH]IA64 kexec/kdump patch for INIT

Quoted 6 lines · Takao Indoh
Quoted 5 lines

arch/ia64/kernel/mca.c ia64_init_handler(struct pt_regs *regs, · line 1409

Quoted 2 lines
arch/ia64/kernel/mca.c +2 -0
+		/* change region of gp to region5 */
+		asm volatile ("movl gp=__gp"::: "memory");

Why? gp is already pointing at the kernel code before we enter ia64_init_handler().

Quoted 9 lines
Quoted 2 lines

The purpose of this code is just changing region of gp from region7 to region5. For example, if gp is e000000004ace170, I want to change gp to

                                ~~~~~~~~~~~~~~~~e000000000ace170

Sorry, I mistook address...

Regards,
Takao Indoh

You don't need to set gp here. Control page does not use GP, and purgatory code will set GP to a physical address which was pre-calculated at the time of crash kernel loading. Thanks
Zou Nan hai

Quoted 5 lines

-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html