-
Notifications
You must be signed in to change notification settings - Fork 212
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
Allow static initialization for BPF_MAP_TYPE_HASH_OF_MAPS map with integer as key_size #2951
Comments
I think this issue stemmed from the fact that the native program loader failed to load Cilium XDP program with the following map definition.
This is tracked by: Issue #2854 While trying to work around this, I inadvertently made an incorrect suggestion that on Windows we could represent the above as:
The static initialization part at the end is not needed at all. And it created further issues with loading the program as static initializing a hashmap was not supported. Later @Alan-Jowett found out this super corner case in Linux where this is actually supported. Here is the slack channel conversation: Why create a hashmap if “use it exactly the same way as array” ? Also, I don’t buy that key-size of 4 bytes implies the key is actually an integer and can be used as an array index. Instead the key type should be an integer type. Pull Request #2952 attempts to replicate the Linux behavior. But I am not sure if it actually does as what the slack conversation above suggests. The _ebpf_native_set_initial_map_values function was originally meant for arraymaps and prog_arrays only. It treats the outer map as an array and adds the inner map instances to it with the array index as key here:
See how the inner maps are inserted using ebpf_core_update_map_with_handle. Since the outer map is defined as a hashmap; the update function will eventually invoke ebpf_hash_table_update which would compute a hash of the key by invoking _ebpf_murmur3_32. So unlike array, there is no “order” in the entries. Not sure if this is a big deal. Also, I have doubts about if this should work for keys of size 1 byte and 2 bytes which the above PR allows. And most importantly the Cilium program does not static initialize the hashmaps. For example, the maglev map (hashmap); even though has a key of type uint16_t; its not really an array index – it’s the service ID. So static intitilization does not make any sense for the maglev map. |
We should also consider putting a more robust initialization method where both {key, values} are specified. |
Fixed by #3211 |
Describe the bug
Request: Allow static initialization for BPF_MAP_TYPE_HASH_OF_MAPS map value with integer as key_size.
Reason: BPF_MAP_TYPE_HASH_OF_MAPS style maps have no implicit key value but if the key type is defined as an integer, it can be statically initialized.
Reference:
"For BPF_MAP_TYPE_HASH_OF_MAPS the key type can be chosen when defining the map. "
Map structure:
OS information
Windows 10 and above
Steps taken to reproduce bug
Please see #2882.
Expected behavior
Hash-of-maps should be statically initialized if the key is an integer.
Actual outcome
Please see #2882 for analysis.
Additional details
No response
The text was updated successfully, but these errors were encountered: