Skip to contentSkip to conversation

perf inject: Call dso__put() even if dso->hit is set

PATCH Applied Namhyung Kim 3 participants 4 messages May 24, 2021 – May 26, 2021 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/2 perf inject: Call dso__put() even if dso->hit is set

Otherwise it'll leak the refcount for the DSO. As dso__put() can handle a NULL dso pointer, we can just call it unconditionally.

---
 tools/perf/builtin-inject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-inject.c +2 -2
index 102cafb0c0b3..8bbaa46eb7e6 100644
@@ -383,8 +383,8 @@ static int perf_event__repipe_buildid_mmap(struct perf_tool *tool,
 	if (dso && !dso->hit) {
 		dso->hit = 1;
 		dso__inject_build_id(dso, tool, machine, sample->cpumode, 0);
-		dso__put(dso);
 	}
+	dso__put(dso);
 
 	return perf_event__repipe(tool, event, sample, machine);
 }
@@ -447,8 +447,8 @@ static int perf_event__repipe_buildid_mmap2(struct perf_tool *tool,
 		dso->hit = 1;
 		dso__inject_build_id(dso, tool, machine, sample->cpumode,
 				     event->mmap2.flags);
-		dso__put(dso);
 	}
+	dso__put(dso);
 
 	perf_event__repipe(tool, event, sample, machine);
 
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
author maintainer
#1 lore raw

PATCH 2/2 perf inject: Do not inject BUILD_ID record if MMAP2 has it

When PERF_RECORD_MISC_MMAP_BUILD_ID is set, the event has a build-id of the DSO already so no need to add it again.

---
 tools/perf/builtin-inject.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
tools/perf/builtin-inject.c +24 -0
index 8bbaa46eb7e6..5d6f583e2cd3 100644
@@ -399,6 +399,18 @@ static int perf_event__repipe_mmap2(struct perf_tool *tool,
 	err = perf_event__process_mmap2(tool, event, sample, machine);
 	perf_event__repipe(tool, event, sample, machine);
 
+	if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
+		struct dso *dso;
+
+		dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
+				  event->mmap2.filename, NULL, machine);
+		if (dso) {
+			/* mark it not to inject build-id */
+			dso->hit = 1;
+		}
+		dso__put(dso);
+	}
+
 	return err;
 }
 
@@ -440,6 +452,18 @@ static int perf_event__repipe_buildid_mmap2(struct perf_tool *tool,
 	};
 	struct dso *dso;
 
+	if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
+		/* cannot use dso_id since it'd have invalid info */
+		dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
+				  event->mmap2.filename, NULL, machine);
+		if (dso) {
+			/* mark it not to inject build-id */
+			dso->hit = 1;
+		}
+		dso__put(dso);
+		return 0;
+	}
+
 	dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
 			  event->mmap2.filename, &dso_id, machine);
 
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
Acked-by on v1 1/2
#2 lore raw
In reply to Namhyung Kim
Quoted 4 lines · Namhyung Kim

Otherwise it'll leak the refcount for the DSO. As dso__put() can handle a NULL dso pointer, we can just call it unconditionally.

for the patchset

thanks,
jirka

Quoted 31 lines
---
 tools/perf/builtin-inject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-inject.c +2 -2
index 102cafb0c0b3..8bbaa46eb7e6 100644
@@ -383,8 +383,8 @@ static int perf_event__repipe_buildid_mmap(struct perf_tool *tool,
 	if (dso && !dso->hit) {
 		dso->hit = 1;
 		dso__inject_build_id(dso, tool, machine, sample->cpumode, 0);
-		dso__put(dso);
 	}
+	dso__put(dso);
 
 	return perf_event__repipe(tool, event, sample, machine);
 }
@@ -447,8 +447,8 @@ static int perf_event__repipe_buildid_mmap2(struct perf_tool *tool,
 		dso->hit = 1;
 		dso__inject_build_id(dso, tool, machine, sample->cpumode,
 				     event->mmap2.flags);
-		dso__put(dso);
 	}
+	dso__put(dso);
 
 	perf_event__repipe(tool, event, sample, machine);
 
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
maintainer Applied
#3 lore raw

Em Wed, May 26, 2021 at 02:13:43PM +0200, Jiri Olsa escreveu:

Quoted 9 lines · Namhyung Kim
Quoted 4 lines

Otherwise it'll leak the refcount for the DSO. As dso__put() can handle a NULL dso pointer, we can just call it unconditionally.

for the patchset

Thanks, applied.

- Arnaldo

Quoted 35 lines

thanks,
jirka

Quoted 31 lines
---
 tools/perf/builtin-inject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-inject.c +2 -2
index 102cafb0c0b3..8bbaa46eb7e6 100644
@@ -383,8 +383,8 @@ static int perf_event__repipe_buildid_mmap(struct perf_tool *tool,
 	if (dso && !dso->hit) {
 		dso->hit = 1;
 		dso__inject_build_id(dso, tool, machine, sample->cpumode, 0);
-		dso__put(dso);
 	}
+	dso__put(dso);
 
 	return perf_event__repipe(tool, event, sample, machine);
 }
@@ -447,8 +447,8 @@ static int perf_event__repipe_buildid_mmap2(struct perf_tool *tool,
 		dso->hit = 1;
 		dso__inject_build_id(dso, tool, machine, sample->cpumode,
 				     event->mmap2.flags);
-		dso__put(dso);
 	}
+	dso__put(dso);
 
 	perf_event__repipe(tool, event, sample, machine);
 
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
Signature · 1 line
- Arnaldo