-
Notifications
You must be signed in to change notification settings - Fork 95
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
legacy cgroup attachment functionality (needed for <= 5.6 kernels) #214
legacy cgroup attachment functionality (needed for <= 5.6 kernels) #214
Conversation
LGTM so far. I can't run the tests on a generic/ubuntu2004 box, unfortunately. vagrant@ubuntu2004:~/libbpfgo/selftest/cgroup-legacy$ uname -a
Linux ubuntu2004.localdomain 5.4.0-122-generic #138-Ubuntu SMP Wed Jun 22 15:00:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
vagrant@ubuntu2004:~/libbpfgo/selftest/cgroup-legacy$ pwd
/home/vagrant/libbpfgo/selftest/cgroup-legacy
vagrant@ubuntu2004:~/libbpfgo/selftest/cgroup-legacy$ git branch
* cgroup-attach-legacy
main
tinoco
vagrant@ubuntu2004:~/libbpfgo/selftest/cgroup-legacy$ make
make -C /home/vagrant/libbpfgo libbpfgo-static
make[1]: Entering directory '/home/vagrant/libbpfgo'
CC=clang \
CGO_CFLAGS="-I/home/vagrant/libbpfgo/output" \
CGO_LDFLAGS="-lelf -lz /home/vagrant/libbpfgo/output/libbpf.a" \
GOOS=linux GOARCH=amd64 \
go build \
-tags netgo -ldflags '-w -extldflags "-static"' \
.
make[1]: Leaving directory '/home/vagrant/libbpfgo'
make -C /home/vagrant/libbpfgo vmlinuxh
make[1]: Entering directory '/home/vagrant/libbpfgo'
make[1]: Leaving directory '/home/vagrant/libbpfgo'
clang -g -O2 -Wall -fpie -target bpf -D__TARGET_ARCH_amd64 -I../../output -c main.bpf.c -o main.bpf.o
In file included from main.bpf.c:3:
In file included from ../../output/bpf/bpf_helpers.h:11:
../../output/bpf/bpf_helper_defs.h:73:83: error: unknown type name '__u64'
static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = (void *) 2;
^
../../output/bpf/bpf_helper_defs.h:97:42: error: unknown type name '__u32'
static long (*bpf_probe_read)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 4;
... |
If this is a Focal machine, please check tracee/packaging/Dockerfile.ubuntu-packaging file to see how to properly install needed toolchain (clang-12 needed, etc). |
- Add AttachCgroupLegacy() AttachCgroupLegacy attaches the BPFProg to a cgroup described by given fd. It first tries to use the most recent attachment method and, if that does not work, instead of failing it tries the legacy way: to attach the cgroup eBPF program without previously creating a link. Related to upstream kernel commit af6eea57437a ("bpf: Implement bpf_link-based cgroup BPF program attachment"). - Add DetachCgroupLegacy() DetachCgroupLegacy detaches the BPFProg from a cgroup described by given fd. This is needed because in legacy attachment there is no BPFLink, just a fake one (kernel did not support it, nor libbpf). This function should be called by the (*BPFLink)->Destroy() function, since BPFLink is emulated (so user don´t need to distinguish between regular and legacy cgroup detachments).
Note: this test will be skipped for kernels >= 5.4 (because its original intent is to test the old attachment model, not the new one, already being tested by other test(s)).
The test still works in newer kernels but with a warning: Because it is just testing the newer cgroup attachment type in those cases. When we run in kernels <= 5.4, then we get no warning and we test the interface for real. I thought about adding a flag to "force" using the legacy method but I don't think I should, so... it is what it is =). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I like what you did with those latest changes (selftest running regardless, legacy struct)
I'm still working on this. Will finish the selftest and try to REAL use cases before moving away from draft. But feel free to review the work so far. Thanks.