Skip to content

Mark inner map template descriptors in EbpfMapDescriptor#1069

Merged
elazarg merged 5 commits intovbpf:mainfrom
saxena-anurag:user/anusa/add_inner_map_template
Apr 19, 2026
Merged

Mark inner map template descriptors in EbpfMapDescriptor#1069
elazarg merged 5 commits intovbpf:mainfrom
saxena-anurag:user/anusa/add_inner_map_template

Conversation

@saxena-anurag
Copy link
Copy Markdown
Contributor

@saxena-anurag saxena-anurag commented Apr 14, 2026

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_template flag to EbpfMapDescriptor so 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

  1. type_descriptors.hpp: Added bool is_inner_map_template{false} to EbpfMapDescriptor.
  2. elf_map_parser.cpp: Added mark_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's inner_map_fd. Called from all code paths in extract_global_data()

Testing

  1. Existing tests pass (tests.exe).
  2. No behavioral change to the verifier — is_inner_map_template is not used for analysis correctness, only as metadata for downstream consumers.

Signed-off-by: Anurag Saxena <anusa@microsoft.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f6e3fbca-b986-48cc-ada2-d2c83bc26c39

📥 Commits

Reviewing files that changed from the base of the PR and between 218115b and 1ae0ed3.

📒 Files selected for processing (1)
  • src/io/elf_map_parser.cpp

📝 Walkthrough

Walkthrough

Adds is_inner_map_template to EbpfMapDescriptor and refactors extract_global_data(...) to always build an ElfGlobalData (via an IIFE), prefer BTF parsing with a fallback to map-section parsing on UnmarshalError, then unconditionally mark inner-map template descriptors in a post-processing pass.

Changes

Cohort / File(s) Summary
Type descriptor
src/spec/type_descriptors.hpp
Added bool is_inner_map_template{false}; to EbpfMapDescriptor.
ELF map parser
src/io/elf_map_parser.cpp
Refactored extract_global_data(...) to construct ElfGlobalData via an immediately-invoked lambda with new parsing selection (prefer BTF, fallback to map sections on UnmarshalError, otherwise choose map sections or create maps). Added an anonymous helper/pass that iterates global.map_descriptors and sets is_inner_map_template = true for descriptors whose original_fd matches another descriptor's inner_map_fd (when inner_map_fd != DEFAULT_MAP_FD). Replaced early returns with unified post-processing.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main objective: adding an is_inner_map_template flag to EbpfMapDescriptor to mark inner map template descriptors.
Description check ✅ Passed The description clearly explains the problem, solution, and changes made, directly relating to the code modifications in the pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@saxena-anurag saxena-anurag marked this pull request as ready for review April 14, 2026 16:09
@saxena-anurag
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between daceb4f and 7227fbb.

📒 Files selected for processing (2)
  • src/io/elf_map_parser.cpp
  • src/spec/type_descriptors.hpp

Comment thread src/io/elf_map_parser.cpp Outdated
Comment thread src/spec/type_descriptors.hpp Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Comment thread src/io/elf_map_parser.cpp Outdated
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>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/io/elf_map_parser.cpp (1)

297-307: 🧹 Nitpick | 🔵 Trivial

Reduce 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_fd values, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 369e3a2 and 218115b.

📒 Files selected for processing (1)
  • src/io/elf_map_parser.cpp

Comment thread src/io/elf_map_parser.cpp Outdated
Signed-off-by: Anurag Saxena <anusa@microsoft.com>
@elazarg elazarg merged commit b75b4c3 into vbpf:main Apr 19, 2026
16 checks passed
@saxena-anurag saxena-anurag deleted the user/anusa/add_inner_map_template branch April 20, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants