note-taking post – bpf kernel dev - how to begin hacking it
by Anne Macedo
This is a very unstructured post, full of errors and stuff. Use it only for reference.
After spending some time lurking on the bpf mailing lists, I figured out it might be a good idea to start checking some code as well. So, I decided to clone the bpf-next tree and check what’s in there. This way, I can see some of the patches that I’ve seen in the mailing list.
I’ve also seen some interesting issues on the libbpf mirror on Github, from OSSFUZZ. [1]
Truth is: I don’t understand this issue [1] 🤡
I will take a look at the selftests then. [2]
I saw a bunch of errors… attempted to only make the bpf tests.
And more errors! Related to this [3].
And I realized that I found a small bug!
This “Unknown error” should actually be positive to tell that the file does not exist. I tried changing it manually on the code and I got the right message.
This is how you compile the bpftool.
Will keep you posted if this change makes its way to the kernel :).
updates
Found the correct way to enable BTF in order to run selftests. I need to run make menuconfig and search for DEBUG_INFO_BTF. From there, check all the dependencies and enable them. [4]
Then:
And… I got new errors! 🫠
I updated clang to clang-16. Hint was in [4].
New error:
According to the email:
Discussion at [5].
Using menuconfig, I enabled CGROUP_BPF. That… didn’t do anything :(
Hints at [6] and [7]. I may need to learn chinese…
I realized I don’t have memory cgroups available!
That… didn’t work. I really don’t know how to fix it.
I fixed it by enabling CONFIG_MEMCG!
More errors:
Now, run actual tests!
Tried cding to the bpf self tests directory and ran make run_tests… it’s working now? More or less since I see a bunch of errors but none fatal. Ran as sudo, creepy but it works!
References
[1] libbpf #484 [2] Linux Kernel Selftests [3] bpftool: print correct error message when failing to load BTF [4] Re: bpf selftest compiling error [5] [bpf-next,v6,8/8] selftests/bpf: add a selftest for cgroup hierarchical stats collection [6] cgroup中的cgroup_subsys[]数组解析 [7] cgroups on the raspberry pi zero [8] Re: [PATCH bpf-next v2 2/2] selftests/bpf: Add connmark read test
tags: