Mark inner map template descriptors in EbpfMapDescriptor#1069
Mark inner map template descriptors in EbpfMapDescriptor#1069
EbpfMapDescriptor#1069Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Changes
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/io/elf_map_parser.cpp`:
- Around line 315-317: The code repeats mark_inner_map_templates(global) in each
parse branch; instead, perform the parse (e.g., call parse_btf_section,
parse_elf_symbols, etc.) to assign the resulting "global" variable, then call
mark_inner_map_templates(global) exactly once before returning. Remove the
duplicate mark_inner_map_templates calls from each branch (the ones around
parse_btf_section and the branches noted at 322-324, 330-332, 336-338) so the
post-processing happens centrally immediately prior to the final return.
In `@src/spec/type_descriptors.hpp`:
- Around line 33-34: Update the comment for the field is_inner_map_template in
type_descriptors.hpp to clarify it means the descriptor is referenced as an
inner-map template (i.e., another descriptor points to it via inner_map_fd), not
that it is exclusively used as a template; reference mark_inner_map_templates()
and inner_map_fd in the comment to make the intended semantics explicit for
downstream consumers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: b0df8e9a-ff6f-479e-b43e-e83697864435
📒 Files selected for processing (2)
src/io/elf_map_parser.cppsrc/spec/type_descriptors.hpp
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Signed-off-by: Anurag Saxena <anusa@microsoft.com>
…m/saxena-anurag/ebpf-verifier into user/anusa/add_inner_map_template Signed-off-by: Anurag Saxena <anusa@microsoft.com>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/io/elf_map_parser.cpp (1)
297-307: 🧹 Nitpick | 🔵 TrivialReduce template-marking from quadratic to linear scan.
Line 297–Line 307 performs a nested scan over the same vector. Build a set of referenced
inner_map_fdvalues, then mark in one pass.Refactor sketch
+#include <unordered_set> ... void mark_inner_map_templates(ElfGlobalData& global) { - for (const auto& desc : global.map_descriptors) { - if (desc.inner_map_fd != DEFAULT_MAP_FD) { - for (auto& inner_desc : global.map_descriptors) { - if (inner_desc.original_fd == desc.inner_map_fd) { - inner_desc.is_inner_map_template = true; - } - } - } - } + std::unordered_set<int> referenced_inner_fds; + for (const auto& desc : global.map_descriptors) { + if (desc.inner_map_fd != DEFAULT_MAP_FD) { + referenced_inner_fds.insert(desc.inner_map_fd); + } + } + + for (auto& desc : global.map_descriptors) { + if (referenced_inner_fds.contains(desc.original_fd)) { + desc.is_inner_map_template = true; + } + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/io/elf_map_parser.cpp` around lines 297 - 307, The current mark_inner_map_templates function does a quadratic nested loop over global.map_descriptors; instead, collect all referenced inner_map_fd values (skipping DEFAULT_MAP_FD) into a hash set (e.g., std::unordered_set<int>) and then do a single linear pass over global.map_descriptors marking inner_desc.is_inner_map_template = true when inner_desc.original_fd is found in that set; use the existing symbols ElfGlobalData, map_descriptors, inner_map_fd, DEFAULT_MAP_FD, original_fd, and is_inner_map_template to locate and implement this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/io/elf_map_parser.cpp`:
- Around line 297-307: The current mark_inner_map_templates function does a
quadratic nested loop over global.map_descriptors; instead, collect all
referenced inner_map_fd values (skipping DEFAULT_MAP_FD) into a hash set (e.g.,
std::unordered_set<int>) and then do a single linear pass over
global.map_descriptors marking inner_desc.is_inner_map_template = true when
inner_desc.original_fd is found in that set; use the existing symbols
ElfGlobalData, map_descriptors, inner_map_fd, DEFAULT_MAP_FD, original_fd, and
is_inner_map_template to locate and implement this change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0aad582a-dc6a-43f0-b5ae-f748aa094b54
📒 Files selected for processing (1)
src/io/elf_map_parser.cpp
Signed-off-by: Anurag Saxena <anusa@microsoft.com>
Problem
PR #1066 added map names to `EbpfMapDescriptor. However, for HASH_OF_MAP or ARRAY_OF_MAP map types, the inner map defined in the ELF is only a structural template — at runtime, the actual inner map can be any map with a matching layout. The verifier was treating the template's ELF name as if it were the definitive name of the inner map, which is incorrect and could mislead downstream consumers.
Solution
Add an
is_inner_map_templateflag toEbpfMapDescriptorso that consumers can distinguish inner map templates from concrete maps. The name is preserved for informational purposes, but the flag signals that it should not be treated as the identity of the inner map at runtime.Summary of changes
type_descriptors.hpp: Added bool is_inner_map_template{false} toEbpfMapDescriptor.elf_map_parser.cpp: Addedmark_inner_map_templates()which iterates over all map descriptors after parsing and sets is_inner_map_template = true on any descriptor referenced by another descriptor'sinner_map_fd. Called from all code paths inextract_global_data()Testing
is_inner_map_templateis not used for analysis correctness, only as metadata for downstream consumers.