diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2010-05-06 09:42:53 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-05-07 05:30:59 -0400 |
commit | a0507c84bf47dfd204299774f45fd16da33f0619 (patch) | |
tree | d40bf7628ebb9935fb1ef6727337dcd9e2c94fd5 /kernel/perf_event.c | |
parent | cce913178118b0b36742eb7544c2b38a0c957ee7 (diff) |
perf: Annotate perf_event_read_group() vs perf_event_release_kernel()
Stephane reported a lockdep warning while using PERF_FORMAT_GROUP.
The issue is that perf_event_read_group() takes faults while holding
the ctx->mutex, while perf_event_release_kernel() can be called from
munmap(). Which makes for an AB-BA deadlock.
Except we can never establish the deadlock because we'll only ever
call perf_event_release_kernel() after all file descriptors are dead
so there is no concurrency possible.
Reported-by: Stephane Eranian <eranian@google.com>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/perf_event.c')
-rw-r--r-- | kernel/perf_event.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index 49d8be5a45e3..34659d4085c7 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -1867,7 +1867,19 @@ int perf_event_release_kernel(struct perf_event *event) | |||
1867 | event->state = PERF_EVENT_STATE_FREE; | 1867 | event->state = PERF_EVENT_STATE_FREE; |
1868 | 1868 | ||
1869 | WARN_ON_ONCE(ctx->parent_ctx); | 1869 | WARN_ON_ONCE(ctx->parent_ctx); |
1870 | mutex_lock(&ctx->mutex); | 1870 | /* |
1871 | * There are two ways this annotation is useful: | ||
1872 | * | ||
1873 | * 1) there is a lock recursion from perf_event_exit_task | ||
1874 | * see the comment there. | ||
1875 | * | ||
1876 | * 2) there is a lock-inversion with mmap_sem through | ||
1877 | * perf_event_read_group(), which takes faults while | ||
1878 | * holding ctx->mutex, however this is called after | ||
1879 | * the last filedesc died, so there is no possibility | ||
1880 | * to trigger the AB-BA case. | ||
1881 | */ | ||
1882 | mutex_lock_nested(&ctx->mutex, SINGLE_DEPTH_NESTING); | ||
1871 | perf_event_remove_from_context(event); | 1883 | perf_event_remove_from_context(event); |
1872 | mutex_unlock(&ctx->mutex); | 1884 | mutex_unlock(&ctx->mutex); |
1873 | 1885 | ||
@@ -5305,7 +5317,7 @@ void perf_event_exit_task(struct task_struct *child) | |||
5305 | * | 5317 | * |
5306 | * But since its the parent context it won't be the same instance. | 5318 | * But since its the parent context it won't be the same instance. |
5307 | */ | 5319 | */ |
5308 | mutex_lock_nested(&child_ctx->mutex, SINGLE_DEPTH_NESTING); | 5320 | mutex_lock(&child_ctx->mutex); |
5309 | 5321 | ||
5310 | again: | 5322 | again: |
5311 | list_for_each_entry_safe(child_event, tmp, &child_ctx->pinned_groups, | 5323 | list_for_each_entry_safe(child_event, tmp, &child_ctx->pinned_groups, |