Message ID | 1444826502-49291-6-git-send-email-wangnan0@huawei.com |
---|---|
State | New |
Headers | show |
Hi Arnaldo, On 2015/10/24 8:27, Arnaldo Carvalho de Melo wrote: > libbpf: load bpf program failed: Invalid argument > libbpf: -- BEGIN DUMP LOG --- > libbpf: > > libbpf: -- END LOG -- > libbpf: failed to load program 'fork=_do_fork' > libbpf: failed to load object '/tmp/foo.o' > bpf: load objects failed > event syntax error: '/tmp/foo.o' > \___ Invalid argument: Are you root and runing a CONFIG_BPF_SYSCALL kernel? > > (add -v to see detail) > Run 'perf list' for a list of valid events > > Usage: perf record [<options>] [<command>] > or: perf record [<options>] -- <command> [<options>] > > -e, --event <event> event selector. use 'perf list' to list available events > Opening /sys/kernel/debug/tracing//kprobe_events write=1 > Opening /sys/kernel/debug/tracing//uprobe_events write=1 > Parsing probe_events: p:perf_bpf_probe/fork _text+638512 > Group:perf_bpf_probe Event:fork probe:p > Writing event: -:perf_bpf_probe/fork > [acme@felicio linux]$ uname -a > Linux felicio.ghostprotocols.net 4.3.0-rc6+ #1 SMP Fri Oct 23 16:40:25 BRT 2015 x86_64 x86_64 x86_64 GNU/Linux > [acme@felicio linux]$ > Please have a look at patch [1]. With that patch kernel will dump something into log buffer. In your case, you will see: root@sandybridge:~# /tmp/perf record -e /tmp/test_config_base.o ls libbpf: load bpf program failed: Invalid argument libbpf: -- BEGIN DUMP LOG --- libbpf: Kernel version mismatch: 0x40400 != 0x40300 libbpf: -- END LOG -- libbpf: failed to load program 'func_write=sys_write' libbpf: failed to load object '/tmp/test_config_base.o' event syntax error: '/tmp/test_config_base.o' \___ Invalid argument: Are you root and runing a CONFIG_BPF_SYSCALL kernel? (add -v to see detail) Run 'perf list' for a list of valid events ... And I'd like to improve the error message output by perf. Do you want me to send a patch for fixing this problem or modifying existing patches in my git tree? Thank you. [1] http://lkml.kernel.org/r/1445843588-143137-1-git-send-email-wangnan0@huawei.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 56f6fe8..7279558 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -243,6 +243,18 @@ int bpf__unprobe(struct bpf_object *obj) return ret; } +int bpf__load(struct bpf_object *obj) +{ + int err; + + err = bpf_object__load(obj); + if (err) { + pr_debug("bpf: load objects failed\n"); + return err; + } + return 0; +} + #define bpf__strerror_head(err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\ @@ -275,3 +287,13 @@ int bpf__strerror_probe(struct bpf_object *obj __maybe_unused, bpf__strerror_end(buf, size); return 0; } + +int bpf__strerror_load(struct bpf_object *obj __maybe_unused, + int err, char *buf, size_t size) +{ + bpf__strerror_head(err, buf, size); + bpf__strerror_entry(EINVAL, "%s: Are you root and runing a CONFIG_BPF_SYSCALL kernel?", + emsg) + bpf__strerror_end(buf, size); + return 0; +} diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index b819622..b091ceb 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -23,6 +23,9 @@ int bpf__unprobe(struct bpf_object *obj); int bpf__strerror_probe(struct bpf_object *obj, int err, char *buf, size_t size); +int bpf__load(struct bpf_object *obj); +int bpf__strerror_load(struct bpf_object *obj, int err, + char *buf, size_t size); #else static inline struct bpf_object * bpf__prepare_load(const char *filename __maybe_unused) @@ -35,6 +38,7 @@ static inline void bpf__clear(void) { } static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} +static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } static inline int __bpf_strerror(char *buf, size_t size) @@ -55,5 +59,12 @@ bpf__strerror_probe(struct bpf_object *obj __maybe_unused, { return __bpf_strerror(buf, size); } + +static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, + int err __maybe_unused, + char *buf, size_t size) +{ + return __bpf_strerror(buf, size); +} #endif #endif diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 06ff8d6..5b17b88 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -561,6 +561,12 @@ int parse_events_load_bpf_obj(struct parse_events_evlist *data, goto errout; } + err = bpf__load(obj); + if (err) { + bpf__strerror_load(obj, err, errbuf, sizeof(errbuf)); + goto errout; + } + /* * Temporary add a dummy event here so we can check whether * basic bpf loader works. Following patches will replace
This patch utilizes bpf_object__load() provided by libbpf to load all objects into kernel. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Alexei Starovoitov <ast@plumgrid.com> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: David Ahern <dsahern@gmail.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kaixu Xia <xiakaixu@huawei.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Link: http://lkml.kernel.org/n/ebpf-6yw9eg0ej3l4jnqhinngkw86@git.kernel.org --- tools/perf/util/bpf-loader.c | 22 ++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 11 +++++++++++ tools/perf/util/parse-events.c | 6 ++++++ 3 files changed, 39 insertions(+)