Skip to contentSkip to conversation

perf: Ensure we call add_event_to_ctx() with the right locks held

tip:perf/core tip-bot for Peter Zijlstra 1 participant 1 message Sep 10, 2010

lore
Share & tools
lore
#0 lore raw
Commit-ID:  cee010ec5211b96f33c5c2208f5c14ebb04b634a
Gitweb:     http://git.kernel.org/tip/cee010ec5211b96f33c5c2208f5c14ebb04b634a
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Fri, 10 Sep 2010 12:51:54 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 10 Sep 2010 16:24:33 +0200

perf: Ensure we call add_event_to_ctx() with the right locks held

Even though we call it from the inherit path, where the child is not yet accessible, we need to hold ctx->lock, add_event_to_ctx() assumes IRQs are disabled.

LKML-Reference: <new-submission>

---
 kernel/perf_event.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
kernel/perf_event.c +3 -0
index eaf1c5d..f395fb4 100644
@@ -5913,6 +5913,7 @@ inherit_event(struct perf_event *parent_event,
 	      struct perf_event_context *child_ctx)
 {
 	struct perf_event *child_event;
+	unsigned long flags;
 
 	/*
 	 * Instead of creating recursive hierarchies of events,
@@ -5957,7 +5958,9 @@ inherit_event(struct perf_event *parent_event,
 	/*
 	 * Link it up in the child's context:
 	 */
+	raw_spin_lock_irqsave(&child_ctx->lock, flags);
 	add_event_to_ctx(child_event, child_ctx);
+	raw_spin_unlock_irqrestore(&child_ctx->lock, flags);
 
 	/*
 	 * Get a reference to the parent filp - we will fput it