[PATCH 0/5] perf bpf: Improve error code delivering and output

From: Wang Nan
Date: Tue Nov 03 2015 - 06:01:01 EST


This patchset is based on tip/core.

Arnaldo found some confusing error reports when reviewing BPF related
patches. This patch set makes some changes:

- perf test only print ok, failed or skip. Extra messages can be seen
by '-v'.

- libbpf not output anything when called from perf without '-v'.

- Create libbpf and bpf-loader specific error number group to deliver
precise error. New strerror framework makes adding new error code
easier.

- Improve error messages.

After applying this patch:

When target object not exist:

$ ls ./foo.o
ls: cannot access ./foo.o: No such file or directory
$ ./perf record --event foo.o sleep
event syntax error: 'foo.o'
\___ Failed to load foo.o: No such file or directory

(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

When target object format invalid:

$ cp /etc/passwd ./badbpf.o
$ ./perf record --event ./badbpf.o sleep
event syntax error: './badbpf.o'
\___ Failed to load ./badbpf.o: BPF object format invalid
(... skip ...)

When run by normal user and /proc/sys/kernel/kptr_restrict is 1:

$ cat /proc/sys/kernel/kptr_restrict
1
$ ./perf record --event ./bpf-script-example.o sleep
Failed to init vmlinux path.
event syntax error: './bpf-script-example.o'
\___ You need to be root, and /proc/sys/kernel/kptr_restrict should be 0
(... skip ...)

After fixing /proc/sys/kernel/kptr_restrict:

$ sudo -s
# echo 0 > /proc/sys/kernel/kptr_restrict
# exit
$ ./perf record --event ./bpf-script-example.o sleep
Failed to open kprobe_events: Permission denied
event syntax error: './bpf-script-example.o'
\___ You need to be root
(... skip ...)

Load an object with no 'version' section:

# ./perf record --event ./bpf-script-example.o sleep
event syntax error: './bpf-script-example.o'
\___ Failed to load ./bpf-script-example.o: 'version' section incorrect or lost
(... skip ...)

Load an object with incorrect 'version' section:
# ./perf record --event ./bpf-script-example.o sleep
event syntax error: './bpf-script-example.o'
\___ Failed to load program: Validate your program and check 'license'/'version' sections in your object
(... skip ...)

When event name not set:

# ./perf record --event ./bpf-script-example.o sleep
event syntax error: './bpf-script-example.o'
\___ No event name found in config string
(... skip ...)

Wang Nan (5):
perf test: Keep test result clean if '-v' not set
perf tools: Mute libbpf when '-v' not set
perf tools: Parsing libbpf return value using err.h
bpf tools: Improve libbpf error reporting
perf tools: Improve BPF related error messages output

tools/lib/bpf/libbpf.c | 149 +++++++++++++++++++++++++------------
tools/lib/bpf/libbpf.h | 12 +++
tools/perf/tests/attr.c | 3 +-
tools/perf/tests/code-reading.c | 8 +-
tools/perf/tests/keep-tracking.c | 4 +-
tools/perf/tests/llvm.c | 13 ++--
tools/perf/tests/switch-tracking.c | 4 +-
tools/perf/util/bpf-loader.c | 110 +++++++++++++++++++++++----
tools/perf/util/bpf-loader.h | 18 +++++
tools/perf/util/parse-events.c | 7 +-
10 files changed, 243 insertions(+), 85 deletions(-)

--
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/