Skip to content

Commit

Permalink
perf: Avoid race between cpu hotplug and installing event
Browse files Browse the repository at this point in the history
perf_event_open() requires the cpu on which to install event is online,
but the cpu can go offline after perf_event_open checks that. Add a
get_online_cpus()/put_online_cpus() pair to avoid the race.

Signed-off-by: Zheng Yan <zheng.z.yan@intel.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1339741902-8449-3-git-send-email-zheng.z.yan@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Yan, Zheng authored and Ingo Molnar committed Jun 18, 2012
1 parent 4b4969b commit fbfc623
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
@@ -6252,6 +6252,8 @@ SYSCALL_DEFINE5(perf_event_open,
}
}

get_online_cpus();

event = perf_event_alloc(&attr, cpu, task, group_leader, NULL,
NULL, NULL);
if (IS_ERR(event)) {
@@ -6391,6 +6393,8 @@ SYSCALL_DEFINE5(perf_event_open,
perf_unpin_context(ctx);
mutex_unlock(&ctx->mutex);

put_online_cpus();

event->owner = current;

mutex_lock(&current->perf_event_mutex);
@@ -6419,6 +6423,7 @@ SYSCALL_DEFINE5(perf_event_open,
err_alloc:
free_event(event);
err_task:
put_online_cpus();
if (task)
put_task_struct(task);
err_group_fd:

0 comments on commit fbfc623

Please sign in to comment.