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

perf bpf: Process PERF_BPF_EVENT_PROG_LOAD for annotation

This patch adds processing of PERF_BPF_EVENT_PROG_LOAD, which sets
proper DSO type/id/etc of memory regions mapped to BPF programs to
DSO_BINARY_TYPE__BPF_PROG_INFO.

Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: kernel-team@fb.com
Link: http://lkml.kernel.org/r/20190312053051.2690567-14-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Song Liu and committed by
Arnaldo Carvalho de Melo
3ca3877a 9b86d04d

+54
+54
tools/perf/util/bpf-event.c
··· 12 12 #include "machine.h" 13 13 #include "env.h" 14 14 #include "session.h" 15 + #include "map.h" 15 16 16 17 #define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr)) 17 18 ··· 26 25 return ret; 27 26 } 28 27 28 + static int machine__process_bpf_event_load(struct machine *machine, 29 + union perf_event *event, 30 + struct perf_sample *sample __maybe_unused) 31 + { 32 + struct bpf_prog_info_linear *info_linear; 33 + struct bpf_prog_info_node *info_node; 34 + struct perf_env *env = machine->env; 35 + int id = event->bpf_event.id; 36 + unsigned int i; 37 + 38 + /* perf-record, no need to handle bpf-event */ 39 + if (env == NULL) 40 + return 0; 41 + 42 + info_node = perf_env__find_bpf_prog_info(env, id); 43 + if (!info_node) 44 + return 0; 45 + info_linear = info_node->info_linear; 46 + 47 + for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) { 48 + u64 *addrs = (u64 *)(info_linear->info.jited_ksyms); 49 + u64 addr = addrs[i]; 50 + struct map *map; 51 + 52 + map = map_groups__find(&machine->kmaps, addr); 53 + 54 + if (map) { 55 + map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO; 56 + map->dso->bpf_prog.id = id; 57 + map->dso->bpf_prog.sub_id = i; 58 + map->dso->bpf_prog.env = env; 59 + } 60 + } 61 + return 0; 62 + } 63 + 29 64 int machine__process_bpf_event(struct machine *machine __maybe_unused, 30 65 union perf_event *event, 31 66 struct perf_sample *sample __maybe_unused) 32 67 { 33 68 if (dump_trace) 34 69 perf_event__fprintf_bpf_event(event, stdout); 70 + 71 + switch (event->bpf_event.type) { 72 + case PERF_BPF_EVENT_PROG_LOAD: 73 + return machine__process_bpf_event_load(machine, event, sample); 74 + 75 + case PERF_BPF_EVENT_PROG_UNLOAD: 76 + /* 77 + * Do not free bpf_prog_info and btf of the program here, 78 + * as annotation still need them. They will be freed at 79 + * the end of the session. 80 + */ 81 + break; 82 + default: 83 + pr_debug("unexpected bpf_event type of %d\n", 84 + event->bpf_event.type); 85 + break; 86 + } 35 87 return 0; 36 88 } 37 89