[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8760yr83nx.fsf@ashishki-desk.ger.corp.intel.com>
Date: Mon, 18 Jan 2016 14:37:06 +0200
From: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Ingo Molnar <mingo@...hat.com>, linux-kernel@...r.kernel.org,
vince@...ter.net, eranian@...gle.com,
Arnaldo Carvalho de Melo <acme@...radead.org>,
Jiri Olsa <jolsa@...nel.org>
Subject: Re: [PATCH] perf: Synchronously cleanup child events
Peter Zijlstra <peterz@...radead.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);
Powered by blists - more mailing lists