Skip to content

Commit

Permalink
perf: Fix perf_event_init_task()/perf_event_free_task() interaction
Browse files Browse the repository at this point in the history
perf_event_init_task() should clear child->perf_event_ctxp[]
before anything else. Otherwise, if
perf_event_init_context(perf_hw_context) fails,
perf_event_free_task() can free perf_event_ctxp[perf_sw_context]
copied from parent->perf_event_ctxp[] by dup_task_struct().

Also move the initialization of perf_event_mutex and
perf_event_list from perf_event_init_context() to
perf_event_init_context().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: Roland McGrath <roland@redhat.com>
LKML-Reference: <20110119182228.GC12183@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Oleg Nesterov authored and Ingo Molnar committed Jan 19, 2011
1 parent dbe08d8 commit 8550d7c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kernel/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -6446,11 +6446,6 @@ int perf_event_init_context(struct task_struct *child, int ctxn)
unsigned long flags;
int ret = 0;

child->perf_event_ctxp[ctxn] = NULL;

mutex_init(&child->perf_event_mutex);
INIT_LIST_HEAD(&child->perf_event_list);

if (likely(!parent->perf_event_ctxp[ctxn]))
return 0;

Expand Down Expand Up @@ -6539,6 +6534,10 @@ int perf_event_init_task(struct task_struct *child)
{
int ctxn, ret;

memset(child->perf_event_ctxp, 0, sizeof(child->perf_event_ctxp));
mutex_init(&child->perf_event_mutex);
INIT_LIST_HEAD(&child->perf_event_list);

for_each_task_context_nr(ctxn) {
ret = perf_event_init_context(child, ctxn);
if (ret)
Expand Down

0 comments on commit 8550d7c

Please sign in to comment.