mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [GIT PULL] hw-breakpoints: Various fixes
@ 2009-11-10 10:25 Frederic Weisbecker
  2009-11-10 10:25 ` [PATCH 1/4] ksym_tracer: Support read accesses independent of read/write Frederic Weisbecker
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Frederic Weisbecker @ 2009-11-10 10:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Frederic Weisbecker, Jan Kiszka, Avi Kivity, K. Prasad,
	Paul Mundt, Li Zefan, Alan Stern, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Steven Rostedt, Jiri Slaby,
	Paul Mackerras, Mike Galbraith, Masami Hiramatsu,
	Arjan van de Ven

Ingo,

Please pull the tracing/hw-breakpoints branch that can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
	tracing/hw-breakpoints

Thanks,
	Frederic
---

Frederic Weisbecker (3):
      hw-breakpoints: Fix broken a.out format dump
      hw-breakpoints: Fix broken hw-breakpoint sample module
      hw-breakpoints: Wrap in the KVM breakpoint active state check

Paul Mundt (1):
      ksym_tracer: Support read accesses independent of read/write.


 arch/x86/include/asm/a.out-core.h       |   10 +------
 arch/x86/include/asm/debugreg.h         |    7 +++++
 arch/x86/kernel/hw_breakpoint.c         |   35 +++++++++++++++++++++++++
 arch/x86/kvm/x86.c                      |    2 +-
 kernel/hw_breakpoint.c                  |    3 +-
 kernel/kallsyms.c                       |    1 +
 kernel/trace/trace_ksym.c               |   11 +++++++-
 samples/hw_breakpoint/data_breakpoint.c |   43 +++++++++++++++++-------------
 8 files changed, 82 insertions(+), 30 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] ksym_tracer: Support read accesses independent of read/write.
  2009-11-10 10:25 [GIT PULL] hw-breakpoints: Various fixes Frederic Weisbecker
@ 2009-11-10 10:25 ` Frederic Weisbecker
  2009-11-10 10:25 ` [PATCH 2/4] hw-breakpoints: Fix broken a.out format dump Frederic Weisbecker
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Frederic Weisbecker @ 2009-11-10 10:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Paul Mundt, Jan Kiszka, Avi Kivity, K. Prasad, Li Zefan,
	Alan Stern, Peter Zijlstra, Arnaldo Carvalho de Melo,
	Steven Rostedt, Jiri Slaby, Paul Mackerras, Mike Galbraith,
	Masami Hiramatsu, Arjan van de Ven, Ingo Molnar,
	Frederic Weisbecker

From: Paul Mundt <lethal@linux-sh.org>

All of the infrastructure already exists to support read accesses
for platforms that support a read access independently of read/write
(such as in the case of the SuperH UBC). This just trivially hooks
up the read case by itself.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jan Kiszka <jan.kiszka@web.de>
Cc: Jiri Slaby <jirislaby@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
LKML-Reference: <20091109083733.GA25848@linux-sh.org>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/trace/trace_ksym.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c
index fea83ee..11935b5 100644
--- a/kernel/trace/trace_ksym.c
+++ b/kernel/trace/trace_ksym.c
@@ -136,6 +136,7 @@ static int ksym_trace_get_access_type(char *str)
 		access |= HW_BREAKPOINT_X;
 
 	switch (access) {
+	case HW_BREAKPOINT_R:
 	case HW_BREAKPOINT_W:
 	case HW_BREAKPOINT_W | HW_BREAKPOINT_R:
 		return access;
@@ -239,7 +240,9 @@ static ssize_t ksym_trace_filter_read(struct file *filp, char __user *ubuf,
 
 	hlist_for_each_entry(entry, node, &ksym_filter_head, ksym_hlist) {
 		ret = trace_seq_printf(s, "%pS:", (void *)entry->ksym_addr);
-		if (entry->type == HW_BREAKPOINT_W)
+		if (entry->type == HW_BREAKPOINT_R)
+			ret = trace_seq_puts(s, "r--\n");
+		else if (entry->type == HW_BREAKPOINT_W)
 			ret = trace_seq_puts(s, "-w-\n");
 		else if (entry->type == (HW_BREAKPOINT_W | HW_BREAKPOINT_R))
 			ret = trace_seq_puts(s, "rw-\n");
@@ -414,6 +417,9 @@ static enum print_line_t ksym_trace_output(struct trace_iterator *iter)
 		return TRACE_TYPE_PARTIAL_LINE;
 
 	switch (field->type) {
+	case HW_BREAKPOINT_R:
+		ret = trace_seq_printf(s, " R  ");
+		break;
 	case HW_BREAKPOINT_W:
 		ret = trace_seq_printf(s, " W  ");
 		break;
@@ -488,6 +494,9 @@ static int ksym_tracer_stat_show(struct seq_file *m, void *v)
 	access_type = entry->type;
 
 	switch (access_type) {
+	case HW_BREAKPOINT_R:
+		seq_puts(m, "  R           ");
+		break;
 	case HW_BREAKPOINT_W:
 		seq_puts(m, "  W           ");
 		break;
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] hw-breakpoints: Fix broken a.out format dump
  2009-11-10 10:25 [GIT PULL] hw-breakpoints: Various fixes Frederic Weisbecker
  2009-11-10 10:25 ` [PATCH 1/4] ksym_tracer: Support read accesses independent of read/write Frederic Weisbecker
@ 2009-11-10 10:25 ` Frederic Weisbecker
  2009-11-10 10:25 ` [PATCH 3/4] hw-breakpoints: Fix broken hw-breakpoint sample module Frederic Weisbecker
  2009-11-10 10:26 ` [PATCH 4/4] hw-breakpoints: Wrap in the KVM breakpoint active state check Frederic Weisbecker
  3 siblings, 0 replies; 5+ messages in thread
From: Frederic Weisbecker @ 2009-11-10 10:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Frederic Weisbecker, Jan Kiszka, Avi Kivity, K. Prasad,
	Paul Mundt, Li Zefan, Alan Stern, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Steven Rostedt, Jiri Slaby,
	Paul Mackerras, Mike Galbraith, Masami Hiramatsu,
	Arjan van de Ven

Fix the broken a.out format dump. For now we only dump the ptrace
breakpoints.

TODO: Dump every perf breakpoints for the current thread, not only
ptrace based ones.

Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: "K. Prasad" <prasad@linux.vnet.ibm.com>
---
 arch/x86/include/asm/a.out-core.h |   10 ++--------
 arch/x86/include/asm/debugreg.h   |    2 ++
 arch/x86/kernel/hw_breakpoint.c   |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/a.out-core.h b/arch/x86/include/asm/a.out-core.h
index fc4685d..7a15588 100644
--- a/arch/x86/include/asm/a.out-core.h
+++ b/arch/x86/include/asm/a.out-core.h
@@ -17,6 +17,7 @@
 
 #include <linux/user.h>
 #include <linux/elfcore.h>
+#include <asm/debugreg.h>
 
 /*
  * fill in the user structure for an a.out core dump
@@ -32,14 +33,7 @@ static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
 			>> PAGE_SHIFT;
 	dump->u_dsize -= dump->u_tsize;
 	dump->u_ssize = 0;
-	dump->u_debugreg[0] = current->thread.debugreg[0];
-	dump->u_debugreg[1] = current->thread.debugreg[1];
-	dump->u_debugreg[2] = current->thread.debugreg[2];
-	dump->u_debugreg[3] = current->thread.debugreg[3];
-	dump->u_debugreg[4] = 0;
-	dump->u_debugreg[5] = 0;
-	dump->u_debugreg[6] = current->thread.debugreg6;
-	dump->u_debugreg[7] = current->thread.debugreg7;
+	aout_dump_debugregs(dump);
 
 	if (dump->start_stack < TASK_SIZE)
 		dump->u_ssize = ((unsigned long)(TASK_SIZE - dump->start_stack))
diff --git a/arch/x86/include/asm/debugreg.h b/arch/x86/include/asm/debugreg.h
index 9a3333c..f1b673f 100644
--- a/arch/x86/include/asm/debugreg.h
+++ b/arch/x86/include/asm/debugreg.h
@@ -89,6 +89,8 @@ static inline void hw_breakpoint_disable(void)
 	set_debugreg(0UL, 3);
 }
 
+extern void aout_dump_debugregs(struct user *dump);
+
 #ifdef CONFIG_KVM
 extern void hw_breakpoint_restore(void);
 #endif
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index e622620..57dcee5 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -376,6 +376,41 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp,
 }
 
 /*
+ * Dump the debug register contents to the user.
+ * We can't dump our per cpu values because it
+ * may contain cpu wide breakpoint, something that
+ * doesn't belong to the current task.
+ *
+ * TODO: include non-ptrace user breakpoints (perf)
+ */
+void aout_dump_debugregs(struct user *dump)
+{
+	int i;
+	int dr7 = 0;
+	struct perf_event *bp;
+	struct arch_hw_breakpoint *info;
+	struct thread_struct *thread = &current->thread;
+
+	for (i = 0; i < HBP_NUM; i++) {
+		bp = thread->ptrace_bps[i];
+
+		if (bp && !bp->attr.disabled) {
+			dump->u_debugreg[i] = bp->attr.bp_addr;
+			info = counter_arch_bp(bp);
+			dr7 |= encode_dr7(i, info->len, info->type);
+		} else {
+			dump->u_debugreg[i] = 0;
+		}
+	}
+
+	dump->u_debugreg[4] = 0;
+	dump->u_debugreg[5] = 0;
+	dump->u_debugreg[6] = current->thread.debugreg6;
+
+	dump->u_debugreg[7] = dr7;
+}
+
+/*
  * Release the user breakpoints used by ptrace
  */
 void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] hw-breakpoints: Fix broken hw-breakpoint sample module
  2009-11-10 10:25 [GIT PULL] hw-breakpoints: Various fixes Frederic Weisbecker
  2009-11-10 10:25 ` [PATCH 1/4] ksym_tracer: Support read accesses independent of read/write Frederic Weisbecker
  2009-11-10 10:25 ` [PATCH 2/4] hw-breakpoints: Fix broken a.out format dump Frederic Weisbecker
@ 2009-11-10 10:25 ` Frederic Weisbecker
  2009-11-10 10:26 ` [PATCH 4/4] hw-breakpoints: Wrap in the KVM breakpoint active state check Frederic Weisbecker
  3 siblings, 0 replies; 5+ messages in thread
From: Frederic Weisbecker @ 2009-11-10 10:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Frederic Weisbecker, Jan Kiszka, Avi Kivity, K. Prasad,
	Paul Mundt, Li Zefan, Alan Stern, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Steven Rostedt, Jiri Slaby,
	Paul Mackerras, Mike Galbraith, Masami Hiramatsu,
	Arjan van de Ven

The hw-breakpoint sample module has been broken during the
hw-breakpoint internals refactoring. Propagate the changes
to it.

Reported-by: "K. Prasad" <prasad@linux.vnet.ibm.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/hw_breakpoint.c                  |    3 +-
 kernel/kallsyms.c                       |    1 +
 samples/hw_breakpoint/data_breakpoint.c |   43 +++++++++++++++++-------------
 3 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c
index e662dc9..9ea9414 100644
--- a/kernel/hw_breakpoint.c
+++ b/kernel/hw_breakpoint.c
@@ -454,6 +454,7 @@ fail:
 	/* return the error if any */
 	return ERR_PTR(err);
 }
+EXPORT_SYMBOL_GPL(register_wide_hw_breakpoint);
 
 /**
  * unregister_wide_hw_breakpoint - unregister a wide breakpoint in the kernel
@@ -470,7 +471,7 @@ void unregister_wide_hw_breakpoint(struct perf_event **cpu_events)
 	}
 	free_percpu(cpu_events);
 }
-
+EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint);
 
 static struct notifier_block hw_breakpoint_exceptions_nb = {
 	.notifier_call = hw_breakpoint_exceptions_notify,
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 8b6b8b6..8e5288a 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -181,6 +181,7 @@ unsigned long kallsyms_lookup_name(const char *name)
 	}
 	return module_kallsyms_lookup_name(name);
 }
+EXPORT_SYMBOL_GPL(kallsyms_lookup_name);
 
 int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
 				      unsigned long),
diff --git a/samples/hw_breakpoint/data_breakpoint.c b/samples/hw_breakpoint/data_breakpoint.c
index 9cbdbb8..5bc9819 100644
--- a/samples/hw_breakpoint/data_breakpoint.c
+++ b/samples/hw_breakpoint/data_breakpoint.c
@@ -27,18 +27,19 @@
 #include <linux/module.h>	/* Needed by all modules */
 #include <linux/kernel.h>	/* Needed for KERN_INFO */
 #include <linux/init.h>		/* Needed for the macros */
+#include <linux/kallsyms.h>
 
-#include <asm/hw_breakpoint.h>
+#include <linux/perf_event.h>
+#include <linux/hw_breakpoint.h>
 
-struct hw_breakpoint sample_hbp;
+struct perf_event **sample_hbp;
 
 static char ksym_name[KSYM_NAME_LEN] = "pid_max";
 module_param_string(ksym, ksym_name, KSYM_NAME_LEN, S_IRUGO);
 MODULE_PARM_DESC(ksym, "Kernel symbol to monitor; this module will report any"
 			" write operations on the kernel symbol");
 
-void sample_hbp_handler(struct hw_breakpoint *temp, struct pt_regs
-								*temp_regs)
+static void sample_hbp_handler(struct perf_event *temp, void *data)
 {
 	printk(KERN_INFO "%s value is changed\n", ksym_name);
 	dump_stack();
@@ -48,30 +49,34 @@ void sample_hbp_handler(struct hw_breakpoint *temp, struct pt_regs
 static int __init hw_break_module_init(void)
 {
 	int ret;
+	unsigned long addr;
 
-#ifdef CONFIG_X86
-	sample_hbp.info.name = ksym_name;
-	sample_hbp.info.type = HW_BREAKPOINT_WRITE;
-	sample_hbp.info.len = HW_BREAKPOINT_LEN_4;
-#endif /* CONFIG_X86 */
+	addr = kallsyms_lookup_name(ksym_name);
 
-	sample_hbp.triggered = (void *)sample_hbp_handler;
+	sample_hbp = register_wide_hw_breakpoint(addr, HW_BREAKPOINT_LEN_4,
+						 HW_BREAKPOINT_W | HW_BREAKPOINT_R,
+						 sample_hbp_handler, true);
+	if (IS_ERR(sample_hbp)) {
+		ret = PTR_ERR(sample_hbp);
+		goto fail;
+	} else if (!sample_hbp) {
+		ret = -EINVAL;
+		goto fail;
+	}
 
-	ret = register_kernel_hw_breakpoint(&sample_hbp);
-
-	if (ret < 0) {
-		printk(KERN_INFO "Breakpoint registration failed\n");
-		return ret;
-	} else
-		printk(KERN_INFO "HW Breakpoint for %s write installed\n",
-								ksym_name);
+	printk(KERN_INFO "HW Breakpoint for %s write installed\n", ksym_name);
 
 	return 0;
+
+fail:
+	printk(KERN_INFO "Breakpoint registration failed\n");
+
+	return ret;
 }
 
 static void __exit hw_break_module_exit(void)
 {
-	unregister_kernel_hw_breakpoint(&sample_hbp);
+	unregister_wide_hw_breakpoint(sample_hbp);
 	printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name);
 }
 
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] hw-breakpoints: Wrap in the KVM breakpoint active state check
  2009-11-10 10:25 [GIT PULL] hw-breakpoints: Various fixes Frederic Weisbecker
                   ` (2 preceding siblings ...)
  2009-11-10 10:25 ` [PATCH 3/4] hw-breakpoints: Fix broken hw-breakpoint sample module Frederic Weisbecker
@ 2009-11-10 10:26 ` Frederic Weisbecker
  3 siblings, 0 replies; 5+ messages in thread
From: Frederic Weisbecker @ 2009-11-10 10:26 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Frederic Weisbecker, Jan Kiszka, Avi Kivity, K. Prasad,
	Paul Mundt, Li Zefan, Alan Stern, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Steven Rostedt, Jiri Slaby,
	Paul Mackerras, Mike Galbraith, Masami Hiramatsu,
	Arjan van de Ven

Wrap in the cpu dr7 check that tells if we have active
breakpoints that need to be restored in the cpu.

This wrapper makes the check more self-explainable and also
reusable for any further other uses.

Reported-by: Jan Kiszka <jan.kiszka@web.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: "K. Prasad" <prasad@linux.vnet.ibm.com>
---
 arch/x86/include/asm/debugreg.h |    5 +++++
 arch/x86/kvm/x86.c              |    2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/debugreg.h b/arch/x86/include/asm/debugreg.h
index f1b673f..0f6e92a 100644
--- a/arch/x86/include/asm/debugreg.h
+++ b/arch/x86/include/asm/debugreg.h
@@ -89,6 +89,11 @@ static inline void hw_breakpoint_disable(void)
 	set_debugreg(0UL, 3);
 }
 
+static inline int hw_breakpoint_active(void)
+{
+	return __get_cpu_var(dr7) & DR_GLOBAL_ENABLE_MASK;
+}
+
 extern void aout_dump_debugregs(struct user *dump);
 
 #ifdef CONFIG_KVM
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 22dee7a..3817220 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3651,7 +3651,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 	 * care about the messed up debug address registers. But if
 	 * we have some of them active, restore the old state.
 	 */
-	if (__get_cpu_var(dr7) & DR_GLOBAL_ENABLE_MASK)
+	if (hw_breakpoint_active())
 		hw_breakpoint_restore();
 
 	set_bit(KVM_REQ_KICK, &vcpu->requests);
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-11-10 10:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-10 10:25 [GIT PULL] hw-breakpoints: Various fixes Frederic Weisbecker
2009-11-10 10:25 ` [PATCH 1/4] ksym_tracer: Support read accesses independent of read/write Frederic Weisbecker
2009-11-10 10:25 ` [PATCH 2/4] hw-breakpoints: Fix broken a.out format dump Frederic Weisbecker
2009-11-10 10:25 ` [PATCH 3/4] hw-breakpoints: Fix broken hw-breakpoint sample module Frederic Weisbecker
2009-11-10 10:26 ` [PATCH 4/4] hw-breakpoints: Wrap in the KVM breakpoint active state check Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®