linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: Re: [PATCH 3/4] perf map: Set kmap->kmaps backpointer for main kernel map chunks
Date: Mon, 10 Feb 2020 01:37:57 +0100	[thread overview]
Message-ID: <20200210003757.GB1907700@krava> (raw)
In-Reply-To: <20200209193238.GA1907700@krava>

On Sun, Feb 09, 2020 at 08:32:38PM +0100, Jiri Olsa wrote:

SNIP

> > > 
> > > perf top from perf/core has started crashing at __map__is_kernel():
> > > 
> > >   (gdb) bt
> > >   #0  __map__is_kernel (map=<optimized out>) at util/map.c:935
> > >   #1  0x000000000045551d in perf_event__process_sample (machine=0xbab8f8,
> > >       sample=0x7fffe5ffa6d0, evsel=0xba7570, event=0xbcac50, tool=0x7fffffff84e0)
> > >       at builtin-top.c:833
> > >   #2  deliver_event (qe=<optimized out>, qevent=<optimized out>) at builtin-top.c:1192
> > >   #3  0x000000000050b9fb in do_flush (show_progress=false, oe=0x7fffffff87e0)
> > >       at util/ordered-events.c:244
> > >   #4  __ordered_events__flush (oe=oe@entry=0x7fffffff87e0, how=how@entry=OE_FLUSH__TOP,
> > >       timestamp=timestamp@entry=0) at util/ordered-events.c:323
> > >   #5  0x000000000050c1b5 in __ordered_events__flush (timestamp=<optimized out>,
> > >       how=<optimized out>, oe=<optimized out>) at util/ordered-events.c:339
> > >   #6  ordered_events__flush (how=OE_FLUSH__TOP, oe=0x7fffffff87e0) at util/ordered-events.c:341
> > >   #7  ordered_events__flush (oe=oe@entry=0x7fffffff87e0, how=how@entry=OE_FLUSH__TOP)
> > >       at util/ordered-events.c:339
> > >   #8  0x0000000000454e21 in process_thread (arg=0x7fffffff84e0) at builtin-top.c:1104
> > >   #9  0x00007ffff7f2c4e2 in start_thread () from /lib64/libpthread.so.0
> > >   #10 0x00007ffff76086d3 in clone () from /lib64/libc.so.6
> > > 
> > > I haven't debugged it much but seems like the actual patch that's causing the
> > > crash is de90d513b246 ("perf map: Use map->dso->kernel + map__kmaps() in
> > > map__kmaps()").
> > > 
> > > Did you face this / aware of it?
> > 
> > hum, looks like there are few more places where we don't set
> > kmaps pointer, patch below fixes that for me
> > 
> > I'll still need to do more checking and I'll send a fix
> > 
> > jirka
> > 
> > 
> > ---
> 
> I found one more place.. please check the attached patch

and third time's the charm.. hopefully ;-)

I made the fix more central.. it still needs to be split
into several small fixes, but I'm running perf top for
few hours now without the crash

jirka


---
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index c8c5410315e8..460315476314 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -686,6 +686,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine,
 
 		dso__set_module_info(dso, m, machine);
 		dso__set_long_name(dso, strdup(filename), true);
+		dso->kernel = DSO_TYPE_KERNEL;
 	}
 
 	dso__get(dso);
@@ -726,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
 	if (!map) {
-		map = dso__new_map(event->ksymbol.name);
-		if (!map)
+		struct dso *dso = dso__new(event->ksymbol.name);
+
+		if (dso) {
+			dso->kernel = DSO_TYPE_KERNEL;
+			map = map__new2(0, dso);
+		}
+
+		if (!dso || !map)
 			return -ENOMEM;
 
 		map->start = event->ksymbol.addr;
@@ -972,7 +979,6 @@ int machine__create_extra_kernel_map(struct machine *machine,
 
 	kmap = map__kmap(map);
 
-	kmap->kmaps = &machine->kmaps;
 	strlcpy(kmap->name, xm->name, KMAP_NAME_LEN);
 
 	maps__insert(&machine->kmaps, map);
@@ -1082,9 +1088,6 @@ int __weak machine__create_extra_kernel_maps(struct machine *machine __maybe_unu
 static int
 __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
 {
-	struct kmap *kmap;
-	struct map *map;
-
 	/* In case of renewal the kernel map, destroy previous one */
 	machine__destroy_kernel_maps(machine);
 
@@ -1093,14 +1096,7 @@ __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
 		return -1;
 
 	machine->vmlinux_map->map_ip = machine->vmlinux_map->unmap_ip = identity__map_ip;
-	map = machine__kernel_map(machine);
-	kmap = map__kmap(map);
-	if (!kmap)
-		return -1;
-
-	kmap->kmaps = &machine->kmaps;
-	maps__insert(&machine->kmaps, map);
-
+	maps__insert(&machine->kmaps, machine->vmlinux_map);
 	return 0;
 }
 
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index f67960bedebb..a08ca276098e 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -375,8 +375,13 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
 
 struct map *map__clone(struct map *from)
 {
-	struct map *map = memdup(from, sizeof(*map));
+	size_t size = sizeof(struct map);
+	struct map *map;
+
+	if (from->dso && from->dso->kernel)
+		size += sizeof(struct kmap);
 
+	map = memdup(from, size);
 	if (map != NULL) {
 		refcount_set(&map->refcnt, 1);
 		RB_CLEAR_NODE(&map->rb_node);
@@ -538,6 +543,16 @@ void maps__insert(struct maps *maps, struct map *map)
 	__maps__insert(maps, map);
 	++maps->nr_maps;
 
+	if (map->dso && map->dso->kernel) {
+		struct kmap *kmap = map__kmap(map);
+
+		if (kmap)
+			kmap->kmaps = maps;
+		else
+			pr_err("Internal error: kernel dso with non kernel map\n");
+	}
+
+
 	/*
 	 * If we already performed some search by name, then we need to add the just
 	 * inserted map and resort.

  reply	other threads:[~2020-02-10  0:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-23 13:32 [GIT PULL] perf/urgent improvements and fixes Arnaldo Carvalho de Melo
2019-12-23 13:32 ` [PATCH 1/4] tools lib traceevent: Fix memory leakage in filter_event Arnaldo Carvalho de Melo
2019-12-23 13:32 ` [PATCH 2/4] perf report: Fix incorrectly added dimensions as switch perf data file Arnaldo Carvalho de Melo
2019-12-23 13:32 ` [PATCH 3/4] perf map: Set kmap->kmaps backpointer for main kernel map chunks Arnaldo Carvalho de Melo
2020-02-06  9:40   ` Ravi Bangoria
2020-02-09 15:01     ` Jiri Olsa
2020-02-09 19:32       ` Jiri Olsa
2020-02-10  0:37         ` Jiri Olsa [this message]
2020-02-10 11:16           ` Ravi Bangoria
2020-02-10 13:13     ` Arnaldo Carvalho de Melo
2019-12-23 13:32 ` [PATCH 4/4] perf hists: Fix variable name's inconsistency in hists__for_each() macro Arnaldo Carvalho de Melo
2019-12-23 21:28 ` [GIT PULL] perf/urgent improvements and fixes 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=20200210003757.GB1907700@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=ravi.bangoria@linux.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).