lkml.org 
[lkml]   [2016]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH] perf: Synchronously cleanup child events
Date
Peter Zijlstra <peterz@infradead.org> writes:

> I suspect this races against inherit_event(), like:
>
> inherit_event() perf_event_release_kernel()
>
> if (is_orphaned_event(parent_event) /* false */
>
> event->owner = NULL
>
> mutex_lock(child_mutex);
> list_splice
> mutex_unlock(child_mutex);
>
> mutex_lock(child_mutex);
> list_add_tail
> mutex_unlock(child_mutex);

Or how about this instead:

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8eb3fee429..cd9f1ac537 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3786,8 +3786,9 @@ int perf_event_release_kernel(struct perf_event *event)

event->owner = NULL;

+retry:
/*
- * event::child_mutex nests inside ctx::lock, so move children
+ * event::child_mutex nests inside ctx::mutex, so move children
* to a safe place first and avoid inversion
*/
mutex_lock(&event->child_mutex);
@@ -3818,8 +3819,13 @@ int perf_event_release_kernel(struct perf_event *event)
put_event(event);
}

- /* Must be the last reference */
+ /* Must be the last reference, .. */
put_event(event);
+
+ /* .. unless we raced with inherit_event(), in which case, repeat */
+ if (atomic_long_inc_not_zero(&event->refcount))
+ goto retry;
+
return 0;
}
EXPORT_SYMBOL_GPL(perf_event_release_kernel);
\
 
 \ /
  Last update: 2016-01-18 14:01    [W:0.064 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site