mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [GIT PULL] hw-breakpoints fixes
@ 2009-12-07  6:22 Frederic Weisbecker
  2009-12-07  6:22 ` [PATCH 1/2] hw-breakpoints: Zeroe the breakpoint attrs on initialization Frederic Weisbecker
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2009-12-07  6:22 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: LKML, Frederic Weisbecker, Walt, Prasad

Ingo,

Please pull the perf/urgent branch that can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
	perf/urgent

The first patch prevents from stack randomnesses in a breakpoint
definition.
The second fixes a ptrace regression reported by walt.

Thanks,
	Frederic
---

Frederic Weisbecker (2):
      hw-breakpoints: Zeroe the breakpoint attrs on initialization
      hw-breakpoints: Fix task-bound breakpoint slot allocation


 include/linux/hw_breakpoint.h |    2 +
 kernel/hw_breakpoint.c        |   74 +++++++++++++++++++++++++----------------
 2 files changed, 47 insertions(+), 29 deletions(-)

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

* [PATCH 1/2] hw-breakpoints: Zeroe the breakpoint attrs on initialization
  2009-12-07  6:22 [GIT PULL] hw-breakpoints fixes Frederic Weisbecker
@ 2009-12-07  6:22 ` Frederic Weisbecker
  2009-12-07  6:22 ` [PATCH 2/2] hw-breakpoints: Fix task-bound breakpoint slot allocation Frederic Weisbecker
  2009-12-07  7:04 ` [GIT PULL] hw-breakpoints fixes Ingo Molnar
  2 siblings, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2009-12-07  6:22 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: LKML, Frederic Weisbecker, Walt, Prasad

The perf attrs used to set up breakpoint parameters are often allocated
in the stack and not zeroed out before calling hw_breakpoint_init().
Handle it from this helper to avoid random attributes set by the stack.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Prasad <prasad@linux.vnet.ibm.com>
---
 include/linux/hw_breakpoint.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h
index 4d14a38..42da1ce 100644
--- a/include/linux/hw_breakpoint.h
+++ b/include/linux/hw_breakpoint.h
@@ -22,6 +22,8 @@ enum {
 
 static inline void hw_breakpoint_init(struct perf_event_attr *attr)
 {
+	memset(attr, 0, sizeof(*attr));
+
 	attr->type = PERF_TYPE_BREAKPOINT;
 	attr->size = sizeof(*attr);
 	/*
-- 
1.6.2.3


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

* [PATCH 2/2] hw-breakpoints: Fix task-bound breakpoint slot allocation
  2009-12-07  6:22 [GIT PULL] hw-breakpoints fixes Frederic Weisbecker
  2009-12-07  6:22 ` [PATCH 1/2] hw-breakpoints: Zeroe the breakpoint attrs on initialization Frederic Weisbecker
@ 2009-12-07  6:22 ` Frederic Weisbecker
  2009-12-07  7:04 ` [GIT PULL] hw-breakpoints fixes Ingo Molnar
  2 siblings, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2009-12-07  6:22 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: LKML, Frederic Weisbecker, Walt, Prasad

Whatever the context nature of a breakpoint, we always perform the
following constraint checks before allocating it a slot:

- Check the number of pinned breakpoint bound the concerned cpus
- Check the max number of task-bound breakpoints that are belonging
  to a task.
- Add both and see if we have a reamining slot for the new breakpoint

This is the right thing to do when we are about to register a cpu-only
bound breakpoint. But not if we are dealing with a task bound
breakpoint. What we want in this case is:

- Check the number of pinned breakpoint bound the concerned cpus
- Check the number of breakpoints that already belong to the task
  in which the breakpoint to register is bound to.
- Add both

This fixes a regression that makes the "firefox -g" command fail to
register breakpoints once we deal with a secondary thread.

Reported-by: Walt <w41ter@gmail.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Prasad <prasad@linux.vnet.ibm.com>
---
 kernel/hw_breakpoint.c |   74 +++++++++++++++++++++++++++++-------------------
 1 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c
index b600fc2..02b4925 100644
--- a/kernel/hw_breakpoint.c
+++ b/kernel/hw_breakpoint.c
@@ -83,15 +83,51 @@ static unsigned int max_task_bp_pinned(int cpu)
 	return 0;
 }
 
+static int task_bp_pinned(struct task_struct *tsk)
+{
+	struct perf_event_context *ctx = tsk->perf_event_ctxp;
+	struct list_head *list;
+	struct perf_event *bp;
+	unsigned long flags;
+	int count = 0;
+
+	if (WARN_ONCE(!ctx, "No perf context for this task"))
+		return 0;
+
+	list = &ctx->event_list;
+
+	spin_lock_irqsave(&ctx->lock, flags);
+
+	/*
+	 * The current breakpoint counter is not included in the list
+	 * at the open() callback time
+	 */
+	list_for_each_entry(bp, list, event_entry) {
+		if (bp->attr.type == PERF_TYPE_BREAKPOINT)
+			count++;
+	}
+
+	spin_unlock_irqrestore(&ctx->lock, flags);
+
+	return count;
+}
+
 /*
  * Report the number of pinned/un-pinned breakpoints we have in
  * a given cpu (cpu > -1) or in all of them (cpu = -1).
  */
-static void fetch_bp_busy_slots(struct bp_busy_slots *slots, int cpu)
+static void
+fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp)
 {
+	int cpu = bp->cpu;
+	struct task_struct *tsk = bp->ctx->task;
+
 	if (cpu >= 0) {
 		slots->pinned = per_cpu(nr_cpu_bp_pinned, cpu);
-		slots->pinned += max_task_bp_pinned(cpu);
+		if (!tsk)
+			slots->pinned += max_task_bp_pinned(cpu);
+		else
+			slots->pinned += task_bp_pinned(tsk);
 		slots->flexible = per_cpu(nr_bp_flexible, cpu);
 
 		return;
@@ -101,7 +137,10 @@ static void fetch_bp_busy_slots(struct bp_busy_slots *slots, int cpu)
 		unsigned int nr;
 
 		nr = per_cpu(nr_cpu_bp_pinned, cpu);
-		nr += max_task_bp_pinned(cpu);
+		if (!tsk)
+			nr += max_task_bp_pinned(cpu);
+		else
+			nr += task_bp_pinned(tsk);
 
 		if (nr > slots->pinned)
 			slots->pinned = nr;
@@ -118,33 +157,10 @@ static void fetch_bp_busy_slots(struct bp_busy_slots *slots, int cpu)
  */
 static void toggle_bp_task_slot(struct task_struct *tsk, int cpu, bool enable)
 {
-	int count = 0;
-	struct perf_event *bp;
-	struct perf_event_context *ctx = tsk->perf_event_ctxp;
 	unsigned int *tsk_pinned;
-	struct list_head *list;
-	unsigned long flags;
-
-	if (WARN_ONCE(!ctx, "No perf context for this task"))
-		return;
-
-	list = &ctx->event_list;
-
-	spin_lock_irqsave(&ctx->lock, flags);
-
-	/*
-	 * The current breakpoint counter is not included in the list
-	 * at the open() callback time
-	 */
-	list_for_each_entry(bp, list, event_entry) {
-		if (bp->attr.type == PERF_TYPE_BREAKPOINT)
-			count++;
-	}
-
-	spin_unlock_irqrestore(&ctx->lock, flags);
+	int count = 0;
 
-	if (WARN_ONCE(count < 0, "No breakpoint counter found in the counter list"))
-		return;
+	count = task_bp_pinned(tsk);
 
 	tsk_pinned = per_cpu(task_bp_pinned, cpu);
 	if (enable) {
@@ -233,7 +249,7 @@ int reserve_bp_slot(struct perf_event *bp)
 
 	mutex_lock(&nr_bp_mutex);
 
-	fetch_bp_busy_slots(&slots, bp->cpu);
+	fetch_bp_busy_slots(&slots, bp);
 
 	/* Flexible counters need to keep at least one slot */
 	if (slots.pinned + (!!slots.flexible) == HBP_NUM) {
-- 
1.6.2.3


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

* Re: [GIT PULL] hw-breakpoints fixes
  2009-12-07  6:22 [GIT PULL] hw-breakpoints fixes Frederic Weisbecker
  2009-12-07  6:22 ` [PATCH 1/2] hw-breakpoints: Zeroe the breakpoint attrs on initialization Frederic Weisbecker
  2009-12-07  6:22 ` [PATCH 2/2] hw-breakpoints: Fix task-bound breakpoint slot allocation Frederic Weisbecker
@ 2009-12-07  7:04 ` Ingo Molnar
  2 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2009-12-07  7:04 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: LKML, Walt, Prasad


* Frederic Weisbecker <fweisbec@gmail.com> wrote:

> Ingo,
> 
> Please pull the perf/urgent branch that can be found at:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
> 	perf/urgent
> 
> The first patch prevents from stack randomnesses in a breakpoint
> definition.
> The second fixes a ptrace regression reported by walt.
> 
> Thanks,
> 	Frederic
> ---
> 
> Frederic Weisbecker (2):
>       hw-breakpoints: Zeroe the breakpoint attrs on initialization
>       hw-breakpoints: Fix task-bound breakpoint slot allocation
> 
> 
>  include/linux/hw_breakpoint.h |    2 +
>  kernel/hw_breakpoint.c        |   74 +++++++++++++++++++++++++----------------
>  2 files changed, 47 insertions(+), 29 deletions(-)

Pulled, thanks a lot Frederic!

	Ingo

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

end of thread, other threads:[~2009-12-07  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-07  6:22 [GIT PULL] hw-breakpoints fixes Frederic Weisbecker
2009-12-07  6:22 ` [PATCH 1/2] hw-breakpoints: Zeroe the breakpoint attrs on initialization Frederic Weisbecker
2009-12-07  6:22 ` [PATCH 2/2] hw-breakpoints: Fix task-bound breakpoint slot allocation Frederic Weisbecker
2009-12-07  7:04 ` [GIT PULL] hw-breakpoints fixes Ingo Molnar

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®