Closed brendangregg closed 6 years ago
EDIT: ignore this comment, it's a separate issue I've refiled as #18.
Perhaps related perhaps not, comm also doesn't work on that 4.4.90 Ubuntu system:
# strace -febpf ./src/bpftrace -e 'kprobe:sys_nanosleep { printf("sleep by %s\n", comm); }'
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=8}, 72) = -1 EINVAL (Invalid argument)
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=8}, 72) = 3
Attaching 1 probe...
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fff19f71bb0, value=0x7fff19f71bb4, flags=BPF_ANY}, 72) = 0
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=257, insns=0x7f5c60865000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=263258}, 72) = -1 E2BIG (Argument list too long)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=257, insns=0x7f5c60865000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=263258}, 72) = -1 EPERM (Operation not permitted)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=257, insns=0x7f5c60865000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=263258}, 72) = -1 EACCES (Permission denied)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=257, insns=0x7f5c60865000, license="GPL", log_level=1, log_size=65536, log_buf=0x3489630, kern_version=263258}, 72) = -1 EACCES (Permission denied)
bpf: Failed to load program: Permission denied
0: (7b) *(u64 *)(r10 -192) = r1
1: (b7) r1 = 0
2: (7b) *(u64 *)(r10 -136) = r1
3: (bf) r1 = r10
4: (07) r1 += -64
5: (b7) r2 = 64
6: (85) call 16
invalid indirect read from stack off -64+0 size 64
Error loading program: kprobe:sys_nanosleep
+++ exited with 255 +++
The first bug was visible in the strace output:
map_type=0x5 /* BPF_MAP_TYPE_??? */
So that's BPF_MAP_TYPE_PERCPU_HASH, but this Linux 4.4 system doesn't have that -- that was added in 4.6 I think. Switching that to BPF_MAP_TYPE_HASH makes it work. Maybe we need a Linux version test.
Works on 4.15.4:
$ sudo strace -febpf ./bpftrace -e 'kprobe:sys_read { @who[comm] = count(); }'
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_HASH, key_size=64, value_size=8, max_entries=128, map_flags=0, inner_map_fd=0, ...}, 72) = -1 EINVAL (Invalid argument)
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_HASH, key_size=64, value_size=8, max_entries=128, map_flags=0, inner_map_fd=0}, 72) = 3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=2, map_flags=0, inner_map_fd=0, ...}, 72) = 4
Attaching 1 probe...
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x7fff7ae05c2c, value=0x7fff7ae05c08, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x7fff7ae05c2c, value=0x7fff7ae05c08, flags=BPF_ANY}, 72) = 0
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=262, insns=0x7fdbd7069000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=265988, prog_flags=0, ...}, 72) = -1 EINVAL (Invalid argument)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=262, insns=0x7fdbd7069000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=265988, prog_flags=0}, 72) = 8
^Cstrace: Process 16120 detached
@who[kuiserver5]: 1
@who[klauncher]: 1
@who[kscreen_backend]: 1
[ ... ]
Doesn't work on Ubuntu 17.10 (kernel 4.13) either:
# strace -febpf ./bpftrace -e 'kprobe:sys_read { @who[comm] = count(); }'
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_HASH, key_size=64, value_size=8, max_entries=128}, 72) = -1 EINVAL (Invalid argument)
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_HASH, key_size=64, value_size=8, max_entries=128}, 72) = 3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=4}, 72) = -1 EINVAL (Invalid argument)
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=4}, 72) = 4
Attaching 1 probe...
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x7fffef03ce80, value=0x7fffef03ce84, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x7fffef03ce80, value=0x7fffef03ce84, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x7fffef03ce80, value=0x7fffef03ce84, flags=BPF_ANY}, 72) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x7fffef03ce80, value=0x7fffef03ce84, flags=BPF_ANY}, 72) = 0
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=49, insns=0x7f6034f62000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=265472}, 72) = -1 E2BIG (Argument list too long)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=49, insns=0x7f6034f62000, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=265472}, 72) = -1 EINVAL (Invalid argument)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=49, insns=0x7f6034f62000, license="GPL", log_level=1, log_size=65536, log_buf=0x561553519740, kern_version=265472}, 72) = -1 EINVAL (Invalid argument)
bpf: Failed to load program: Invalid argument
Error loading program: kprobe:sys_read
+++ exited with 255 +++
# uname -a
Linux jr-ThinkPad-T430 4.13.0-37-generic #42-Ubuntu SMP Wed Mar 7 14:13:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
I also have problems with many other examples from #34
I think above comment is more appropriate under issue #8. I have just tried patch #16 and it works for me.
Fixed with #17
After fixing kern_version (#8), this Ubuntu Linux 4.4.90 system can then do printf(), but not maps. Eg:
This works fine on a 4.14 system:
I wonder if it's the same as issue #8 somehow.