Skip to contentSkip to conversation

perf tools: Fix maps__find_symbol_by_name()

PATCH In review Adrian Hunter 4 participants 5 messages Sep 7, 2018 – Sep 12, 2018 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

PATCH v2 1/1 perf tools: Fix maps__find_symbol_by_name()

Commit 1c5aae7710bb ("perf machine: Create maps for x86 PTI entry trampolines") revealed a problem with maps__find_symbol_by_name() that resulted in probes not being found e.g.

	$ sudo perf probe xsk_mmap
	xsk_mmap is out of .text, skip it.
	Probe point 'xsk_mmap' not found.
	   Error: Failed to add events.

maps__find_symbol_by_name() can optionally return the map of the found symbol. It can get the map wrong because, in fact, the symbol is found on the map's dso, not allowing for the possibility that the dso has more than one map. Fix by always checking the map contains the symbol.

---

Changes in V2:

Expanded commit message
Corrected email address

 tools/perf/util/map.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/perf/util/map.c +11 -0
index 3f07a587c8e6..354e54550d2b 100644
@@ -574,6 +574,13 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg,
 	return NULL;
 }
 
+static bool map__contains_symbol(struct map *map, struct symbol *sym)
+{
+	u64 ip = map->unmap_ip(map, sym->start);
+
+	return ip >= map->start && ip < map->end;
+}
+
 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 					 struct map **mapp)
 {
@@ -589,6 +596,10 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 
 		if (sym == NULL)
 			continue;
+		if (!map__contains_symbol(pos, sym)) {
+			sym = NULL;
+			continue;
+		}
 		if (mapp != NULL)
 			*mapp = pos;
 		goto out;
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Adrian Hunter

Commit 1c5aae7710bb ("perf machine: Create maps for x86 PTI entry trampolines") revealed a problem with maps__find_symbol_by_name() that resulted in probes not being found e.g.

	$ sudo perf probe xsk_mmap
	xsk_mmap is out of .text, skip it.
	Probe point 'xsk_mmap' not found.
	   Error: Failed to add events.
Quoted 7 lines

maps__find_symbol_by_name() can optionally return the map of the found symbol. It can get the map wrong because, in fact, the symbol is found on the map's dso, not allowing for the possibility that the dso has more than one map. Fix by always checking the map contains the symbol.

thanks,
jirka

#2 lore raw
In reply to Adrian Hunter

Em Fri, Sep 07, 2018 at 11:51:16AM +0300, Adrian Hunter escreveu:

Quoted 2 lines

Commit 1c5aae7710bb ("perf machine: Create maps for x86 PTI entry trampolines") revealed a problem with maps__find_symbol_by_name() that

Can we have this with a Fixes: 1c5aae7710bb?

So that that, combined with the CC: stable, tells which stable kernels should get that fix, I think there are scripts harvesting Fixes: tags to help stable maintainers :-)

- Arnaldo

Quoted 59 lines

resulted in probes not being found e.g.

	$ sudo perf probe xsk_mmap
	xsk_mmap is out of .text, skip it.
	Probe point 'xsk_mmap' not found.
	   Error: Failed to add events.

maps__find_symbol_by_name() can optionally return the map of the found symbol. It can get the map wrong because, in fact, the symbol is found on the map's dso, not allowing for the possibility that the dso has more than one map. Fix by always checking the map contains the symbol.

---

Changes in V2:

Expanded commit message
Corrected email address

 tools/perf/util/map.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/perf/util/map.c +11 -0
index 3f07a587c8e6..354e54550d2b 100644
@@ -574,6 +574,13 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg,
 	return NULL;
 }
 
+static bool map__contains_symbol(struct map *map, struct symbol *sym)
+{
+	u64 ip = map->unmap_ip(map, sym->start);
+
+	return ip >= map->start && ip < map->end;
+}
+
 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 					 struct map **mapp)
 {
@@ -589,6 +596,10 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 
 		if (sym == NULL)
 			continue;
+		if (!map__contains_symbol(pos, sym)) {
+			sym = NULL;
+			continue;
+		}
 		if (mapp != NULL)
 			*mapp = pos;
 		goto out;
Signature · 1 line
2.17.1
author reviewer
#3 lore raw
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Fri, Sep 07, 2018 at 11:51:16AM +0300, Adrian Hunter escreveu:

Quoted 2 lines

Commit 1c5aae7710bb ("perf machine: Create maps for x86 PTI entry trampolines") revealed a problem with maps__find_symbol_by_name() that

Can we have this with a Fixes: 1c5aae7710bb?

So that that, combined with the CC: stable, tells which stable kernels should get that fix, I think there are scripts harvesting Fixes: tags to help stable maintainers :-)

It seemed like potentially an existing issue so I did not want to limit how far back it got applied.

Quoted 63 lines

- Arnaldo

Quoted 59 lines

resulted in probes not being found e.g.

	$ sudo perf probe xsk_mmap
	xsk_mmap is out of .text, skip it.
	Probe point 'xsk_mmap' not found.
	   Error: Failed to add events.

maps__find_symbol_by_name() can optionally return the map of the found symbol. It can get the map wrong because, in fact, the symbol is found on the map's dso, not allowing for the possibility that the dso has more than one map. Fix by always checking the map contains the symbol.

---

Changes in V2:

Expanded commit message
Corrected email address

 tools/perf/util/map.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/perf/util/map.c +11 -0
index 3f07a587c8e6..354e54550d2b 100644
@@ -574,6 +574,13 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg,
 	return NULL;
 }
 
+static bool map__contains_symbol(struct map *map, struct symbol *sym)
+{
+	u64 ip = map->unmap_ip(map, sym->start);
+
+	return ip >= map->start && ip < map->end;
+}
+
 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 					 struct map **mapp)
 {
@@ -589,6 +596,10 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 
 		if (sym == NULL)
 			continue;
+		if (!map__contains_symbol(pos, sym)) {
+			sym = NULL;
+			continue;
+		}
 		if (mapp != NULL)
 			*mapp = pos;
 		goto out;
Signature · 1 line
2.17.1
#4 lore raw
In reply to Adrian Hunter
perf tools: Fix maps__find_symbol_by_name()
Commit-ID:  03db8b583d1c3c84963e08e2abf6c79081da5c31
Gitweb:     https://git.kernel.org/tip/03db8b583d1c3c84963e08e2abf6c79081da5c31
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 7 Sep 2018 11:51:16 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 11 Sep 2018 14:12:51 -0300

perf tools: Fix maps__find_symbol_by_name()

Commit 1c5aae7710bb ("perf machine: Create maps for x86 PTI entry trampolines") revealed a problem with maps__find_symbol_by_name() that resulted in probes not being found e.g.

	$ sudo perf probe xsk_mmap
	xsk_mmap is out of .text, skip it.
	Probe point 'xsk_mmap' not found.
	   Error: Failed to add events.

maps__find_symbol_by_name() can optionally return the map of the found symbol. It can get the map wrong because, in fact, the symbol is found on the map's dso, not allowing for the possibility that the dso has more than one map. Fix by always checking the map contains the symbol.

---
 tools/perf/util/map.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/perf/util/map.c +11 -0
index 36d0763311ef..6a6929f208b4 100644
@@ -576,6 +576,13 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg,
 	return NULL;
 }
 
+static bool map__contains_symbol(struct map *map, struct symbol *sym)
+{
+	u64 ip = map->unmap_ip(map, sym->start);
+
+	return ip >= map->start && ip < map->end;
+}
+
 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 					 struct map **mapp)
 {
@@ -591,6 +598,10 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
 
 		if (sym == NULL)
 			continue;
+		if (!map__contains_symbol(pos, sym)) {
+			sym = NULL;
+			continue;
+		}
 		if (mapp != NULL)
 			*mapp = pos;
 		goto out;