From: Peter Zijlstra <peterz@infradead.org>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, vince@deater.net,
eranian@google.com, Arnaldo Carvalho de Melo <acme@infradead.org>,
Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH] perf: Synchronously cleanup child events
Date: Fri, 15 Jan 2016 18:57:59 +0100 [thread overview]
Message-ID: <20160115175759.GL3421@worktop> (raw)
In-Reply-To: <1452866861-17680-1-git-send-email-alexander.shishkin@linux.intel.com>
On Fri, Jan 15, 2016 at 04:07:41PM +0200, Alexander Shishkin wrote:
> int perf_event_release_kernel(struct perf_event *event)
> {
> + struct perf_event *child, *tmp;
> + LIST_HEAD(child_list);
>
> + if (!is_kernel_event(event))
> + perf_remove_from_owner(event);
>
> + event->owner = NULL;
>
> + /*
> + * event::child_mutex nests inside ctx::lock, so move children
> + * to a safe place first and avoid inversion
> + */
> + mutex_lock(&event->child_mutex);
> + list_splice_init(&event->child_list, &child_list);
> + mutex_unlock(&event->child_mutex);
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);
Something like this would fix that I think, not sure its the best way
though...
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -979,8 +979,8 @@ static void put_ctx(struct perf_event_co
* Lock order:
* task_struct::perf_event_mutex
* perf_event_context::mutex
- * perf_event_context::lock
* perf_event::child_mutex;
+ * perf_event_context::lock
* perf_event::mmap_mutex
* mmap_sem
*/
@@ -8956,6 +8958,16 @@ inherit_event(struct perf_event *parent_
if (parent_event->parent)
parent_event = parent_event->parent;
+ WARN_ON_ONCE(parent_event->ctx->parent_ctx);
+ /*
+ * Serialize against perf_event_kernel_release()'s orphanage..
+ */
+ mutex_lock(&parent_event->child_mutex);
+ if (is_orphaned_event(parent_event)) {
+ mutex_unlock(&parent_event->child_mutex);
+ return NULL;
+ }
+
child_event = perf_event_alloc(&parent_event->attr,
parent_event->cpu,
child,
@@ -8964,8 +8976,8 @@ inherit_event(struct perf_event *parent_
if (IS_ERR(child_event))
return child_event;
- if (is_orphaned_event(parent_event) ||
- !atomic_long_inc_not_zero(&parent_event->refcount)) {
+ if (!atomic_long_inc_not_zero(&parent_event->refcount)) {
+ mutex_unlock(&parent_event->child_mutex);
free_event(child_event);
return NULL;
}
@@ -9013,8 +9025,6 @@ inherit_event(struct perf_event *parent_
/*
* Link this into the parent event's child list
*/
- WARN_ON_ONCE(parent_event->ctx->parent_ctx);
- mutex_lock(&parent_event->child_mutex);
list_add_tail(&child_event->child_list, &parent_event->child_list);
mutex_unlock(&parent_event->child_mutex);
next prev parent reply other threads:[~2016-01-15 17:58 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-15 11:22 [PATCH] perf: Cleanup user's child events Alexander Shishkin
2016-01-15 12:54 ` Peter Zijlstra
2016-01-15 13:05 ` Alexander Shishkin
2016-01-15 13:09 ` Peter Zijlstra
2016-01-15 14:07 ` [PATCH] perf: Synchronously cleanup " Alexander Shishkin
2016-01-15 17:57 ` Peter Zijlstra [this message]
2016-01-18 12:07 ` Alexander Shishkin
2016-01-18 12:37 ` Alexander Shishkin
2016-01-18 14:44 ` Peter Zijlstra
2016-01-19 15:12 ` [PATCH v2] " Alexander Shishkin
2016-01-19 20:05 ` Peter Zijlstra
2016-01-19 21:58 ` Alexei Starovoitov
2016-01-20 8:32 ` Peter Zijlstra
2016-01-21 4:55 ` Alexei Starovoitov
2016-01-20 7:04 ` Alexander Shishkin
2016-01-20 8:03 ` Peter Zijlstra
2016-01-22 11:35 ` Alexander Shishkin
2016-01-22 12:12 ` Peter Zijlstra
2016-01-22 12:38 ` Peter Zijlstra
2016-01-22 19:44 ` Alexei Starovoitov
2016-01-25 11:48 ` Peter Zijlstra
2016-01-25 14:54 ` Peter Zijlstra
2016-01-25 21:04 ` Peter Zijlstra
2016-01-26 4:59 ` Alexei Starovoitov
2016-01-26 16:16 ` Peter Zijlstra
2016-01-26 17:24 ` Peter Zijlstra
2016-01-26 23:31 ` Alexei Starovoitov
2016-01-27 9:58 ` Peter Zijlstra
2016-01-27 17:52 ` Alexei Starovoitov
2016-01-29 11:28 ` [tip:perf/urgent] perf/bpf: Convert perf_event_array to use struct file tip-bot for Alexei Starovoitov
2016-01-29 20:01 ` Alexei Starovoitov
2016-01-19 20:07 ` [PATCH v2] perf: Synchronously cleanup child events Peter Zijlstra
2016-01-19 7:45 ` [PATCH] " Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160115175759.GL3421@worktop \
--to=peterz@infradead.org \
--cc=acme@infradead.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=vince@deater.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.