public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] perf_event: fix race in perf_swevent_get_recursion_context()
@ 2010-01-18 13:42 Xiao Guangrong
  2010-01-18 13:44 ` [PATCH 2/3] perf_event: cleanup for event profile buffer operation Xiao Guangrong
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Xiao Guangrong @ 2010-01-18 13:42 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Peter Zijlstra, Frederic Weisbecker, Paul Mackerras, LKML

It only disable preemption in perf_swevent_get_recursion_context()
it can't avoid race of hard-irq and NMI

In this patch, we use atomic operation to avoid it and reduce
cpu_ctx->recursion size, it also make this patch no need diable
preemption

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 include/linux/perf_event.h |    2 +-
 kernel/perf_event.c        |   14 ++++----------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index c6f812e..8474ab0 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -730,7 +730,7 @@ struct perf_cpu_context {
 	 *
 	 * task, softirq, irq, nmi context
 	 */
-	int				recursion[4];
+	unsigned long			recursion;
 };
 
 struct perf_output_handle {
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index eae6ff6..77ef16e 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -3921,7 +3921,7 @@ static void perf_swevent_ctx_event(struct perf_event_context *ctx,
 
 int perf_swevent_get_recursion_context(void)
 {
-	struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context);
+	struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context);
 	int rctx;
 
 	if (in_nmi())
@@ -3933,13 +3933,8 @@ int perf_swevent_get_recursion_context(void)
 	else
 		rctx = 0;
 
-	if (cpuctx->recursion[rctx]) {
-		put_cpu_var(perf_cpu_context);
+	if (test_and_set_bit(rctx, &cpuctx->recursion))
 		return -1;
-	}
-
-	cpuctx->recursion[rctx]++;
-	barrier();
 
 	return rctx;
 }
@@ -3948,9 +3943,8 @@ EXPORT_SYMBOL_GPL(perf_swevent_get_recursion_context);
 void perf_swevent_put_recursion_context(int rctx)
 {
 	struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context);
-	barrier();
-	cpuctx->recursion[rctx]--;
-	put_cpu_var(perf_cpu_context);
+
+	clear_bit(rctx, &cpuctx->recursion);
 }
 EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context);
 
-- 
1.6.1.2


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

end of thread, other threads:[~2010-01-19 14:24 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-18 13:42 [PATCH 1/3] perf_event: fix race in perf_swevent_get_recursion_context() Xiao Guangrong
2010-01-18 13:44 ` [PATCH 2/3] perf_event: cleanup for event profile buffer operation Xiao Guangrong
2010-01-18 13:46   ` [PATCH 3/3] tracing/kprobe: cleanup unused return value of function Xiao Guangrong
2010-01-18 16:16     ` Masami Hiramatsu
2010-01-19  8:37     ` [PATCH 1/3 v2] perf_event: fix race in perf_swevent_get_recursion_context() Xiao Guangrong
2010-01-19  8:46       ` Peter Zijlstra
2010-01-19  9:06         ` Xiao Guangrong
2010-01-19  8:39     ` [PATCH 2/3 v2] perf_event: cleanup for event profile buffer operation Xiao Guangrong
2010-01-19  8:41     ` [PATCH 3/3 v2] tracing/kprobe: cleanup unused return value of function Xiao Guangrong
2010-01-18 16:21   ` [PATCH 2/3] perf_event: cleanup for event profile buffer operation Masami Hiramatsu
2010-01-18 17:20     ` Frederic Weisbecker
2010-01-18 17:48       ` Masami Hiramatsu
2010-01-18 18:02         ` Frederic Weisbecker
2010-01-19  1:26         ` Xiao Guangrong
2010-01-19  9:00           ` Frederic Weisbecker
2010-01-19 14:26             ` Masami Hiramatsu
2010-01-18 17:11   ` Frederic Weisbecker
2010-01-18 13:55 ` [PATCH 1/3] perf_event: fix race in perf_swevent_get_recursion_context() Peter Zijlstra
2010-01-19  7:36   ` Xiao Guangrong
2010-01-19  8:41     ` Peter Zijlstra
2010-01-18 16:41 ` Frederic Weisbecker
2010-01-19  1:19   ` Xiao Guangrong
2010-01-19  8:46     ` Peter Zijlstra
2010-01-19  8:58     ` Frederic Weisbecker
2010-01-19  9:09       ` Xiao Guangrong

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