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
bpf: Migrate cilium-migrate-map
from C to Go
#16917
bpf: Migrate cilium-migrate-map
from C to Go
#16917
Conversation
ad37ac7
to
21ffe74
Compare
@nathanjsweet MBOI #16561. |
b99b8e5
to
c8fe204
Compare
2e5dcd4
to
f9a7dc6
Compare
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.
Hey, thanks for taking this on. I think most of the code around renaming map pins can be removed, as the lib has Map.Pin()
that was introduced specifically for this renaming use case.
I don't think we should pass in $RETCODE
, let's handle any conditionals in the script itself.
Also, we should take #16561 into account, but can be done in a follow-up. Will further the discussion on the issue itself.
f9a7dc6
to
6f0932f
Compare
6f0932f
to
d06baee
Compare
a154b15
to
80b2b10
Compare
/test |
4b2a1ab
to
eb711d6
Compare
/test Job 'Cilium-PR-K8s-1.21-kernel-4.9' failed and has not been observed before, so may be related to your PR: Click to show.Test Name
Failure Output
If it is a flake, comment |
/test |
17e9cd1
to
c8be0b5
Compare
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.
Thanks @ti-mo for walking me through the change. LGTM with one minor comment which can be done in a follow-up PR if needed.
#include "elf/libelf.h" | ||
#include "elf/gelf.h" | ||
|
||
#include "bpf/ctx/nobpf.h" |
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.
It looks like cilium-map-migrate.c
is the only user of the headers in bpf/include/elf
and the bpf/ctx/nobpf.h
. So I think we can safely remove these as part of this PR as well.
Also, we no longer need to link binaries against libelf
so we can remove -lelf
from bpf/Makefile
here:
Lines 306 to 307 in 6a722d3
@# Due to gcc bug, -lelf needs to be at the end. | |
$(QUIET) ${HOST_CC} -Wall -O2 -Wno-format-truncation -I include/ $@.c -lelf -o $@ |
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.
Thanks, that's great news! 😁 Will tackle in a follow-up. 👍
/test Job 'Cilium-PR-Runtime-net-next' failed and has not been observed before, so may be related to your PR: Click to show.Test Name
Failure Output
If it is a flake, comment Job 'Cilium-PR-K8s-1.19-kernel-5.4' failed and has not been observed before, so may be related to your PR: Click to show.Test Name
Failure Output
If it is a flake, comment |
c8be0b5
to
f17159d
Compare
/test Job 'Cilium-PR-K8s-1.21-kernel-4.9' failed and has not been observed before, so may be related to your PR: Click to show.Test Name
Failure Output
If it is a flake, comment |
f17159d
to
6f160eb
Compare
Upgrade the lib to make use of new pinning features. Signed-off-by: Timo Beckers <timo@isovalent.com>
Document the ELF parsing logic to make it easier to grok. Signed-off-by: Timo Beckers <timo@isovalent.com>
This patch uses io.WriteSeeker.Seek() to navigate to each symbol's offset instead of alternating between streaming input from the original ELF and inscribing replacement values. The new approach is slightly more straightforward as no global offset tracking needs to take place. Signed-off-by: Timo Beckers <timo@isovalent.com>
The way we currently perform string substitutions in ELFs no longer holds up with the presence of a BTF blob. The .BTF section has its own string table for representing type metadata, and cilium/ebpf uses this table to perform lookups for building its internal representations of the BTF type graph. This behaviour should not be altered, as it makes sure all ELF symbols are correctly represented in the BTF blob. This patch extends our current approach to also rewrite pieces of the .BTF section, which will be required for as long as we keep using a mix of iproute2 and cilium/ebpf for reading ELFs. Signed-off-by: Timo Beckers <timo@isovalent.com>
Currently initializing bpf programs and migrating maps is done by a C program implementing an ELF parser. This patch introduces a Go version of the program where cilium/ebpf does the heavy lifting instead. The feature is now also exposed as a Go API, making it callable from other parts of the agent. This version also parses and verifies the ELF's BTF section. A CLI wrapper is temporarily included to make it callable from init.sh while it is translated to Go. Signed-off-by: Nate Sweet <nathanjsweet@pm.me> Co-authored-by: Timo Beckers <timo@isovalent.com>
This uses the newly-ported Go logic to execute bpffs map migrations in replaceQdisc and replaceDatapath. Also simplified the control flow a bit to avoid accidentally shadowing err. The revert behaviour has been made more explicit. Signed-off-by: Timo Beckers <timo@isovalent.com>
This has been replaced with a Go-based implementation, so no longer needs to be part of the build/packaging process. The CILIUM_BPF_MNT env has been removed from shell invocations pertaining to bpffs since it was only referenced in cilium-map-migrate. Signed-off-by: Timo Beckers <timo@isovalent.com>
6f160eb
to
66cd0e0
Compare
/test |
/mlh new-flake Cilium-PR-K8s-1.21-kernel-4.9 |
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.
Nice stuff! The pull request is really easy to review thanks to all the comments :-)
I have a couple nits below, which I'll send as a separate PR given I'm a bit late to the merge party.
As flagged by @tklauser in cilium#16917 (comment), these headers are no longer used, and we no longer need to link against libelf. Signed-off-by: Timo Beckers <timo@isovalent.com>
As flagged by @tklauser in #16917 (comment), these headers are no longer used, and we no longer need to link against libelf. Signed-off-by: Timo Beckers <timo@isovalent.com>
Currently, initializing bpf programs and migrating maps is done by a C program implementing an ELF parser. This patch introduces a Go version of the program where
cilium/ebpf
does the heavy lifting instead. The feature is now also exposed as a Go API, making it callable from other parts of the agent. This version also parses and verifies the ELF's BTF section.A CLI wrapper is temporarily included to make it callable from init.sh while it is translated to Go.
Best reviewed per commit.