Skip to content

Commit a93e0b2

Browse files
liu-song-6acmel
authored andcommitted
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 <[email protected]> Reported-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Yonghong Song <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Fixes: 76193a9 ("perf, bpf: Introduce PERF_RECORD_KSYMBOL") Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent aa52660 commit a93e0b2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tools/perf/util/map.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,22 @@ bool __map__is_extra_kernel_map(const struct map *map)
261261
return kmap && kmap->name[0];
262262
}
263263

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+
264280
bool map__has_symbols(const struct map *map)
265281
{
266282
return dso__has_symbols(map->dso);

tools/perf/util/map.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name,
159159

160160
bool __map__is_kernel(const struct map *map);
161161
bool __map__is_extra_kernel_map(const struct map *map);
162+
bool __map__is_bpf_prog(const struct map *map);
162163

163164
static inline bool __map__is_kmodule(const struct map *map)
164165
{
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);
166168
}
167169

168170
bool map__has_symbols(const struct map *map);

0 commit comments

Comments
 (0)