-
Notifications
You must be signed in to change notification settings - Fork 232
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 #2952
Allow static initialization for BPF_MAP_TYPE_HASH_OF_MAPS map with integer as key_size #2952
Conversation
ebpf_map_definition_in_file_t map_def = native_map_to_update->entry->definition; | ||
uint32_t key_size = map_def.key_size; | ||
bool is_hash_of_maps_with_int_key = (map_def.type == BPF_MAP_TYPE_HASH_OF_MAPS) && | ||
(key_size == sizeof(uint8_t) || |
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.
what if key size is uint8_t and max_entries exceeds 256 etc.? Does this code handle that? @Alan-Jowett can you confirm if Linux mandates key_size to be strictly 4-bytes in this case?
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.
Can you please clarify the concern on the max_entries (number of entries in the hash table) and key_size (size of the key) relation?
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.
@shankarseal : Could you please help clarify the discussed suggestion for the value_size?
For static initialization of hash-of-maps,
- Add key_size == sizeof(int) or sizeof(long) (so, it is only 4 bytes allowed).
- value_size == ???
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.
With the suggested change of key_size == sizeof(int), adding value into the inner map array is failing. Hence the suggestion does not work.
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.
If the key size is x, there can be at most 2^8x entries in the map which must be checked.
Also, it is not enough to only check the length of the key; but the type should be an integer. Not sure if/how that can be verified here.
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.
If bpf2c has that info (from parsing btf data), I think we need to change bpf2c to add that information in native driver, and then this code can check it.
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.
Static initialization of hashmap of maps is not possible unless its a BTF map.
Make change in bpf2c to fail converstion if static initialized map in maps dont use integer as key type. Similar changes need to be made for the JIT-ed case as well.
@shpalani What is the status of this PR? Has it been abandoned? If so, please close. If not, please address any comments and mark as ready for review. |
Closing this PR, as it is committed through |
Description
Testing
_Do any existing tests cover this change? No
Are new tests needed? Yes
Manual test:
Documentation
_Is there any documentation impact for this change? No
Installation
_Is there any installer impact for this change? No