-
Notifications
You must be signed in to change notification settings - Fork 224
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 static initializer support to bpf2c - part 1 #2728
Conversation
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #2728 +/- ##
==========================================
+ Coverage 87.19% 87.21% +0.02%
==========================================
Files 129 129
Lines 25184 25312 +128
==========================================
+ Hits 21958 22077 +119
- Misses 3226 3235 +9
|
Signed-off-by: Alan Jowett <[email protected]>
02b2761
to
8333b44
Compare
Signed-off-by: Alan Jowett <[email protected]>
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.
Ok other than a grammar nit in a comment
Co-authored-by: Dave Thaler <[email protected]>
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.
- For my understanding, what is the 'recurse' type in the .values array?
Is it a function pointer? Or if it is an enum, what are the various values it can take? In short, trying to understand how the value is consumed.
- Is the .values an optional array?
Signed-off-by: Alan Jowett <[email protected]>
…windows into static_initializer
The "values" field is defined by BPF convention as a BTF map field. It is how the types of values stored in a BPF map declared via BTF. Optionally it can also be used to declare the initial values for the BPF map that will be set when the map is created. If you take a look at the "tests/sample/tail_call_sequential.c" sample, it should be clearer that the .values field contains the list of programs to be inserted into the BPF map. Likewise, the "tests/sample/map_in_map_btf.c" there is an example of initializing a map in map with an initial value. |
sequential7, sequential8, sequential9, sequential10, sequential11, sequential12, sequential13, | ||
sequential14, sequential15, sequential16, sequential17, sequential18, sequential19, sequential20, | ||
sequential21, sequential22, sequential23, sequential24, sequential25, sequential26, sequential27, | ||
sequential28, sequential29, sequential30, sequential31, sequential32, |
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.
The test case exercising this sample program (TEST_CASE("sequential_tail_call", "[libbpf]")
) is overwriting the map entries manually. I think we should:
- Update the test case to not do so, else the new code path will not be tested.
- Instead of updating this sample, have a new sample program so that one can test normal map creation, and other can test creation + static initialization.
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.
The test was updated to not initialize the map and instead rely on the statically initialized values.
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.
From the above, with this new field,
__array(values, int(struct xdp_md* ctx));
-
Do the user program need to do bpf_map_update_elem for each tail call program?
Eg, for (...) {
bpf_map_update_elem(map_fd, &key, &program_fd, 0);
} -
If yes, What happens if the map elements are not done in that order (index), matching the .values array?
Signed-off-by: Alan Jowett <[email protected]>
Description
Add support for static map initialization via BTF map definitions.
This is part 1, which only changes bpf2c to emit the map definitions in the compiled PE image and to the native loader to consume it.
Part 2 will update the ELF loader to consume this data and set the initial values in the maps.
Testing
CI/CD
Documentation
No.
Installation
No.
Map's data is stored in the ".maps" section of the ELF file. The symbols for the ".maps" section gives the starting and ending offset of each map. The relocations for the ".maps" section give the offset of the initial values for each map. Each relocation record is a pair of (offset, symbol) where the symbol is the map value to insert. To convert offset to index in the "values" field, the first step is to determine which map the offset is for. This is done by finding the map whose range contains the offset. Then the offset is converted to an index by subtracting the offset of the values array and dividing by the size of a pointer. Finally, the value is inserted into the map's initial values vector at the computed index.
As an example, assume a map declared as:
This produces the following symbol records:
So, the maps are as follows:
(0x0, 0x30) -> map
(0x30, 0x50) -> canary.
The relocation data for the .maps section then contains:
So, the relocation is at offset 0x20, which is within the map called "map".
The offset of the "values" field is 0x18 (from the BTF data, not shown here).
Index is then:
(0x20 - 0x18) / sizeof(uintptr) -> 1
So, the map value at index 1 should be "recurse".
There are no relocation records for NULL entries.
Partially resolves: #2555