Skip to contentSkip to conversation

debug: prevent entering debug mode on panic/exception.

RFC Superseded Kiran Raparthy 3 participants 9 messages Dec 23, 2014 – Jan 7, 2015 KGDB / KDB /debug_core

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

RFC v4 1/1 debug: prevent entering debug mode on panic/exception.

From: Colin Cross <[email protected]>

debug: prevent entering debug mode on panic/exception.

On non-developer devices, kgdb prevents the device from rebooting after a panic.

Incase of panics and exceptions, to allow the device to reboot, prevent entering debug mode to avoid getting stuck waiting for the user to interact with debugger.

To avoid entering the debugger on panic/exception without any extra configuration, panic_timeout is being used which can be set via /proc/sys/kernel/panic at run time and CONFIG_PANIC_TIMEOUT sets the default value.

Cc Jason Wessel <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc John Stultz <[email protected]>
Cc Sumit Semwal <[email protected]>

[Kiran: Added context to commit message. panic_timeout is used instead of break_on_panic and break_on_exception to honor CONFIG_PANIC_TIMEOUT. Modified the commit as per community feedback]

---
 kernel/debug/debug_core.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
kernel/debug/debug_core.c +17 -0
index 1adf62b..0012a1f 100644
@@ -689,6 +689,14 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
 
 	if (arch_kgdb_ops.enable_nmi)
 		arch_kgdb_ops.enable_nmi(0);
+	/*
+	 * Avoid entering the debugger if we were triggered due to an oops
+	 * but panic_timeout indicates the system should automatically
+	 * reboot on panic. We don't want to get stuck waiting for input
+	 * on such systems, especially if its "just" an oops.
+	 */
+	if (signo != SIGTRAP && panic_timeout)
+		return 1;
 
 	memset(ks, 0, sizeof(struct kgdb_state));
 	ks->cpu			= raw_smp_processor_id();
@@ -821,6 +829,15 @@ static int kgdb_panic_event(struct notifier_block *self,
 			    unsigned long val,
 			    void *data)
 {
+	/*
+	 * Avoid entering the debugger if we were triggered due to a panic
+	 * We don't want to get stuck waiting for input from user in such case.
+	 * panic_timeout indicates the system should automatically
+	 * reboot on panic.
+	 */
+	if (panic_timeout)
+		return NOTIFY_DONE;
+
 	if (dbg_kdb_mode)
 		kdb_printf("PANIC: %s\n", (char *)data);
 	kgdb_breakpoint();
Signature · 1 line
1.8.2.1
#1 lore raw
Quoted 11 lines · On Tue, 23 Dec 2014 18:08:29 +0530 Kiran Raparthy <[email protected]>…

From: Colin Cross <[email protected]>

debug: prevent entering debug mode on panic/exception.

On non-developer devices, kgdb prevents the device from rebooting after a panic.

Incase of panics and exceptions, to allow the device to reboot, prevent entering debug mode to avoid getting stuck waiting for the user to interact with debugger.

Quoted 7 lines

To avoid entering the debugger on panic/exception without any extra configuration, panic_timeout is being used which can be set via /proc/sys/kernel/panic at run time and CONFIG_PANIC_TIMEOUT sets the default value.

...

hm. Why overload the meaning of panic_timeout in this fashion? If someone is using kgdb and has panic_timeout set, they'll get quiet a surprise.

Would it be cleaner/clearer to add some new standalone control for this? One which is only present if CONFIG_KGDB.

We appear to have forgotten to document panic_timeout. Sigh.

#2 lore raw

Hi Andrew,

Quoted 18 lines · Andrew Morton
Quoted 16 lines · On Tue, 23 Dec 2014 18:08:29 +0530 Kiran Raparthy <[email protected]>…

From: Colin Cross <[email protected]>

debug: prevent entering debug mode on panic/exception.

On non-developer devices, kgdb prevents the device from rebooting after a panic.

Incase of panics and exceptions, to allow the device to reboot, prevent entering debug mode to avoid getting stuck waiting for the user to interact with debugger.

To avoid entering the debugger on panic/exception without any extra configuration, panic_timeout is being used which can be set via /proc/sys/kernel/panic at run time and CONFIG_PANIC_TIMEOUT sets the default value.

Quoted 6 lines
Quoted 2 lines

...

hm. Why overload the meaning of panic_timeout in this fashion? If someone is using kgdb and has panic_timeout set, they'll get quiet a surprise.

We are just using already exported kernel symbol to avoid extra configuration. So we have chosen panic_timeout to allow kgdb to honor CONFIG_PANIC_TIMEOUT. I can modify the commit text if you feel the above commit text overloading the meaning of panic_timeout.

To give you a better idea about why we have used panic_timeout, sharing Daniel's previous review comment:

"It ought to be possible for kgdb/kdb to honour CONFIG_PANIC_TIMEOUT by tracking how long it takes for the user to attach a debugger (or to run the first kdb command after the panic). As it happens the timeout value is already an exported kernel symbol so all the info is there for us to use.Doing so would save us imposing further configuration burden on the user"

Quoted 3 lines

Would it be cleaner/clearer to add some new standalone control for this? One which is only present if CONFIG_KGDB.

Original Android patch uses separate configuration but since we can achieve the same with
already existing kernel symbol,we have used panic_timeout.

Quoted 3 lines

We appear to have forgotten to document panic_timeout. Sigh.

Regards,
Kiran

#3 lore raw
In reply to Andrew Morton
Quoted 18 lines · Andrew Morton
Quoted 16 lines · On Tue, 23 Dec 2014 18:08:29 +0530 Kiran Raparthy <[email protected]>…

From: Colin Cross <[email protected]>

debug: prevent entering debug mode on panic/exception.

On non-developer devices, kgdb prevents the device from rebooting after a panic.

Incase of panics and exceptions, to allow the device to reboot, prevent entering debug mode to avoid getting stuck waiting for the user to interact with debugger.

To avoid entering the debugger on panic/exception without any extra configuration, panic_timeout is being used which can be set via /proc/sys/kernel/panic at run time and CONFIG_PANIC_TIMEOUT sets the default value.

Quoted 6 lines
Quoted 2 lines

...

hm. Why overload the meaning of panic_timeout in this fashion? If someone is using kgdb and has panic_timeout set, they'll get quiet a surprise.

Will they?

Setting panic_timeout means the user explicitly requested that the machine try to perform an unattended reboot after a panic. Wedging in kgdb during panic on such a system absolutely contradicts the user's request to have an automated reboot.

In this case it is not overloading the meaning... we are simply altering kgdb to properly honour the existing meaning.

Changing the behaviour for exceptions as well as for panics *might* maybe veer into overloading but even there, I think we are simply better reflecting user intent. It is hard to imagine a user that wants automatic-reboot-on-panic being happy for the kernel to get stuck overnight just because of an oops.

Quoted 2 lines

Would it be cleaner/clearer to add some new standalone control for this? One which is only present if CONFIG_KGDB.

I don't think it is clearer (although given it was my review that lead us here that's probably to be expected).

Separating them out simply means an additional gotcha a user must be aware of if they want automatic reboot *and* kgdb (i.e. two kernel cmdline arguments must be used that then just one).

Quoted 1 line

We appear to have forgotten to document panic_timeout. Sigh.

On the subject of documentation it would be useful to update the kgdb docs to document the effect of panic_timeout on panic/exception behaviour.

#4 lore raw
Quoted 19 lines · On Tue, 06 Jan 2015 15:25:51 +0000 Daniel Thompson…
Quoted 11 lines
Quoted 7 lines

To avoid entering the debugger on panic/exception without any extra configuration, panic_timeout is being used which can be set via /proc/sys/kernel/panic at run time and CONFIG_PANIC_TIMEOUT sets the default value.

...

hm. Why overload the meaning of panic_timeout in this fashion? If someone is using kgdb and has panic_timeout set, they'll get quiet a surprise.

Will they?

Setting panic_timeout means the user explicitly requested that the machine try to perform an unattended reboot after a panic. Wedging in kgdb during panic on such a system absolutely contradicts the user's request to have an automated reboot.

Quoted 8 lines

In this case it is not overloading the meaning... we are simply altering kgdb to properly honour the existing meaning.

Changing the behaviour for exceptions as well as for panics *might* maybe veer into overloading but even there, I think we are simply better reflecting user intent. It is hard to imagine a user that wants automatic-reboot-on-panic being happy for the kernel to get stuck overnight just because of an oops.

OK, when you put it that way...

Kiran, could we please have an updated patch which includes the above observations in the changelog and which documents panic_timeout?

#5 lore raw
Quoted 30 lines · Andrew Morton
Quoted 19 lines · On Tue, 06 Jan 2015 15:25:51 +0000 Daniel Thompson…
Quoted 11 lines
Quoted 7 lines

To avoid entering the debugger on panic/exception without any extra configuration, panic_timeout is being used which can be set via /proc/sys/kernel/panic at run time and CONFIG_PANIC_TIMEOUT sets the default value.

...

hm. Why overload the meaning of panic_timeout in this fashion? If someone is using kgdb and has panic_timeout set, they'll get quiet a surprise.

Will they?

Setting panic_timeout means the user explicitly requested that the machine try to perform an unattended reboot after a panic. Wedging in kgdb during panic on such a system absolutely contradicts the user's request to have an automated reboot.

Quoted 8 lines

In this case it is not overloading the meaning... we are simply altering kgdb to properly honour the existing meaning.

Changing the behaviour for exceptions as well as for panics *might* maybe veer into overloading but even there, I think we are simply better reflecting user intent. It is hard to imagine a user that wants automatic-reboot-on-panic being happy for the kernel to get stuck overnight just because of an oops.

Quoted 4 lines

OK, when you put it that way...

Kiran, could we please have an updated patch which includes the above observations in the changelog and which documents panic_timeout?

Sure,I'll do that.Thanks for your time.
Regards,
Kiran

#7 lore raw
Quoted 7 lines · On Tue, 06 Jan 2015 15:31:31 +0000 Daniel Thompson…
Quoted 1 line · Andrew Morton

We appear to have forgotten to document panic_timeout. Sigh.

I knew I'd seen it somewhere...

Once its been sysctlised it ends up called "panic":
https://www.kernel.org/doc/Documentation/sysctl/kernel.txt

Confused. That file doesn't mention panic_timeout. But it is the place where panic_timeout can be described.

#8 lore raw
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Tue, 06 Jan 2015 15:31:31 +0000 Daniel Thompson…
Quoted 1 line · Andrew Morton

We appear to have forgotten to document panic_timeout. Sigh.

Quoted 7 lines
Quoted 4 lines

I knew I'd seen it somewhere...

Once its been sysctlised it ends up called "panic":
https://www.kernel.org/doc/Documentation/sysctl/kernel.txt

Confused. That file doesn't mention panic_timeout. But it is the place where panic_timeout can be described.

The sysctl is called "panic" (as is the closely related kernel parameter)

The name panic_timeout is used only for the C symbol presumably because panic was already used for something else...

Daniel.