Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Brian Robbins <brianrob@linux.microsoft.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220805220645.95855-1-brianrob@linux.microsoft.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Brian Robbins and committed by
Arnaldo Carvalho de Melo
46f7bd5e e0b23af8

+7 -2
+7 -2
tools/perf/util/jitdump.c
··· 845 845 if (jit_detect(filename, pid, nsi)) { 846 846 nsinfo__put(nsi); 847 847 848 - // Strip //anon* mmaps if we processed a jitdump for this pid 849 - if (jit_has_pid(machine, pid) && (strncmp(filename, "//anon", 6) == 0)) 848 + /* 849 + * Strip //anon*, [anon:* and /memfd:* mmaps if we processed a jitdump for this pid 850 + */ 851 + if (jit_has_pid(machine, pid) && 852 + ((strncmp(filename, "//anon", 6) == 0) || 853 + (strncmp(filename, "[anon:", 6) == 0) || 854 + (strncmp(filename, "/memfd:", 7) == 0))) 850 855 return 1; 851 856 852 857 return 0;