All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Add hw_breakpoint_enable function
@ 2015-12-12 22:44 Jeff Merkey
  0 siblings, 0 replies; only message in thread
From: Jeff Merkey @ 2015-12-12 22:44 UTC (permalink / raw)
  To: LKML
  Cc: Thomas Gleixner, Andy Lutomirski, Ingo Molnar, H. Peter Anvin,
	X86 ML, Peter Zijlstra, Andy Lutomirski, Masami Hiramatsu,
	Steven Rostedt, Borislav Petkov, Jiri Olsa

The current function to manually restore breakpoints
(hw_breakpoint_restore) places the contents of the thread.debugreg6
variable back into the dr6 hardware register, a piece of hardware
intended to be read, not used as local storage.  The problem with this
is that systems that register for breakpoints, including the perf
event system and kgdb/kdb, modify this variable.  I have observed
garbage stacked debug statuses being cycled through dr6 and this
variable over and over again in a loop by calls to
hw_breakpoint_restore() that cause strange behaviors in kdb and this
layer.  In short, I don't use this broken function.

This function is necessary because upon debugger entry, you must set
dr7 to 0 to disable breakpoints while inside the debugger then call
hw_breakpoint_restore() to reload the state and re-enable them.  This
function is identical to hw_breakpoint_restore() except it leaves out
writing a user defined thread.debugreg6 variable back into a hardware
register not intended for that purpose.


Signed-off-by:  Jeff V. Merkey  <jeffmerkey@gmail.com>
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index 50a3fad..7ea0f78 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -425,6 +425,16 @@ void hw_breakpoint_restore(void)
 }
 EXPORT_SYMBOL_GPL(hw_breakpoint_restore);

+void hw_breakpoint_enable(void)
+{
+	set_debugreg(__this_cpu_read(cpu_debugreg[0]), 0);
+	set_debugreg(__this_cpu_read(cpu_debugreg[1]), 1);
+	set_debugreg(__this_cpu_read(cpu_debugreg[2]), 2);
+	set_debugreg(__this_cpu_read(cpu_debugreg[3]), 3);
+	set_debugreg(__this_cpu_read(cpu_dr7), 7);
+}
+EXPORT_SYMBOL_GPL(hw_breakpoint_enable);
+
 /*
  * Handle debug exception notifications.
  *

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-12-12 22:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-12 22:44 [PATCH 1/1] Add hw_breakpoint_enable function Jeff Merkey

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.