Skip to contentSkip to conversation

Invoke __perf_event_disable without an IPI

PATCH In review K.Prasad 6 participants 17 messages Jun 11, 2012 – Sep 4, 2012 perf events

lore
Share & tools
lore

K.Prasad

author
#0 lore raw

PATCH 1/1 Invoke __perf_event_disable without an IPI

Hi All,
Please review the following patch, the details of which are
described in the commit message below.

Basic perf commands (and memory tracing event '-e mem') were tested to work fine with this patch and can be applied over commit b1dab2f0409c478fd2d9e227c2c018524eca9603.

Kindly let me know if there could be a better approach or if there's a need for further testing.

Thanks,
K.Prasad

---

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch avoids the use of an IPI to invoke __perf_event_disable when it is safe to do so i.e. when the process associated with the perf-event would run on the current CPU and interrupts are disabled on the system. Since interrupts are always disabled before hw_breakpoint_handler in PowerPC, the warning message will no longer be seen.

---
 kernel/events/core.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
kernel/events/core.c +12 -0
index fd126f8..0e2c1eb 100644
@@ -1302,6 +1302,7 @@ static int __perf_event_disable(void *info)
  */
 void perf_event_disable(struct perf_event *event)
 {
+	int ret;
 	struct perf_event_context *ctx = event->ctx;
 	struct task_struct *task = ctx->task;
 
@@ -1314,6 +1315,17 @@ void perf_event_disable(struct perf_event *event)
 	}
 
 retry:
+	/*
+	 * perf_event_disable may be called when interrupts are disabled.
+	 * For e.g. hw_breakpoint_handler exception in PowerPC. Hence using
+	 * IPIs to invoke __perf_event_disable is not always suitable. When
+	 * possible invoke __perf_event_disable directly.
+	 */
+	if ((task_cpu(task) == smp_processor_id()) && irqs_disabled()) {
+		ret = __perf_event_disable(event);
+		if (!ret)
+			return;
+	}
 	if (!task_function_call(task, __perf_event_disable, event))
 		return;
 
#1 lore raw
Quoted 31 lines · K.Prasad

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch avoids the use of an IPI to invoke __perf_event_disable when it is safe to do so i.e. when the process associated with the perf-event would run on the current CPU and interrupts are disabled on the system. Since interrupts are always disabled before hw_breakpoint_handler in PowerPC, the warning message will no longer be seen.

---
 kernel/events/core.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
kernel/events/core.c +1 -0
index fd126f8..0e2c1eb 100644
@@ -1302,6 +1302,7 @@ static int __perf_event_disable(void *info)
  */
 void perf_event_disable(struct perf_event *event)
 {
+	int ret;
 	struct perf_event_context *ctx = event->ctx;
 	struct task_struct *task = ctx->task;
 

kernel/events/core.c void perf_event_disable(struct perf_event *event) · line 1324

Quoted 10 lines
kernel/events/core.c +7 -0
@@ -1314,6 +1315,17 @@ void perf_event_disable(struct perf_event *event)
 	}
 
 retry:
+	/*
+	 * perf_event_disable may be called when interrupts are disabled.
+	 * For e.g. hw_breakpoint_handler exception in PowerPC. Hence using
+	 * IPIs to invoke __perf_event_disable is not always suitable. When
+	 * possible invoke __perf_event_disable directly.
+	 */
+	if ((task_cpu(task) == smp_processor_id()) && irqs_disabled()) {

Urgh..

So what's the callchain for the ppc->hw_bp->perf that triggers this?

Quoted 8 lines
kernel/events/core.c +4 -0
+		ret = __perf_event_disable(event);
+		if (!ret)
+			return;
+	}
 	if (!task_function_call(task, __perf_event_disable, event))
 		return;
 
author
#2 lore raw
Quoted 28 lines · Peter Zijlstra
Quoted 13 lines · K.Prasad
kernel/events/core.c +1 -0
index fd126f8..0e2c1eb 100644
@@ -1302,6 +1302,7 @@ static int __perf_event_disable(void *info)
  */
 void perf_event_disable(struct perf_event *event)
 {
+	int ret;
 	struct perf_event_context *ctx = event->ctx;
 	struct task_struct *task = ctx->task;
 

kernel/events/core.c void perf_event_disable(struct perf_event *event) · line 1324

Quoted 10 lines
kernel/events/core.c +7 -0
@@ -1314,6 +1315,17 @@ void perf_event_disable(struct perf_event *event)
 	}
 
 retry:
+	/*
+	 * perf_event_disable may be called when interrupts are disabled.
+	 * For e.g. hw_breakpoint_handler exception in PowerPC. Hence using
+	 * IPIs to invoke __perf_event_disable is not always suitable. When
+	 * possible invoke __perf_event_disable directly.
+	 */
+	if ((task_cpu(task) == smp_processor_id()) && irqs_disabled()) {

Urgh..

Quoted 1 line

So what's the callchain for the ppc->hw_bp->perf that triggers this?

Hardware breakpoints for user-space have traditionally operated in a one-shot mode i.e. breakpoint is disabled after the first hit by invoking perf_event_disable from hw_breakpoint_handler.

PowerPC server class processors follow 'trigger-before-execute', wherein the breakpoint exception is triggered before the instruction performing the memory access is executed. So the one-shot mode prevents the processor from entering an infinite loop and the debugging tools like GDB re-enable the breakpoints explicitly after a SIGTRAP.

Thanks,
K.Prasad

#3 lore raw
Quoted 29 lines · K.Prasad
Quoted 28 lines · Peter Zijlstra
Quoted 13 lines · K.Prasad
kernel/events/core.c +1 -0
index fd126f8..0e2c1eb 100644
@@ -1302,6 +1302,7 @@ static int __perf_event_disable(void *info)
  */
 void perf_event_disable(struct perf_event *event)
 {
+	int ret;
 	struct perf_event_context *ctx = event->ctx;
 	struct task_struct *task = ctx->task;
 

kernel/events/core.c void perf_event_disable(struct perf_event *event) · line 1324

Quoted 10 lines
kernel/events/core.c +7 -0
@@ -1314,6 +1315,17 @@ void perf_event_disable(struct perf_event *event)
 	}
 
 retry:
+	/*
+	 * perf_event_disable may be called when interrupts are disabled.
+	 * For e.g. hw_breakpoint_handler exception in PowerPC. Hence using
+	 * IPIs to invoke __perf_event_disable is not always suitable. When
+	 * possible invoke __perf_event_disable directly.
+	 */
+	if ((task_cpu(task) == smp_processor_id()) && irqs_disabled()) {

Urgh..

Quoted 5 lines
Quoted 1 line

So what's the callchain for the ppc->hw_bp->perf that triggers this?

Hardware breakpoints for user-space have traditionally operated in a one-shot mode i.e. breakpoint is disabled after the first hit by invoking perf_event_disable from hw_breakpoint_handler.

I take it this is the same across architectures? So basically everybody suffers this?

Hmm,. x86 doesn't seem to do this.. are you saying breakpoint semantics differ across architectures? Really?

Oh man how I do hate this breakpoint crap.. I guess you might as well use __perf_event_disable() directly, no point in butchering perf_event_disable() or even task_function_call().

#4 lore raw

PATCH v2 1/1 Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Please find v2 of the patch from Prasad, based on Peter Zijlstra's feedback. This applies on top of v3.5-rc5. This has been tested and found to work fine by Edjunior.

Regards,
Naveen

---
While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
 include/linux/perf_event.h    |    2 ++
 kernel/events/core.c          |    2 +-
 kernel/events/hw_breakpoint.c |   10 +++++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
 extern void perf_event_task_tick(void);
 #else
 static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
 static inline void perf_event_task_tick(void)				{ }
 #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
 /*
  * Cross CPU call to disable a performance event
  */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
 {
 	struct perf_event *event = info;
 	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +9 -1
index bb38c4d..483f14a 100644
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
 	int old_type = bp->attr.bp_type;
 	int err = 0;
 
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly.
+	 */
+	if (irqs_disabled())
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);
 
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;
#5 lore raw

PATCH v2 1/1 Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

From: K.Prasad <[email protected]>

My apologies. I missed the From header in my previous mail.

---
Please find v2 of the patch from Prasad, based on Peter Zijlstra's feedback. This applies on top of v3.5-rc5. This has been tested and found to work fine by Edjunior.

Regards,
Naveen

---
While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
 include/linux/perf_event.h    |    2 ++
 kernel/events/core.c          |    2 +-
 kernel/events/hw_breakpoint.c |   10 +++++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
 extern void perf_event_task_tick(void);
 #else
 static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
 static inline void perf_event_task_tick(void)				{ }
 #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
 /*
  * Cross CPU call to disable a performance event
  */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
 {
 	struct perf_event *event = info;
 	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +9 -1
index bb38c4d..483f14a 100644
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
 	int old_type = bp->attr.bp_type;
 	int err = 0;
 
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly.
+	 */
+	if (irqs_disabled())
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);
 
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;
#6 lore raw

PATCH RESEND v2 1/1 Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Please find v2 of the patch from Prasad, based on Peter Zijlstra's feedback. This applies on top of v3.5-rc7. This has been tested and found to work fine by Edjunior.

Regards,
Naveen
______

From: K.Prasad <[email protected]>

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
 include/linux/perf_event.h    |    2 ++
 kernel/events/core.c          |    2 +-
 kernel/events/hw_breakpoint.c |   10 +++++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
 extern void perf_event_task_tick(void);
 #else
 static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
 static inline void perf_event_task_tick(void)				{ }
 #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
 /*
  * Cross CPU call to disable a performance event
  */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
 {
 	struct perf_event *event = info;
 	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +9 -1
index bb38c4d..483f14a 100644
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
 	int old_type = bp->attr.bp_type;
 	int err = 0;
 
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly.
+	 */
+	if (irqs_disabled())
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);
 
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;
#7 lore raw

Re: [PATCH v2 RESEND] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 69 lines · Naveen N. Rao

Please find v2 of the patch from Prasad, based on Peter Zijlstra's feedback. This applies on top of v3.5-rc7. This has been tested and found to work fine by Edjunior.

Regards,
Naveen
______

From: K.Prasad <[email protected]>

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
 include/linux/perf_event.h    |    2 ++
 kernel/events/core.c          |    2 +-
 kernel/events/hw_breakpoint.c |   10 +++++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
 extern void perf_event_task_tick(void);
 #else
 static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
 static inline void perf_event_task_tick(void)				{ }
 #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
 /*
  * Cross CPU call to disable a performance event
  */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
 {
 	struct perf_event *event = info;
 	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +0 -0
index bb38c4d..483f14a 100644
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
 	int old_type = bp->attr.bp_type;
 	int err = 0;
 

kernel/events/hw_breakpoint.c int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att · line 464

Quoted 10 lines
kernel/events/hw_breakpoint.c +9 -1
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly.
+	 */
+	if (irqs_disabled())
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);

This only works if we are sure the bp is on the current CPU. Do we have that guarantee?

Quoted 4 lines
kernel/events/hw_breakpoint.c +0 -0
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;
 
#8 lore raw

Re: [PATCH v2 RESEND] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 70 lines · Frederic Weisbecker
Quoted 69 lines · Naveen N. Rao

Please find v2 of the patch from Prasad, based on Peter Zijlstra's feedback. This applies on top of v3.5-rc7. This has been tested and found to work fine by Edjunior.

Regards,
Naveen
______

From: K.Prasad <[email protected]>

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
  include/linux/perf_event.h    |    2 ++
  kernel/events/core.c          |    2 +-
  kernel/events/hw_breakpoint.c |   10 +++++++++-
  3 files changed, 12 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
  extern void perf_swevent_put_recursion_context(int rctx);
  extern void perf_event_enable(struct perf_event *event);
  extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
  extern void perf_event_task_tick(void);
  #else
  static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
  static inline void perf_swevent_put_recursion_context(int rctx)		{ }
  static inline void perf_event_enable(struct perf_event *event)		{ }
  static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
  static inline void perf_event_task_tick(void)				{ }
  #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
  /*
   * Cross CPU call to disable a performance event
   */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
  {
  	struct perf_event *event = info;
  	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +0 -0
index bb38c4d..483f14a 100644
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
  	int old_type = bp->attr.bp_type;
  	int err = 0;
 
Quoted 13 lines

kernel/events/hw_breakpoint.c int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att · line 464

Quoted 10 lines
kernel/events/hw_breakpoint.c +9 -1
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly.
+	 */
+	if (irqs_disabled())
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);

This only works if we are sure the bp is on the current CPU. Do we have that guarantee?

Yes. This is being hit during bp exception processing and is specific to ppc where we disable interrupts: hw_breakpoint_handler->perf_bp_event->ptrace_triggered->modify_user_hw_breakpoint()

Regards,
Naveen

Quoted 6 lines
Quoted 5 lines
kernel/events/hw_breakpoint.c +0 -0
  	bp->attr.bp_addr = attr->bp_addr;
  	bp->attr.bp_type = attr->bp_type;
 
#9 lore raw

Re: [PATCH v2 RESEND] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 94 lines · Naveen N. Rao
Quoted 77 lines · Frederic Weisbecker
Quoted 76 lines · Naveen N. Rao

Please find v2 of the patch from Prasad, based on Peter Zijlstra's feedback. This applies on top of v3.5-rc7. This has been tested and found to work fine by Edjunior.

Regards,
Naveen
______

From: K.Prasad <[email protected]>

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
  include/linux/perf_event.h    |    2 ++
  kernel/events/core.c          |    2 +-
  kernel/events/hw_breakpoint.c |   10 +++++++++-
  3 files changed, 12 insertions(+), 2 deletions(-)
include/linux/perf_event.h +1 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int
 perf_swevent_get_recursion_context(void);
  extern void perf_swevent_put_recursion_context(int rctx);
  extern void perf_event_enable(struct perf_event *event);
  extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
  extern void perf_event_task_tick(void);
  #else

static inline void

include/linux/perf_event.h +0 -0
@@ -1330,6 +1331,7 @@ static inline int
 perf_swevent_get_recursion_context(void)        { return -1; }
  static inline void perf_swevent_put_recursion_context(int
 rctx)        { }
  static inline void perf_event_enable(struct perf_event
 *event)        { }
  static inline void perf_event_disable(struct perf_event

*event) { }

include/linux/perf_event.h +1 -0
+static inline int __perf_event_disable(void *info)            { }
  static inline void perf_event_task_tick(void)                { }
  #endif
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
  /*
   * Cross CPU call to disable a performance event
   */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
  {
      struct perf_event *event = info;
      struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +0 -0
index bb38c4d..483f14a 100644
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event
 *bp, struct perf_event_attr *att
      int old_type = bp->attr.bp_type;
      int err = 0;
 
Quoted 15 lines

kernel/events/hw_breakpoint.c int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att · line 464

Quoted 12 lines
kernel/events/hw_breakpoint.c +2 -1
-    perf_event_disable(bp);
+    /*
+     * modify_user_hw_breakpoint can be invoked with IRQs disabled

and hence it
+ * will not be possible to raise IPIs that invoke
__perf_event_disable.

kernel/events/hw_breakpoint.c +6 -0
+     * So call the function directly.
+     */
+    if (irqs_disabled())
+        __perf_event_disable(bp);
+    else
+        perf_event_disable(bp);

This only works if we are sure the bp is on the current CPU. Do we have that guarantee?

Quoted 3 lines

Yes. This is being hit during bp exception processing and is specific to ppc where we disable interrupts:
hw_breakpoint_handler->perf_bp_event->ptrace_triggered->modify_user_hw_breakpoint()

Frederick,
Is this acceptable, or do you have other scenarios where this won't work? I can add a check to ensure we call __perf_event_disable only if the task is on the current CPU, but the above scenario is the only one where we're seeing this issue.

Thanks,
Naveen

#10 lore raw

Re: [PATCH v2 RESEND] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 25 lines · Naveen N. Rao
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
kernel/events/hw_breakpoint.c +0 -0
@@ -453,7 +453,15 @@ int modify_user_hw_breakpoint(struct perf_event
 *bp, struct perf_event_attr *att
     int old_type = bp->attr.bp_type;
     int err = 0;
 
Quoted 15 lines

kernel/events/hw_breakpoint.c int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att · line 464

Quoted 12 lines
kernel/events/hw_breakpoint.c +2 -1
-    perf_event_disable(bp);
+    /*
+     * modify_user_hw_breakpoint can be invoked with IRQs disabled

and hence it
+ * will not be possible to raise IPIs that invoke
__perf_event_disable.

kernel/events/hw_breakpoint.c +6 -0
+     * So call the function directly.
+     */
+    if (irqs_disabled())
+        __perf_event_disable(bp);
+    else
+        perf_event_disable(bp);

This only works if we are sure the bp is on the current CPU. Do we have that guarantee?

Quoted 3 lines

Yes. This is being hit during bp exception processing and is specific to ppc where we disable interrupts:
hw_breakpoint_handler->perf_bp_event->ptrace_triggered->modify_user_hw_breakpoint()

Quoted 5 lines

Frederick,
Is this acceptable, or do you have other scenarios where this won't work? I can add a check to ensure we call __perf_event_disable only if the task is on the current CPU, but the above scenario is the only one where we're seeing this issue.

Yeah, please make sure that the targeted task is "current".

#11 lore raw

PATCH v3 1/1 Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Hi Frederick,
I've added a check to make sure we are targeting the current task. This applies on top of v3.5. Kindly review.

Thanks,
Naveen

History:
v3: Added check to make sure we only target "current" task.
v2: Use __perf_event_disable() directly
______

From: K.Prasad <[email protected]>

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

[[email protected]: v3: Check to make sure we target current task]
---
 include/linux/perf_event.h    |    2 ++
 kernel/events/core.c          |    2 +-
 kernel/events/hw_breakpoint.c |   11 ++++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
 extern void perf_event_task_tick(void);
 #else
 static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
 static inline void perf_event_task_tick(void)				{ }
 #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
 /*
  * Cross CPU call to disable a performance event
  */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
 {
 	struct perf_event *event = info;
 	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +10 -1
index bb38c4d..9a7b487 100644
@@ -453,7 +453,16 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
 	int old_type = bp->attr.bp_type;
 	int err = 0;
 
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly after making sure we are targeting the
+	 * current task.
+	 */
+	if (irqs_disabled() && bp->ctx && bp->ctx->task == current)
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);
 
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;
#12 lore raw

Re: [PATCH v3] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Hi Frederick,
Did you get a chance to take a look at this?

Regards,
Naveen

Quoted 89 lines · Naveen N. Rao

Hi Frederick,
I've added a check to make sure we are targeting the current task. This applies on top of v3.5. Kindly review.

Thanks,
Naveen

History:
v3: Added check to make sure we only target "current" task.
v2: Use __perf_event_disable() directly
______

From: K.Prasad <[email protected]>

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

[[email protected]: v3: Check to make sure we target current task]
---
  include/linux/perf_event.h    |    2 ++
  kernel/events/core.c          |    2 +-
  kernel/events/hw_breakpoint.c |   11 ++++++++++-
  3 files changed, 13 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index 45db49f..c289ba0 100644
@@ -1292,6 +1292,7 @@ extern int perf_swevent_get_recursion_context(void);
  extern void perf_swevent_put_recursion_context(int rctx);
  extern void perf_event_enable(struct perf_event *event);
  extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
  extern void perf_event_task_tick(void);
  #else
  static inline void
@@ -1330,6 +1331,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
  static inline void perf_swevent_put_recursion_context(int rctx)		{ }
  static inline void perf_event_enable(struct perf_event *event)		{ }
  static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ }
  static inline void perf_event_task_tick(void)				{ }
  #endif
 
kernel/events/core.c +1 -1
index d7d71d6..0ad0fc9 100644
@@ -1253,7 +1253,7 @@ retry:
  /*
   * Cross CPU call to disable a performance event
   */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
  {
  	struct perf_event *event = info;
  	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +10 -1
index bb38c4d..9a7b487 100644
@@ -453,7 +453,16 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
  	int old_type = bp->attr.bp_type;
  	int err = 0;
 
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly after making sure we are targeting the
+	 * current task.
+	 */
+	if (irqs_disabled() && bp->ctx && bp->ctx->task == current)
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);
 
  	bp->attr.bp_addr = attr->bp_addr;
  	bp->attr.bp_type = attr->bp_type;
#13 lore raw

Re: [PATCH v3] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 5 lines · Naveen N. Rao

Hi Frederick,
Did you get a chance to take a look at this?

Regards,
Naveen

Yeah, I'm ok with the patch. Peter, are you ok with it?

Thanks.

maintainer
#14 lore raw

Re: [PATCH v3] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 8 lines · Frederic Weisbecker
Quoted 5 lines · Naveen N. Rao

Hi Frederick,
Did you get a chance to take a look at this?

Regards,
Naveen

Yeah, I'm ok with the patch. Peter, are you ok with it?

Yeah, queued, it. sorry for loosing track etc..

#15 lore raw

Re: [PATCH v3] Hardware breakpoints: Invoke __perf_event_disable() if interrupts are already disabled

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Frederic Weisbecker
Quoted 3 lines · Naveen N. Rao

Hi Frederick,
Did you get a chance to take a look at this?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Regards,
Naveen

Yeah, I'm ok with the patch. Peter, are you ok with it?

Yeah, queued, it. sorry for loosing track etc..

Hi Peter,
Can you please let me know if you plan to push this for v3.6 or if this has been queued for the next kernel release?

Thanks,
Naveen

#16 lore raw

[tip:perf/urgent] perf/hwpb: Invoke __perf_event_disable() if interrupts are already disabled

In reply to Naveen N. Rao
Commit-ID:  500ad2d8b01390c98bc6dce068bccfa9534b8212
Gitweb:     http://git.kernel.org/tip/500ad2d8b01390c98bc6dce068bccfa9534b8212
Author:     K.Prasad <[email protected]>
AuthorDate: Thu, 2 Aug 2012 13:46:35 +0530
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 4 Sep 2012 17:29:53 +0200

perf/hwpb: Invoke __perf_event_disable() if interrupts are already disabled

While debugging a warning message on PowerPC while using hardware breakpoints, it was discovered that when perf_event_disable is invoked through hw_breakpoint_handler function with interrupts disabled, a subsequent IPI in the code path would trigger a WARN_ON_ONCE message in smp_call_function_single function.

This patch calls __perf_event_disable() when interrupts are already disabled, instead of perf_event_disable().

---
 include/linux/perf_event.h    |    2 ++
 kernel/events/core.c          |    2 +-
 kernel/events/hw_breakpoint.c |   11 ++++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
include/linux/perf_event.h +2 -0
index ad04dfc..33ed9d6 100644
@@ -1296,6 +1296,7 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int __perf_event_disable(void *info);
 extern void perf_event_task_tick(void);
 #else
 static inline void
@@ -1334,6 +1335,7 @@ static inline int  perf_swevent_get_recursion_context(void)		{ return -1; }
 static inline void perf_swevent_put_recursion_context(int rctx)		{ }
 static inline void perf_event_enable(struct perf_event *event)		{ }
 static inline void perf_event_disable(struct perf_event *event)		{ }
+static inline int __perf_event_disable(void *info)			{ return -1; }
 static inline void perf_event_task_tick(void)				{ }
 #endif
 
kernel/events/core.c +1 -1
index efef428..7fee567 100644
@@ -1253,7 +1253,7 @@ retry:
 /*
  * Cross CPU call to disable a performance event
  */
-static int __perf_event_disable(void *info)
+int __perf_event_disable(void *info)
 {
 	struct perf_event *event = info;
 	struct perf_event_context *ctx = event->ctx;
kernel/events/hw_breakpoint.c +10 -1
index bb38c4d..9a7b487 100644
@@ -453,7 +453,16 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
 	int old_type = bp->attr.bp_type;
 	int err = 0;
 
-	perf_event_disable(bp);
+	/*
+	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
+	 * will not be possible to raise IPIs that invoke __perf_event_disable.
+	 * So call the function directly after making sure we are targeting the
+	 * current task.
+	 */
+	if (irqs_disabled() && bp->ctx && bp->ctx->task == current)
+		__perf_event_disable(bp);
+	else
+		perf_event_disable(bp);
 
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;