Skip to contentSkip to conversation

hw-breakpoints: Various fixes

GIT PULL New Frederic Weisbecker 1 participant 5 messages Nov 10, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

PATCH 1/4 ksym_tracer: Support read accesses independent of read/write.

From: Paul Mundt <[email protected]>

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.

Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Prasad <[email protected]>
Cc Alan Stern <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Jan Kiszka <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Avi Kivity <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Arjan van de Ven <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_ksym.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
kernel/trace/trace_ksym.c +10 -1
index fea83ee..11935b5 100644
@@ -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;
Signature · 1 line
1.6.2.3
#2 lore raw

PATCH 2/4 hw-breakpoints: Fix broken a.out format dump

In reply to Frederic Weisbecker

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.

---
 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(-)
arch/x86/include/asm/a.out-core.h +2 -8
index fc4685d..7a15588 100644
@@ -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))
arch/x86/include/asm/debugreg.h +2 -0
index 9a3333c..f1b673f 100644
@@ -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
arch/x86/kernel/hw_breakpoint.c +35 -0
index e622620..57dcee5 100644
@@ -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)
Signature · 1 line
1.6.2.3
#3 lore raw

PATCH 3/4 hw-breakpoints: Fix broken hw-breakpoint sample module

In reply to Frederic Weisbecker

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

---
 kernel/hw_breakpoint.c                  |    3 +-
 kernel/kallsyms.c                       |    1 +
 samples/hw_breakpoint/data_breakpoint.c |   43 +++++++++++++++++-------------
 3 files changed, 27 insertions(+), 20 deletions(-)
kernel/hw_breakpoint.c +2 -1
index e662dc9..9ea9414 100644
@@ -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,
kernel/kallsyms.c +1 -0
index 8b6b8b6..8e5288a 100644
@@ -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),
samples/hw_breakpoint/data_breakpoint.c +24 -19

72 lines not on this page · raw message

Signature · 1 line
1.6.2.3
#4 lore raw

PATCH 4/4 hw-breakpoints: Wrap in the KVM breakpoint active state check

In reply to Frederic Weisbecker

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.

---
 arch/x86/include/asm/debugreg.h |    5 +++++
 arch/x86/kvm/x86.c              |    2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/include/asm/debugreg.h +5 -0
index f1b673f..0f6e92a 100644
@@ -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
arch/x86/kvm/x86.c +1 -1
index 22dee7a..3817220 100644
@@ -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);
Signature · 1 line
1.6.2.3