Skip to contentSkip to conversation

perf inject jit: Ignore memfd and anonymous mmap events if jitdump present

PATCH In review Brian Robbins 3 participants 3 messages Aug 5, 2022 – Aug 10, 2022 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf inject jit: Ignore memfd and anonymous mmap events if jitdump present

Some processes store jitted code in memfd mappings to avoid having rwx mappings. These processes map the code with a writeable mapping and a read-execute mapping. They write the code using the writeable mapping and then unmap the writeable mapping. All subsequent execution is through the read-execute mapping.

perf inject --jit ignores //anon* mappings for each process where a jitdump is present because it expects to inject mmap events for each jitted code range, and said jitted code ranges will overlap with the //anon* mappings.

Ignore /memfd: and [anon:* mappings so that jitted code contained in /memfd: and [anon:* mappings is treated the same way as jitted code contained in //anon* mappings.

---
 tools/perf/util/jitdump.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/jitdump.c +7 -2
index a23255773c60..4e6632203704 100644
@@ -845,8 +845,13 @@ jit_process(struct perf_session *session,
 	if (jit_detect(filename, pid, nsi)) {
 		nsinfo__put(nsi);
 
-		// Strip //anon* mmaps if we processed a jitdump for this pid
-		if (jit_has_pid(machine, pid) && (strncmp(filename, "//anon", 6) == 0))
+		/*
+		 * Strip //anon*, [anon:* and /memfd:* mmaps if we processed a jitdump for this pid
+		 */
+		if (jit_has_pid(machine, pid) &&
+			((strncmp(filename, "//anon", 6) == 0) ||
+			 (strncmp(filename, "[anon:", 6) == 0) ||
+			 (strncmp(filename, "/memfd:", 7) == 0)))
 			return 1;
 
 		return 0;
Signature · 1 line
2.25.1
reviewer Acked-by on v2 1/1
#1 lore raw
Quoted 12 lines · Brian Robbins

Some processes store jitted code in memfd mappings to avoid having rwx mappings. These processes map the code with a writeable mapping and a read-execute mapping. They write the code using the writeable mapping and then unmap the writeable mapping. All subsequent execution is through the read-execute mapping.

perf inject --jit ignores //anon* mappings for each process where a jitdump is present because it expects to inject mmap events for each jitted code range, and said jitted code ranges will overlap with the //anon* mappings.

Quoted 5 lines

Ignore /memfd: and [anon:* mappings so that jitted code contained in /memfd: and [anon:* mappings is treated the same way as jitted code contained in //anon* mappings.

Thanks,
Ian

Quoted 27 lines
---
 tools/perf/util/jitdump.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/jitdump.c +7 -3
index a23255773c60..4e6632203704 100644
@@ -845,8 +845,13 @@ jit_process(struct perf_session *session,
        if (jit_detect(filename, pid, nsi)) {
                nsinfo__put(nsi);
 
-               // Strip //anon* mmaps if we processed a jitdump for this pid
-               if (jit_has_pid(machine, pid) && (strncmp(filename, "//anon", 6) == 0))
+               /*
+                * Strip //anon*, [anon:* and /memfd:* mmaps if we processed a jitdump for this pid
+                */
+               if (jit_has_pid(machine, pid) &&
+                       ((strncmp(filename, "//anon", 6) == 0) ||
+                        (strncmp(filename, "[anon:", 6) == 0) ||
+                        (strncmp(filename, "/memfd:", 7) == 0)))
                        return 1;
 
                return 0;
--

2.25.1

#2 lore raw
In reply to Brian Robbins

Em Fri, Aug 05, 2022 at 03:06:45PM -0700, Brian Robbins escreveu:

Quoted 6 lines

Some processes store jitted code in memfd mappings to avoid having rwx mappings. These processes map the code with a writeable mapping and a read-execute mapping. They write the code using the writeable mapping and then unmap the writeable mapping. All subsequent execution is through the read-execute mapping.

Quoted 8 lines

perf inject --jit ignores //anon* mappings for each process where a jitdump is present because it expects to inject mmap events for each jitted code range, and said jitted code ranges will overlap with the //anon* mappings.

Ignore /memfd: and [anon:* mappings so that jitted code contained in /memfd: and [anon:* mappings is treated the same way as jitted code contained in //anon* mappings.

Removed v1, applied this one.

- Arnaldo

Quoted 27 lines
---
 tools/perf/util/jitdump.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/jitdump.c +7 -2
index a23255773c60..4e6632203704 100644
@@ -845,8 +845,13 @@ jit_process(struct perf_session *session,
 	if (jit_detect(filename, pid, nsi)) {
 		nsinfo__put(nsi);
 
-		// Strip //anon* mmaps if we processed a jitdump for this pid
-		if (jit_has_pid(machine, pid) && (strncmp(filename, "//anon", 6) == 0))
+		/*
+		 * Strip //anon*, [anon:* and /memfd:* mmaps if we processed a jitdump for this pid
+		 */
+		if (jit_has_pid(machine, pid) &&
+			((strncmp(filename, "//anon", 6) == 0) ||
+			 (strncmp(filename, "[anon:", 6) == 0) ||
+			 (strncmp(filename, "/memfd:", 7) == 0)))
 			return 1;
 
 		return 0;
Signature · 1 line
2.25.1
Signature · 1 line
- Arnaldo