Skip to contentSkip to conversation

Clear reserved bits of DR6 in do_debug()

PATCH In review K.Prasad 1 participant 4 messages Jan 28, 2010 – Jan 29, 2010 1 message not in the archive x86

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

K.Prasad

author
#1 lore raw

PATCH v2 1/2 Clear reserved bits of DR6 in do_debug()

Clear the reserved bits from the stored copy of debug status register (DR6). This will help easy bitwise operations.

---
 arch/x86/include/asm/debugreg.h |    3 +++
 arch/x86/kernel/traps.c         |    3 +++
 2 files changed, 6 insertions(+)
arch/x86/include/asm/debugreg.h +3 -0
Index: linux-2.6-tip.bugfix_perf_hbkpt/arch/x86/include/asm/debugreg.h
===================================================================
@@ -14,6 +14,9 @@
    which debugging register was responsible for the trap.  The other bits
    are either reserved or not of interest to us. */
 
+/* Define reserved bits in DR6 which are always set to 1 */
+#define DR6_RESERVED	(0xFFFF0FF0)
+
 #define DR_TRAP0	(0x1)		/* db0 */
 #define DR_TRAP1	(0x2)		/* db1 */
 #define DR_TRAP2	(0x4)		/* db2 */
arch/x86/kernel/traps.c +3 -0
Index: linux-2.6-tip.bugfix_perf_hbkpt/arch/x86/kernel/traps.c
===================================================================
@@ -534,6 +534,9 @@ dotraplinkage void __kprobes do_debug(st
 
 	get_debugreg(dr6, 6);
 
+	/* Filter out all the reserved bits which are preset to 1 */
+	dr6 &= ~DR6_RESERVED;
+
 	/* Catch kmemcheck conditions first of all! */
 	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
 		return;
#2 lore raw

[tip:perf/core] x86/debug: Clear reserved bits of DR6 in do_debug()

Commit-ID:  40f9249a73f6c251adea492b1c3d19d39e2a9bda
Gitweb:     http://git.kernel.org/tip/40f9249a73f6c251adea492b1c3d19d39e2a9bda
Author:     K.Prasad <[email protected]>
AuthorDate: Thu, 28 Jan 2010 16:44:01 +0530
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Fri, 29 Jan 2010 02:26:10 +0100

x86/debug: Clear reserved bits of DR6 in do_debug()

Clear the reserved bits from the stored copy of debug status register (DR6).
This will help easy bitwise operations such as quick testing of a debug event origin.

Cc Roland McGrath <[email protected]>
Cc Jan Kiszka <[email protected]>
Cc Alan Stern <[email protected]>
Cc Ingo Molnar <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/debugreg.h |    3 +++
 arch/x86/kernel/traps.c         |    3 +++
 2 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/include/asm/debugreg.h +3 -0
index 8240f76..b81002f 100644
@@ -14,6 +14,9 @@
    which debugging register was responsible for the trap.  The other bits
    are either reserved or not of interest to us. */
 
+/* Define reserved bits in DR6 which are always set to 1 */
+#define DR6_RESERVED	(0xFFFF0FF0)
+
 #define DR_TRAP0	(0x1)		/* db0 */
 #define DR_TRAP1	(0x2)		/* db1 */
 #define DR_TRAP2	(0x4)		/* db2 */
arch/x86/kernel/traps.c +3 -0
index 3339917..1168e44 100644
@@ -534,6 +534,9 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 
 	get_debugreg(dr6, 6);
 
+	/* Filter out all the reserved bits which are preset to 1 */
+	dr6 &= ~DR6_RESERVED;
+
 	/* Catch kmemcheck conditions first of all! */
 	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
 		return;
author
#3 lore raw

PATCH v2 2/2 Return proper code to notifier chain in hw_breakpoint_handler

In reply to a message not in the archive

Processing of debug exceptions (in do_debug()) can stop if it originated from a hw-breakpoint exception (return NOTIFY_STOP). For certain cases such as
a) user-space breakpoints with pending SIGTRAP signal delivery (as in the case of ptrace induced breakpoints) and b) exceptions due to multiple causes (other than breakpoints) we will continue to process the exception (by returning NOTIFY_DONE).

---
 arch/x86/kernel/hw_breakpoint.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/hw_breakpoint.c +7 -3
Index: linux-2.6-tip.bugfix_perf_hbkpt/arch/x86/kernel/hw_breakpoint.c
===================================================================
@@ -502,8 +502,6 @@ static int __kprobes hw_breakpoint_handl
 		rcu_read_lock();
 
 		bp = per_cpu(bp_per_reg[i], cpu);
-		if (bp)
-			rc = NOTIFY_DONE;
 		/*
 		 * Reset the 'i'th TRAP bit in dr6 to denote completion of
 		 * exception handling
@@ -522,7 +520,13 @@ static int __kprobes hw_breakpoint_handl
 
 		rcu_read_unlock();
 	}
-	if (dr6 & (~DR_TRAP_BITS))
+	/*
+	 * Further processing in do_debug() is needed for a) user-space
+	 * breakpoints (to generate signals) and b) when the system has
+	 * taken exception due to multiple causes
+	 */
+	if ((current->thread.debugreg6 & DR_TRAP_BITS) ||
+	    (dr6 & (~DR_TRAP_BITS)))
 		rc = NOTIFY_DONE;
 
 	set_debugreg(dr7, 7);
#4 lore raw

[tip:perf/core] x86/hw-breakpoints: Optimize return code from notifier chain in hw_breakpoint_handler

Commit-ID:  e0e53db6133c32964fd17f20b17073a402f07ed3
Gitweb:     http://git.kernel.org/tip/e0e53db6133c32964fd17f20b17073a402f07ed3
Author:     K.Prasad <[email protected]>
AuthorDate: Thu, 28 Jan 2010 16:44:15 +0530
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Fri, 29 Jan 2010 02:44:30 +0100

x86/hw-breakpoints: Optimize return code from notifier chain in hw_breakpoint_handler

Processing of debug exceptions in do_debug() can stop if it originated from a hw-breakpoint exception by returning NOTIFY_STOP in most cases.

But for certain cases such as:

a) user-space breakpoints with pending SIGTRAP signal delivery (as in the case of ptrace induced breakpoints).

b) exceptions due to other causes than breakpoints

We will continue to process the exception by returning NOTIFY_DONE.

Cc Ingo Molnar <[email protected]>
Cc Roland McGrath <[email protected]>
Cc Alan Stern <[email protected]>
Cc Jan Kiszka <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/hw_breakpoint.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/hw_breakpoint.c +7 -3
index 05d5fec..ae90b47 100644
@@ -502,8 +502,6 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
 		rcu_read_lock();
 
 		bp = per_cpu(bp_per_reg[i], cpu);
-		if (bp)
-			rc = NOTIFY_DONE;
 		/*
 		 * Reset the 'i'th TRAP bit in dr6 to denote completion of
 		 * exception handling
@@ -522,7 +520,13 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
 
 		rcu_read_unlock();
 	}
-	if (dr6 & (~DR_TRAP_BITS))
+	/*
+	 * Further processing in do_debug() is needed for a) user-space
+	 * breakpoints (to generate signals) and b) when the system has
+	 * taken exception due to multiple causes
+	 */
+	if ((current->thread.debugreg6 & DR_TRAP_BITS) ||
+	    (dr6 & (~DR_TRAP_BITS)))
 		rc = NOTIFY_DONE;
 
 	set_debugreg(dr7, 7);