public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "K.Prasad" <prasad@linux.vnet.ibm.com>
To: Ingo Molnar <mingo@elte.hu>, Frederic Weisbecker <fweisbec@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Andrew Morton <akpm@linux-foundation.org>,
	"K.Prasad" <prasad@linux.vnet.ibm.com>
Subject: [RFC Patch 2/4] Allow breakpoints to be enabled/disabled without yielding the breakpoint request through new APIs - <enable><disable>_hw_breakpoint()
Date: Tue, 27 Oct 2009 02:49:15 +0530	[thread overview]
Message-ID: <20091026211915.GC15529@in.ibm.com> (raw)
In-Reply-To: 20091026211225.214925175@xyz

[-- Attachment #1: enable_disable_patch_03 --]
[-- Type: text/plain, Size: 4714 bytes --]

Allow breakpoints to be enabled/disabled without yielding the
breakpoint request through new APIs - <enable><disable>_hw_breakpoint()

Signed-off-by: K.Prasad <prasad@linux.vnet.ibm.com>
---
 arch/x86/kernel/hw_breakpoint.c     |   15 ++++++++++-----
 include/asm-generic/hw_breakpoint.h |   13 +++++++++++++
 kernel/hw_breakpoint.c              |   27 +++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 5 deletions(-)

Index: linux-2.6-tip.perf_hbkpt/arch/x86/kernel/hw_breakpoint.c
===================================================================
--- linux-2.6-tip.perf_hbkpt.orig/arch/x86/kernel/hw_breakpoint.c
+++ linux-2.6-tip.perf_hbkpt/arch/x86/kernel/hw_breakpoint.c
@@ -85,10 +85,11 @@ void arch_update_kernel_hw_breakpoint(vo
 
 	for (i = hbp_kernel_pos; i < HBP_NUM; i++) {
 		bp = per_cpu(this_hbp_kernel[i], cpu);
-		if (bp) {
+		if (!bp)
+			continue;
+		set_debugreg(bp->info.address, i);
+		if (atomic_read(&bp->enabled) == BP_ENABLED)
 			temp_kdr7 |= encode_dr7(i, bp->info.len, bp->info.type);
-			set_debugreg(bp->info.address, i);
-		}
 	}
 
 	/* No need to set DR6. Update the debug registers with kernel-space
@@ -288,8 +289,9 @@ void arch_update_user_hw_breakpoint(int 
 	thread->debugreg7 &= ~dr7_masks[pos];
 	if (bp) {
 		thread->debugreg[pos] = bp->info.address;
-		thread->debugreg7 |= encode_dr7(pos, bp->info.len,
-							bp->info.type);
+		if (atomic_read(&bp->enabled) == BP_ENABLED)
+			thread->debugreg7 |= encode_dr7(pos, bp->info.len,
+								bp->info.type);
 	} else
 		thread->debugreg[pos] = 0;
 }
@@ -377,6 +379,9 @@ static int __kprobes hw_breakpoint_handl
 		 */
 		if (!bp)
 			continue;
+		/* Ignore exceptions due to disabled breakpoints */
+		if (atomic_read(&bp->enabled) == BP_DISABLED)
+			continue;
 
 		(bp->triggered)(bp, args->regs);
 	}
Index: linux-2.6-tip.perf_hbkpt/include/asm-generic/hw_breakpoint.h
===================================================================
--- linux-2.6-tip.perf_hbkpt.orig/include/asm-generic/hw_breakpoint.h
+++ linux-2.6-tip.perf_hbkpt/include/asm-generic/hw_breakpoint.h
@@ -102,11 +102,22 @@
  * ----------------------------------------------------------------------
  */
 struct hw_breakpoint {
+	/*
+	 * Denotes if a breakpoint is currently enabled in physical debug
+	 * registers. Not to be set directly by the end-user. Must be
+	 * operated through <enable><disable>_hw_breakpoint() APIs only.
+	 */
+	atomic_t enabled;
 	void (*triggered)(struct hw_breakpoint *, struct pt_regs *);
 	const cpumask_t *cpumask;
 	struct arch_hw_breakpoint info;
 };
 
+enum bp_status {
+	BP_DISABLED	= 0,
+	BP_ENABLED	= 1
+};
+
 /*
  * len and type values are defined in include/asm/hw_breakpoint.h.
  * Available values vary according to the architecture.  On i386 the
@@ -135,6 +146,8 @@ extern void unregister_user_hw_breakpoin
 extern int register_kernel_hw_breakpoint(struct hw_breakpoint *bp);
 extern void unregister_kernel_hw_breakpoint(struct hw_breakpoint *bp);
 
+extern void enable_hw_breakpoint(struct hw_breakpoint *bp);
+extern void disable_hw_breakpoint(struct hw_breakpoint *bp);
 extern unsigned int hbp_kernel_pos;
 
 #endif	/* __KERNEL__ */
Index: linux-2.6-tip.perf_hbkpt/kernel/hw_breakpoint.c
===================================================================
--- linux-2.6-tip.perf_hbkpt.orig/kernel/hw_breakpoint.c
+++ linux-2.6-tip.perf_hbkpt/kernel/hw_breakpoint.c
@@ -351,6 +351,7 @@ int register_kernel_hw_breakpoint(struct
 		}
 	}
 
+	atomic_set(&bp->enabled, BP_ENABLED);
 	if (cpumask_test_cpu(smp_processor_id(), bp->cpumask))
 		update_each_cpu_kernel_hbp(bp);
 	smp_call_function_many(bp->cpumask, update_each_cpu_kernel_hbp, bp, 1);
@@ -420,6 +421,32 @@ ret_path:
 }
 EXPORT_SYMBOL_GPL(unregister_kernel_hw_breakpoint);
 
+/**
+ * enable_hw_breakpoint - re-enable a breakpoint previously disabled
+ * @bp: pointer to the breakpoint structure to be enabled
+ *
+ * Re-enable or disable a breakpoint, previously disabled using
+ * disable_hw_breakpoint()
+ */
+void enable_hw_breakpoint(struct hw_breakpoint *bp)
+{
+	atomic_set(&bp->enabled, BP_ENABLED);
+}
+EXPORT_SYMBOL_GPL(enable_hw_breakpoint);
+
+/**
+ * disable_hw_breakpoint - disable a breakpoint from raising breakpoint exceptions
+ * @bp: pointer to the breakpoint structure to be disabled
+ *
+ * Disable a breakpoint without actually losing the registration. Re-enable it
+ * again using enable_hw_breakpoint()
+ */
+void disable_hw_breakpoint(struct hw_breakpoint *bp)
+{
+	atomic_set(&bp->enabled, BP_DISABLED);
+}
+EXPORT_SYMBOL_GPL(disable_hw_breakpoint);
+
 static struct notifier_block hw_breakpoint_exceptions_nb = {
 	.notifier_call = hw_breakpoint_exceptions_notify,
 	/* we need to be notified first */


  parent reply	other threads:[~2009-10-26 21:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20091026211225.214925175@xyz>
2009-10-26 21:17 ` [RFC Patch 1/4] Allow kernel-space hw-breakpoints to be restricted only for a subset of CPUs using a cpumask field in struct hw_breakpoint K.Prasad
2009-10-26 21:19 ` K.Prasad [this message]
2009-10-28 20:31   ` [RFC Patch 2/4] Allow breakpoints to be enabled/disabled without yielding the breakpoint request through new APIs - <enable><disable>_hw_breakpoint() Steven Rostedt
2009-10-29 21:34     ` K.Prasad
2009-10-26 21:19 ` [RFC Patch 3/4] Bugfix HW-BKPT: Fix traceback seen when resuming after suspend-to-ram K.Prasad
2009-10-26 21:20 ` [RFC Patch 4/4] Enable perf-events to use hw-breakpoints K.Prasad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091026211915.GC15529@in.ibm.com \
    --to=prasad@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox