tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

T_TRCTRAP handling



Hello,

Currently, the handling of the Trace trap on amd64 and i386 architectures is problematic under certain conditions. More specifically, on kernels compiled without DDB and KGDB support, Trace traps within supervisor mode result in kernel panic.

I encountered this issue while working on a kernel with the aforementioned configuration on qemu and its built-in gdbserver.

In the following patches I propose a more graceful way of handling T_TRCTRAP. Instead of panicking the kernel upon encountering a trace trap that wasn't addressed by DDB or KGDB, ignore it by clearing the TF in EFLAGS/RFLAGS and resume execution.

Opinions?


Regards,
Dimitris


Index: trap.c
===================================================================
RCS file: /pub/NetBSD-CVS/src/sys/arch/amd64/amd64/trap.c,v
retrieving revision 1.111
diff -u -p -r1.111 trap.c
--- trap.c	20 Jan 2018 08:30:53 -0000	1.111
+++ trap.c	7 Feb 2018 08:56:11 -0000
@@ -402,12 +402,24 @@ trap(struct trapframe *frame)

 	default:
 	we_re_toast:
-		trap_print(frame, l);
+		if (type != T_TRCTRAP)
+			trap_print(frame, l);

 		if (kdb_trap(type, 0, frame))
 			return;
 		if (kgdb_trap(type, frame))
 			return;
+
+		/*
+		 * If we've reached this point it means DDB and KGDB are not
+		 * enabled and we're being single-stepped by a hypervisor.
+		 * Don't panic, clear the Trap Flag and carry on.
+		 */
+		if (type == T_TRCTRAP) {
+			frame->tf_rflags &= ~PSL_T;
+			return;
+		}
+
 		/*
 		 * If this is a breakpoint, don't panic if we're not connected.
 		 */
Index: trap.c
===================================================================
RCS file: /pub/NetBSD-CVS/src/sys/arch/i386/i386/trap.c,v
retrieving revision 1.292
diff -u -p -r1.292 trap.c
--- trap.c	27 Jan 2018 09:33:25 -0000	1.292
+++ trap.c	7 Feb 2018 09:00:18 -0000
@@ -314,6 +314,17 @@ trap(struct trapframe *frame)
 			return;
 		if (kgdb_trap(type, frame))
 			return;
+
+		/*
+		 * If we've reached this point it means DDB and KGDB are not
+		 * enabled and we're being single-stepped by a hypervisor.
+		 * Don't panic, clear the Trap Flag and carry on.
+		 */
+		if (type == T_TRCTRAP) {
+			frame->tf_eflags &= ~PSL_T;
+			return;
+		}
+
 		/*
 		 * If this is a breakpoint, don't panic if we're not connected.
 		 */



Home | Main Index | Thread Index | Old Index