From: Namhyung Kim <namhyung@gmail.com>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH] perf top: Fix a race in callchain handling
Date: Sun, 6 May 2012 00:23:08 +0900 [thread overview]
Message-ID: <1336231388-12347-1-git-send-email-namhyung@gmail.com> (raw)
When perf top collects callchain info, main thread and display
thread share the callchain cursor so that bugs can happen. For
example, if two threads race on callchain_cursor_advance() for
the last cursor node, one of them can dereference a NULL pointer.
Because the display thread only uses the cursor when collapsing
a hist entry, use its own cursor for that.
Reported-by: Sunjin Yang <fan4326@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
tools/perf/util/hist.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 9f6d630d5316..795b49a803f9 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -378,7 +378,7 @@ void hist_entry__free(struct hist_entry *he)
* collapse the histogram
*/
-static bool hists__collapse_insert_entry(struct hists *hists,
+static bool hists__collapse_insert_entry(struct hists *hists __used,
struct rb_root *root,
struct hist_entry *he)
{
@@ -386,6 +386,7 @@ static bool hists__collapse_insert_entry(struct hists *hists,
struct rb_node *parent = NULL;
struct hist_entry *iter;
int64_t cmp;
+ static struct callchain_cursor cursor;
while (*p != NULL) {
parent = *p;
@@ -397,8 +398,8 @@ static bool hists__collapse_insert_entry(struct hists *hists,
iter->period += he->period;
iter->nr_events += he->nr_events;
if (symbol_conf.use_callchain) {
- callchain_cursor_reset(&hists->callchain_cursor);
- callchain_merge(&hists->callchain_cursor, iter->callchain,
+ callchain_cursor_reset(&cursor);
+ callchain_merge(&cursor, iter->callchain,
he->callchain);
}
hist_entry__free(he);
--
1.7.9.2
next reply other threads:[~2012-05-05 15:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 15:23 Namhyung Kim [this message]
2012-05-05 18:22 ` Peter Zijlstra
2012-05-05 23:53 ` Arnaldo Carvalho de Melo
2012-05-06 2:25 ` Namhyung Kim
2012-05-06 18:07 ` Arnaldo Carvalho de Melo
2012-05-07 1:22 ` Namhyung Kim
2012-05-06 18:32 ` Arnaldo Carvalho de Melo
2012-05-07 1:32 ` Namhyung Kim
2012-05-11 2:10 ` Namhyung Kim
2012-05-11 15:01 ` Arnaldo Carvalho de Melo
2012-05-11 16:25 ` Namhyung Kim
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=1336231388-12347-1-git-send-email-namhyung@gmail.com \
--to=namhyung@gmail.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®