Skip to content

Conversation

@saxena-anurag
Copy link
Contributor

@saxena-anurag saxena-anurag commented Sep 24, 2025

Fixes #4272

This pull request adds user reference for nested maps (BPF_MAP_TYPE_ARRAY_OF_MAPS, BPF_MAP_TYPE_HASH_OF_MAPS, BPF_MAP_TYPE_PROG_ARRAY), and removes the logic of weak references.

With this change, outer maps maintain both user and total references. User reference corresponds to references taken when the object is pinned or a handle is created. When an object is inserted in the outer map, a reference is taken on the inner object (program or map). Once the user reference of the outer map is 0, the outer map is cleaned up and references to the underlying objects are released.

The PR also removes the refcount logic for the IDs as the weak reference is no longer used.

Note: There is a follow up PR #4684 that should be merged after this PR is merged.

Testing

The PR add news tests to validate the new scenario.

Documentation

No

Installation

No

@saxena-anurag saxena-anurag changed the title [DRAFT] User/anusa/update prog array refcount logic 3 [DRAFT]: DO NOT REVIEW: Update refcount logic. Sep 26, 2025
@saxena-anurag saxena-anurag changed the title [DRAFT]: DO NOT REVIEW: Update refcount logic. Add user reference for nested maps. Sep 26, 2025
@saxena-anurag saxena-anurag marked this pull request as ready for review September 26, 2025 19:50
@Alan-Jowett Alan-Jowett requested a review from Copilot September 29, 2025 20:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds user reference counting for nested maps (BPF_MAP_TYPE_ARRAY_OF_MAPS, BPF_MAP_TYPE_HASH_OF_MAPS, BPF_MAP_TYPE_PROG_ARRAY) and removes weak reference logic. The change enables outer maps to maintain both user and total references, ensuring proper cleanup when user references reach zero.

  • Introduces user reference counting alongside existing reference counting in the object system
  • Updates nested maps to take direct references on inner objects instead of using weak ID-based references
  • Removes the ID reference counting logic that supported weak references

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libs/runtime/ebpf_object.h Adds user reference count field and function signatures for user reference tracking
libs/runtime/ebpf_object.c Implements user reference counting logic and removes ID-based reference functions
libs/execution_context/ebpf_maps.c Updates nested maps to use direct object references and adds cleanup logic for user reference zeroing
tests/end_to_end/end_to_end.cpp Adds comprehensive tests for nested map user reference behavior
tests/api_test/api_test.cpp Adds API-level tests for user reference functionality and code formatting cleanup

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@Alan-Jowett Alan-Jowett left a comment

Choose a reason for hiding this comment

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

Can we get macros for acquire user reference and acquire kernel reference?

@saxena-anurag saxena-anurag added this pull request to the merge queue Oct 2, 2025
Merged via the queue into microsoft:main with commit 32ed16d Oct 2, 2025
106 checks passed
@shankarseal shankarseal mentioned this pull request Oct 6, 2025
8 tasks
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.

PROG_ARRAY_MAP ownership semantics differ from Linux

3 participants