Skip to contentSkip to conversation

perf tools: Fix kmap handling

PATCH Applied Jiri Olsa 5 participants 17 messages Feb 10, 2020 – Feb 15, 2020 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

cover perf tools: Fix kmap handling

hi,
Ravi Bangoria reported crash in perf top due to wrong kmap objects management, this patchset should fix that.

thanks,
jirka

---
Jiri Olsa (4):
perf tools: Mark modules dsos with kernel type perf tools: Mark ksymbol dsos with kernel type perf tools: Fix map__clone for struct kmap perf tools: Move kmap::kmaps setup to maps__insert

 tools/perf/util/machine.c | 24 ++++++++++--------------
 tools/perf/util/map.c     | 17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 15 deletions(-)
author reviewer
#1 lore raw

PATCH 1/4 perf tools: Mark modules dsos with kernel type

We add kernel module map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/machine.c +1 -0
index c8c5410315e8..e3e5490f6de5 100644
@@ -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);
Signature · 1 line
2.24.1
merge bot Applied
#2 lore raw

[tip: perf/urgent] perf maps: Mark module DSOs with kernel type

The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     02213cec64bbef66d7ad9ddc3b7c47236da64343
Gitweb:        https://git.kernel.org/tip/02213cec64bbef66d7ad9ddc3b7c47236da64343
Author:        Jiri Olsa <[email protected]>
AuthorDate:    Mon, 10 Feb 2020 15:32:15 +01:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 11 Feb 2020 16:41:49 -03:00

perf maps: Mark module DSOs with kernel type

We add kernel module map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/machine.c +1 -0
index c8c5410..e3e5490 100644
@@ -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);
author reviewer
#3 lore raw

PATCH 2/4 perf tools: Mark ksymbol dsos with kernel type

In reply to Jiri Olsa

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +8 -2
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,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;
Signature · 1 line
2.24.1
#4 lore raw

Re: [PATCH 2/4] perf tools: Mark ksymbol dsos with kernel type

Em Mon, Feb 10, 2020 at 03:32:16PM +0100, Jiri Olsa escreveu:

Quoted 19 lines

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +0 -0
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
 	if (!map) {

tools/perf/util/machine.c static int machine__process_ksymbol_register(struct machine *machine, · line 737

Quoted 10 lines
tools/perf/util/machine.c +8 -2
-		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)

We leak dso if map creation fails?

- Arnaldo

Quoted 6 lines
tools/perf/util/machine.c +0 -0
 			return -ENOMEM;
 
 		map->start = event->ksymbol.addr;
Signature · 1 line
2.24.1
Signature · 1 line
- Arnaldo
#5 lore raw

Re: [PATCH 2/4] perf tools: Mark ksymbol dsos with kernel type

Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 10, 2020 at 03:32:16PM +0100, Jiri Olsa escreveu:

Quoted 18 lines

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +0 -0
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
Quoted 13 lines

tools/perf/util/machine.c static int machine__process_ksymbol_register(struct machine *machine, · line 737

Quoted 11 lines
tools/perf/util/machine.c +8 -2
 	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)

We leak dso if map creation fails?

yep :-\ will post v2

thanks,
jirka

Quoted 15 lines

- Arnaldo

Quoted 6 lines
tools/perf/util/machine.c +0 -0
 			return -ENOMEM;
 
 		map->start = event->ksymbol.addr;
Signature · 1 line
2.24.1
Signature · 1 line
- Arnaldo
#6 lore raw

Re: [PATCH 2/4] perf tools: Mark ksymbol dsos with kernel type

Em Mon, Feb 10, 2020 at 04:25:37PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 19 lines

Em Mon, Feb 10, 2020 at 03:32:16PM +0100, Jiri Olsa escreveu:

Quoted 18 lines

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +0 -0
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
Quoted 13 lines

tools/perf/util/machine.c static int machine__process_ksymbol_register(struct machine *machine, · line 737

Quoted 11 lines
tools/perf/util/machine.c +8 -2
 	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)

We leak dso if map creation fails?

Quoted 1 line

yep :-\ will post v2

Please collect Kim's Tested-by then,

- Arnaldo

Quoted 19 lines

thanks,
jirka

Quoted 15 lines

- Arnaldo

Quoted 6 lines
tools/perf/util/machine.c +0 -0
 			return -ENOMEM;
 
 		map->start = event->ksymbol.addr;
Signature · 1 line
2.24.1
Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
#7 lore raw

Re: [PATCH 2/4] perf tools: Mark ksymbol dsos with kernel type

Quoted 35 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 10, 2020 at 04:25:37PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 32 lines

Em Mon, Feb 10, 2020 at 03:32:16PM +0100, Jiri Olsa escreveu:

Quoted 19 lines

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +0 -0
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
 	if (!map) {

tools/perf/util/machine.c static int machine__process_ksymbol_register(struct machine *machine, · line 737

Quoted 10 lines
tools/perf/util/machine.c +8 -2
-		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)

We leak dso if map creation fails?

Quoted 3 lines
Quoted 1 line

yep :-\ will post v2

Please collect Kim's Tested-by then,

oops, did not notice, I updated commits with them in the perf/top branch

jirka

Quoted 27 lines

- Arnaldo

Quoted 19 lines

thanks,
jirka

Quoted 15 lines

- Arnaldo

Quoted 6 lines
tools/perf/util/machine.c +0 -0
 			return -ENOMEM;
 
 		map->start = event->ksymbol.addr;
Signature · 1 line
2.24.1
Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
#8 lore raw

PATCH v2 2/4 perf tools: Mark ksymbol dsos with kernel type

In reply to Jiri Olsa
Quoted 34 lines · Jiri Olsa
Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 10, 2020 at 03:32:16PM +0100, Jiri Olsa escreveu:

Quoted 18 lines

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +0 -0
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
Quoted 13 lines

tools/perf/util/machine.c static int machine__process_ksymbol_register(struct machine *machine, · line 737

Quoted 11 lines
tools/perf/util/machine.c +8 -2
 	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)

We leak dso if map creation fails?

Quoted 1 line

yep :-\ will post v2

v2 attached, it's also all in my perf/top branch

thanks,
jirka

---
We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +10 -2
index e3e5490f6de5..0ad026561c7f 100644
@@ -727,9 +727,17 @@ 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) {
+			dso__put(dso);
 			return -ENOMEM;
+		}
 
 		map->start = event->ksymbol.addr;
 		map->end = map->start + event->ksymbol.len;
Signature · 1 line
2.24.1
#9 lore raw

Re: [PATCHv2 2/4] perf tools: Mark ksymbol dsos with kernel type

Em Mon, Feb 10, 2020 at 09:08:47PM +0100, Jiri Olsa escreveu:

Quoted 35 lines · Jiri Olsa
Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 32 lines

Em Mon, Feb 10, 2020 at 03:32:16PM +0100, Jiri Olsa escreveu:

Quoted 19 lines

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +0 -0
index e3e5490f6de5..0a43dc83d7b2 100644
@@ -727,8 +727,14 @@ static int machine__process_ksymbol_register(struct machine *machine,
 	struct map *map = maps__find(&machine->kmaps, event->ksymbol.addr);
 
 	if (!map) {

tools/perf/util/machine.c static int machine__process_ksymbol_register(struct machine *machine, · line 737

Quoted 10 lines
tools/perf/util/machine.c +8 -2
-		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)

We leak dso if map creation fails?

Quoted 3 lines
Quoted 1 line

yep :-\ will post v2

v2 attached, it's also all in my perf/top branch

Thanks for fixing it, will process it into my perf/urgent branch.

- Arnaldo

Quoted 43 lines

thanks,
jirka

---
We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +10 -2
index e3e5490f6de5..0ad026561c7f 100644
@@ -727,9 +727,17 @@ 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) {
+			dso__put(dso);
 			return -ENOMEM;
+		}
 
 		map->start = event->ksymbol.addr;
 		map->end = map->start + event->ksymbol.len;
Signature · 1 line
2.24.1
Signature · 1 line
- Arnaldo
merge bot Applied
#10 lore raw

[tip: perf/urgent] perf maps: Mark ksymbol DSOs with kernel type

In reply to Jiri Olsa
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     4a4eb6154d67f7766cc7eb74e9f1db424073e832
Gitweb:        https://git.kernel.org/tip/4a4eb6154d67f7766cc7eb74e9f1db424073e832
Author:        Jiri Olsa <[email protected]>
AuthorDate:    Mon, 10 Feb 2020 21:08:47 +01:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 11 Feb 2020 16:41:49 -03:00

perf maps: Mark ksymbol DSOs with kernel type

We add ksymbol map into machine->kmaps, so it needs to be created as 'struct kmap', which is dependent on its dso having kernel type.

---
 tools/perf/util/machine.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +10 -2
index e3e5490..0ad0265 100644
@@ -727,9 +727,17 @@ 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) {
+			dso__put(dso);
 			return -ENOMEM;
+		}
 
 		map->start = event->ksymbol.addr;
 		map->end = map->start + event->ksymbol.len;
author reviewer
#11 lore raw

PATCH 3/4 perf tools: Fix map__clone for struct kmap

In reply to Jiri Olsa

The map__clone function can be called on kernel maps as well, so it needs to duplicate the whole kmap data.

---
 tools/perf/util/map.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/map.c +6 -1
index f67960bedebb..cea05fc9595c 100644
@@ -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);
Signature · 1 line
2.24.1
merge bot Applied
#12 lore raw

[tip: perf/urgent] perf maps: Fix map__clone() for struct kmap

The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     7ce66139a99ce57caaf47b64afed5cb6ed02c5ed
Gitweb:        https://git.kernel.org/tip/7ce66139a99ce57caaf47b64afed5cb6ed02c5ed
Author:        Jiri Olsa <[email protected]>
AuthorDate:    Mon, 10 Feb 2020 15:32:17 +01:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 11 Feb 2020 16:41:49 -03:00

perf maps: Fix map__clone() for struct kmap

The map__clone() function can be called on kernel maps as well, so it needs to duplicate the whole kmap data.

---
 tools/perf/util/map.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/map.c +6 -1
index f67960b..cea05fc 100644
@@ -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);
author reviewer
#13 lore raw

PATCH 4/4 perf tools: Move kmap::kmaps setup to maps__insert

In reply to Jiri Olsa

So the kmaps pointer setup is centralized and we do not need to update it in all those places (2 current places and few more missing) after calling maps__insert.

---
 tools/perf/util/machine.c | 13 +------------
 tools/perf/util/map.c     | 10 ++++++++++
 2 files changed, 11 insertions(+), 12 deletions(-)
tools/perf/util/machine.c +1 -12
index 0a43dc83d7b2..460315476314 100644
@@ -979,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);
@@ -1089,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);
 
@@ -1100,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;
 }
 
tools/perf/util/map.c +10 -0
index cea05fc9595c..a08ca276098e 100644
@@ -543,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.
Signature · 1 line
2.24.1
merge bot Applied
#14 lore raw

[tip: perf/urgent] perf maps: Move kmap::kmaps setup to maps__insert()

The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     484214f49bd0948d716832a94e4737ca4dd02c16
Gitweb:        https://git.kernel.org/tip/484214f49bd0948d716832a94e4737ca4dd02c16
Author:        Jiri Olsa <[email protected]>
AuthorDate:    Mon, 10 Feb 2020 15:32:18 +01:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 11 Feb 2020 16:41:49 -03:00

perf maps: Move kmap::kmaps setup to maps__insert()

So the kmaps pointer setup is centralized and we do not need to update it in all those places (2 current places and few more missing) after calling maps__insert().

---
 tools/perf/util/machine.c | 13 +------------
 tools/perf/util/map.c     | 10 ++++++++++
 2 files changed, 11 insertions(+), 12 deletions(-)
tools/perf/util/machine.c +1 -12
index 0ad0265..fb5c2cd 100644
@@ -981,7 +981,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);
@@ -1091,9 +1090,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);
 
@@ -1102,14 +1098,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;
 }
 
tools/perf/util/map.c +10 -0
index cea05fc..a08ca27 100644
@@ -543,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.
Tested-by on the v1 series
#15 lore raw
In reply to Jiri Olsa
Quoted 15 lines · Jiri Olsa

hi,
Ravi Bangoria reported crash in perf top due to wrong kmap objects management, this patchset should fix that.

thanks,
jirka

---
Jiri Olsa (4):
perf tools: Mark modules dsos with kernel type perf tools: Mark ksymbol dsos with kernel type perf tools: Fix map__clone for struct kmap perf tools: Move kmap::kmaps setup to maps__insert

Quoted 4 lines
 tools/perf/util/machine.c | 24 ++++++++++--------------
 tools/perf/util/map.c     | 17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 15 deletions(-)

This series fixes a segmentation fault I was seeing on a couple of AMD systems, so:

Thanks,

Kim

Thread 259 "perf" received signal SIGSEGV, Segmentation fault.

                                                              [Switching to Thread 0x7fff3b7b6700 (LWP 13241)]

__map__is_kernel (map=0x7fffd80098d0) at util/map.c:244
244 return machine__kernel_map(map__kmaps((struct map *)map)->machine) == map;
(gdb) bt
#0 __map__is_kernel (map=0x7fffd80098d0) at util/map.c:244
#1 0x000055555575d756 in perf_event__process_sample (machine=<optimized out>, sample=0x7fff3b7b5710,

    evsel=0x555555ef9dd0, event=<optimized out>, tool=0x7fffffff8660) at builtin-top.c:799
#2  deliver_event (qe=<optimized out>, qevent=<optimized out>) at builtin-top.c:1192
#3  0x0000555555831f81 in do_flush (show_progress=false, oe=0x7fffffff8960) at util/ordered-events.c:244
#4  __ordered_events__flush (oe=oe@entry=0x7fffffff8960, how=how@entry=OE_FLUSH__TOP, timestamp=timestamp@entry=0)
    at util/ordered-events.c:323
#5  0x00005555558328df in __ordered_events__flush (timestamp=<optimized out>, how=<optimized out>, oe=<optimized out>)
    at util/ordered-events.c:342
#6  ordered_events__flush (oe=oe@entry=0x7fffffff8960, how=how@entry=OE_FLUSH__TOP) at util/ordered-events.c:341
#7  0x000055555575d0f1 in process_thread (arg=0x7fffffff8660) at builtin-top.c:1104
#8  0x00007ffff7bbd6db in start_thread (arg=0x7fff3b7b6700) at pthread_create.c:463
#9  0x00007ffff5d9788f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

(gdb) p map
$1 = (const struct map *) 0x7fffd80098d0

#16 lore raw
Quoted 21 lines · Kim Phillips
Quoted 15 lines · Jiri Olsa

hi,
Ravi Bangoria reported crash in perf top due to wrong kmap objects management, this patchset should fix that.

thanks,
jirka

---
Jiri Olsa (4):
perf tools: Mark modules dsos with kernel type perf tools: Mark ksymbol dsos with kernel type perf tools: Fix map__clone for struct kmap perf tools: Move kmap::kmaps setup to maps__insert

Quoted 4 lines
 tools/perf/util/machine.c | 24 ++++++++++--------------
 tools/perf/util/map.c     | 17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 15 deletions(-)
Quoted 4 lines

This series fixes a segmentation fault I was seeing on a couple of AMD systems, so:

great, thanks a lot for testing

jirka