-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[BPF] Visit nested map array during BTF generation #150608
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
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
This whole business with boolean flags for |
llvm/lib/Target/BPF/BTFDebug.cpp
Outdated
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.
Indeed, now we have three bool parameters. Probably we should have a struct to replace these bool parameters now.
If you want I can do a follow up patch in this PR with this. Or in another. |
|
Please wait a bit. |
|
First, I think that there is no need to modify Second, I think that In both cases llvm unit tests require adjustments, kernel BPF selftests are passing, no significant changes in BPF generated for kernel BPF selftests. |
|
That is true. If in visitMapDefType() we can identify inner maps, we can just recurse visitMapDefType() itself. This should make code simpler. |
feec108 to
75e6c57
Compare
Ah nice, I thought we needed to
Agree, it's better this way, only logical difference is you don't return on llvm-project/llvm/lib/Target/BPF/BTFDebug.cpp Lines 976 to 977 in 2f2df75
|
I thought about it and concluded that it shouldn't matter with the following reasoning: for top-level or nested structures in map key/value definition the reference in debug info shouldn't be a forward declaration. Even if it happens to be somehow, old code didn't handle this situation gracefully (didn't search for corresponding definition). |
|
@mtardy , Could you please fix the following tests: Some reordering is because of my changes in patch #1? |
Fixes missing inner map struct type definitions [^1]. We should visit the type of nested array of maps like we do for global maps. We visit the derived type of the array directly in visitMapDefType. Because of the small changes in visitMapDefType, ordering of the BTF is changed, for example, the PTR for the nested maps might appear later. This explain why this patch had to update the BTF checks of the tests 'map-def-nested-array.ll', 'map-def-2.ll' and 'map-def-3.ll'. We took the opportunity to migrate the last two to use 'print_btf.py'. It ressembles commit 0d21c95 ("[BPF] Handle nested wrapper structs in BPF map definition traversal (llvm#144097)") which focused on directly nested wrapper structs. Before that patch, this ARRAY_OF_MAPS definition would lead to the BTF information include the 'missing_type' as "FWD 'missing_type' fwd_kind=struct": struct missing_type { uint64_t foo; }; struct { __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); [...] __array( values, struct { [...] __type(value, struct missing_type); }); } map SEC(".maps"); Which lead to errors while trying to load the map: libbpf: map 'outer_map.inner': can't determine value size for type [N]: -22. To solve this issue, users had to use the struct in a dummy variable or in a dummy function for the BTF to be generated correctly [^2]. [^1]: https://lore.kernel.org/netdev/[email protected]/T/#u [^2]: cilium/ebpf#1658 (reply in thread) Co-authored-by: Eduard Zingerman <[email protected]> Signed-off-by: Mahe Tardy <[email protected]>
Kernel BPF selftests passing. No change in BTF generated for kernel selftests, modulo some reorderings. Signed-off-by: Mahe Tardy <[email protected]>
75e6c57 to
f67f8ea
Compare
Ah yep I missed this indeed! This should be fixed now and I migrated the tests to use |
|
@mtardy Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Fixes missing inner map struct type definitions 1. We should visit the type of nested array of maps like we do for global maps. This patch adds a boolean to convey the information to visitTypeEntry and visitDerivedType that the pointee is a map definition and should be treated as such.
It ressembles and works with commit 0d21c95 ("[BPF] Handle nested wrapper structs in BPF map definition traversal (#144097)") which focused on directly nested wrapper structs.
Before that patch, this ARRAY_OF_MAPS definition would lead to the BTF information include the 'missing_type' as "FWD 'missing_type' fwd_kind=struct":
Which lead to errors while trying to load the map:
To solve this issue, users had to use the struct in a dummy variable or in a dummy function for the BTF to be generated correctly 2.
Footnotes
https://lore.kernel.org/netdev/[email protected]/T/#u ↩
https://github.com/cilium/ebpf/discussions/1658#discussioncomment-12491339 ↩