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: convert majority of bpf_elf_map
definitions to BTF map definitions
#17640
Conversation
ad79401
to
1654233
Compare
/test |
1 similar comment
/test |
12af5df
to
769163a
Compare
/test |
769163a
to
a071146
Compare
/test Rebased onto master for picking up e057d60 |
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, only minor comments below.
I'm not super confident in my review of the Maglev inner map changes, but I see @borkmann is marked as a reviewer anyway.
a071146
to
afc9a72
Compare
/test |
afc9a72
to
44238da
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.
Nice work! Two nits below (non-blocking).
As a side note, it's not often that we touch so many bpf/
files, and you could take this chance to update the copyright year in most of the files you changed.
This is the first in a series of patches that converts most bpf_elf_map definitions to BTF map definitions. The changes in this patch are limited to maps that are supported by both cilium/ebpf and iproute2+libbpf. Further work is necessary to convert PROG_ARRAY and HASH_OF_MAPS map types given the legacy (iproute2) that needs to be handled. This patch contains mostly non-snowflakes; maps that were more involved to convert are addressed in separate commits. A __section_maps_btf macro was added to emit BTF map definitions into the well-known .maps section. Two other macros, __uint and __type were added, which are part of the BTF map definition spec/layout. The premise of BTF map definitions is that all struct fields must be pointers to save space in the .maps section, and (ab)using the BTF type graph to encode the actual values. In the case of __uint, the length of the array declared by the macro is set to the value given to the macro. The length of the array is then queried at load time and used as the 'value' of that struct member. A few more changes were required to functions that passed an explicit type of btf_elf_map *, which was changed to void *, as the BPF kernel-side map API also takes void *. Signed-off-by: Timo Beckers <timo@isovalent.com>
BTF map definitions allow for specifying a key and value type, which is used for pretty-printing map dumps. BPF arrays don't seem to support non-scalar keys when BTF info is attached, so some refactoring was needed to eliminate the struct key. Since get_encrypt_key() was only called with a zero argument, remove the argument and hardcode it in the function. Signed-off-by: Timo Beckers <timo@isovalent.com>
Broken out into a separate commit because bpf_ct_tests.c copies the map's address in a way that assumes the map is a bpf_elf_map. Access the map's global variable directly instead. patchELF() is also dropped since it is no longer necessary as of version 0.7.0 of cilium/ebpf. The trailing bytes are now carried in MapSpec.Extra and can be parsed or zeroed out by the caller. mark ct_key as static so it doesn't end up in .rodata. Signed-off-by: Timo Beckers <timo@isovalent.com>
This is an early example of what statically initialized PROG_ARRAY maps look like. This way of using .values is currently only supported by cilium/ebpf. While working on this, I noticed this program is never loaded into the kernel, which should probably be changed later as we can start making more use of PROG_RUN for testing purposes. Signed-off-by: Timo Beckers <timo@isovalent.com>
This patch moves over the v4 and v6 Maglev maps to BPF map definitions. NO_PREPOPULATE is no longer necessary given the 'inner_idx' field is not present in BTF map definitions, so it can no longer default to 0. This would normally lead to the inner map being inserted into the outer map at index 0, but BTF map definitions have the .values mechanism to populate outer maps instead. If .values is empty, no outer map writes will be performed. Both libbpf and cilium/ebpf immediately remove inner maps after the outer map has been created, so there is not much point in naming them. They can also not be pinned. The inner map name constants were removed from the agent, and bugtool no longer tries to open them from bpffs. The verifier-test image is upgraded simultaneously because the previous version was the pre-libbpf version of iproute2, which does not support relocating BTF map definitions into progbits yet. Unfortunately, this new version also contains a bug in how legacy bpf_elf_map inner maps are detected, see: https://lore.kernel.org/netdev/20211013143927.GA38205@Mem. In lieu of the iproute2 patch landing upstream, this bug is worked around by this very patch, by converting map-in-maps to BTF map definitions and no longer relying on bpf_elf_map compat code. Signed-off-by: Timo Beckers <timo@isovalent.com>
44238da
to
8bf4206
Compare
@qmonnet Good point, done! |
Marked as ready, all k8s tests were green before and no functional changes were made during the last round of feedback. Kicking off a last round of tests just to make sure. (it takes hours...) |
/test Job 'Cilium-PR-K8s-1.19-kernel-5.4' hit: #17069 (92.67% similarity) Job 'Cilium-PR-K8s-GKE' 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 |
Implements part of: #15149.
Best reviewed per commit.
Note that these were converted by hand using some macros, so would like an extra set of eyes to verify before/after.
This notably omits
PROG_ARRAY
andHASH_OF_MAPS
maps because there is some extra work that needs to be done for those. They will be addressed in a follow-up.