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

perf tools: Check maps for bpf programs

As reported by Jiri Olsa in:

"[BUG] perf: intel_pt won't display kernel function"
https://lore.kernel.org/lkml/20190403143738.GB32001@krava

Recent changes to support PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT
broke --kallsyms option. This is because it broke test __map__is_kmodule.

This patch fixes this by adding check for bpf program, so that these maps
are not mistaken as kernel modules.

Signed-off-by: Song Liu <songliubraving@fb.com>
Reported-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yonghong Song <yhs@fb.com>
Link: http://lkml.kernel.org/r/20190416160127.30203-8-jolsa@kernel.org
Fixes: 76193a94522f ("perf, bpf: Introduce PERF_RECORD_KSYMBOL")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Song Liu and committed by
Arnaldo Carvalho de Melo
a93e0b23 aa526602

+19 -1
+16
tools/perf/util/map.c
··· 261 261 return kmap && kmap->name[0]; 262 262 } 263 263 264 + bool __map__is_bpf_prog(const struct map *map) 265 + { 266 + const char *name; 267 + 268 + if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) 269 + return true; 270 + 271 + /* 272 + * If PERF_RECORD_BPF_EVENT is not included, the dso will not have 273 + * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can 274 + * guess the type based on name. 275 + */ 276 + name = map->dso->short_name; 277 + return name && (strstr(name, "bpf_prog_") == name); 278 + } 279 + 264 280 bool map__has_symbols(const struct map *map) 265 281 { 266 282 return dso__has_symbols(map->dso);
+3 -1
tools/perf/util/map.h
··· 159 159 160 160 bool __map__is_kernel(const struct map *map); 161 161 bool __map__is_extra_kernel_map(const struct map *map); 162 + bool __map__is_bpf_prog(const struct map *map); 162 163 163 164 static inline bool __map__is_kmodule(const struct map *map) 164 165 { 165 - return !__map__is_kernel(map) && !__map__is_extra_kernel_map(map); 166 + return !__map__is_kernel(map) && !__map__is_extra_kernel_map(map) && 167 + !__map__is_bpf_prog(map); 166 168 } 167 169 168 170 bool map__has_symbols(const struct map *map);