diff options
author | Yan, Zheng <zheng.z.yan@intel.com> | 2012-06-15 02:31:31 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-06-18 06:13:20 -0400 |
commit | fbfc623f8231c8d8c78aab5841e9c6e5811ab638 (patch) | |
tree | 54883756f1b404f2232d4d5077219ea98c1fdbfd /kernel/events/core.c | |
parent | 4b4969b14490a4f65b572b8f180164181104b5e1 (diff) |
perf: Avoid race between cpu hotplug and installing event
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>
Diffstat (limited to 'kernel/events/core.c')
-rw-r--r-- | kernel/events/core.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c index d7d71d6ec972..31d182e01549 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -6252,6 +6252,8 @@ SYSCALL_DEFINE5(perf_event_open, | |||
6252 | } | 6252 | } |
6253 | } | 6253 | } |
6254 | 6254 | ||
6255 | get_online_cpus(); | ||
6256 | |||
6255 | event = perf_event_alloc(&attr, cpu, task, group_leader, NULL, | 6257 | event = perf_event_alloc(&attr, cpu, task, group_leader, NULL, |
6256 | NULL, NULL); | 6258 | NULL, NULL); |
6257 | if (IS_ERR(event)) { | 6259 | if (IS_ERR(event)) { |
@@ -6391,6 +6393,8 @@ SYSCALL_DEFINE5(perf_event_open, | |||
6391 | perf_unpin_context(ctx); | 6393 | perf_unpin_context(ctx); |
6392 | mutex_unlock(&ctx->mutex); | 6394 | mutex_unlock(&ctx->mutex); |
6393 | 6395 | ||
6396 | put_online_cpus(); | ||
6397 | |||
6394 | event->owner = current; | 6398 | event->owner = current; |
6395 | 6399 | ||
6396 | mutex_lock(¤t->perf_event_mutex); | 6400 | mutex_lock(¤t->perf_event_mutex); |
@@ -6419,6 +6423,7 @@ err_context: | |||
6419 | err_alloc: | 6423 | err_alloc: |
6420 | free_event(event); | 6424 | free_event(event); |
6421 | err_task: | 6425 | err_task: |
6426 | put_online_cpus(); | ||
6422 | if (task) | 6427 | if (task) |
6423 | put_task_struct(task); | 6428 | put_task_struct(task); |
6424 | err_group_fd: | 6429 | err_group_fd: |