-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multi kprobe attach #90
Conversation
1d811fc
to
51dcbbf
Compare
Refactor the single kprobe attach to a function to prepare for multi kprobe attach Progresses: cilium#87 Signed-off-by: Vincent Li <[email protected]>
51dcbbf
to
e8c11d6
Compare
tested this draft PR on kernel running 5.19 which should support multi kprobe, but got operation not supported, it appears the attach type is not set properly ? strace:
|
f184e61
to
1377150
Compare
upgraded one of my ubuntu 22.04 kernel to 2180 bpf(BPF_LINK_CREATE, {link_create={prog_fd=15, target_fd=0, attach_type=0x2a /* BPF_??? */, flags=0}, ...}, 48) = -1 EINVAL (Invalid argument) 2180 write(2, "2022/09/26 15:42:33 Failed to attach multi kprobes: attaching 'Kprobe(kprobe_skb_5)#15' failed: invalid argument (missing kernel symbol or prog's AttachType not AttachTraceKprobeMulti?)\n", 186 <unfinished ...> |
I hacked the pwu main.go code to be only like below, the multi kprobe works on my ubuntu 22.04 with 5.19 kernel, seems something wrong with this draft PR code
|
Could you run |
1377150
to
42ebc8a
Compare
limited to attach to kfree_skb function test, same error
strace: Process 13990 attached [pid 13999] bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=4, max_entries=1, map_flags=0, inner_map_fd=0</dev/pts/0<char 136:0>>, map_name="feature_test", map_ifindex=0, btf_fd=0</dev/pts/0<char 136:0>>, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 7<anon_inode:bpf-map> [pid 13999] bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=6, insns=0xc001344030, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0</dev/pts/0<char 136:0>>, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0</dev/pts/0<char 136:0>>, fd_array=NULL}, 144) = 11<anon_inode:bpf-prog> [pid 14001] bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=802, insns=0xc001b16000, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(5, 19, 11), prog_flags=0, prog_name="kprobe_skb_5", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=7<anon_inode:btf>, func_info_rec_size=8, func_info=0xc0044521c0, func_info_cnt=1, line_info_rec_size=16, line_info=0xc004e29000, line_info_cnt=229, attach_btf_id=0, attach_prog_fd=0</dev/pts/0<char 136:0>>, fd_array=NULL}, 144) = 15<anon_inode:bpf-prog> |
I think the attach type is wrong:
It has to be
|
ah, that is it! |
hm, the code is still broken, do filter on ip test
filter on function name seems working
2022/09/26 17:57:00 Per cpu buffer size: 4096 bytes |
added
I can see the symbols printed out
2022/09/26 18:21:47 Per cpu buffer size: 4096 bytes |
I suspect for some reason the kernel multi kprobe could not find all the symbols supplied by pwru. |
42ebc8a
to
69b782f
Compare
look through kernel code, wondering if the ESRCH is coming from https://elixir.bootlin.com/linux/latest/source/kernel/trace/ftrace.c#L8078
|
|
Looks like we need to check whether a function is in |
indeed functions like |
cdf7676
to
27ead5b
Compare
kind of getting a half "working" code, it appears no guarantee all symbols can be attached
2022/09/26 22:40:19 Per cpu buffer size: 4096 bytes |
to confirm, i added log in kernel, and indeed it is
[root@centos-dev bpf-next]# tail -f /var/log/kern.log Sep 26 19:21:09 centos-dev kernel: ftrace_lookup_symbols return 0 |
looked further grep '__bpf_redirect_no_mac' /sys/kernel/debug/tracing/available_filter_functions |
a6488ae
to
61595ee
Compare
210b269
to
1689f8c
Compare
it seems working reliably now after taking interSection logic code from https://go.dev/play/p/eGGcyIlZD6y :). the logic is outer loop to get each string from first slice, inner loop to compare the string from first slice to each string in second slice, if it is same string and hash map keyed by the string not exist, add the string to the new slice, set the hash map keyed by the string to true to avoid duplicate I guess. |
c51a1a0
to
d4edec6
Compare
now the draft PR seems working fine for both single kprobe and multi kprobe, need some clean up work, maybe move all the functions other than main from main.go to another go file in internal/pwru directory |
6a3c004
to
7e3cd4b
Compare
Signed-off-by: Vincent Li <[email protected]>
Signed-off-by: Vincent Li <[email protected]> Co-authored-by: Martynas Pumputis <[email protected]>
7e3cd4b
to
2c8477c
Compare
for the record, enable kernel config |
Closing in favor of #99. Thanks! |
Refactor the single kprobe attach to a function to prepare for add multi kprobe attach
Progresses: #87
Signed-off-by: Vincent Li [email protected]