[rebase] feat(aya): add support for map-of-maps (HashOfMaps, ArrayOfMaps)#1564
Open
OliverGavin wants to merge 18 commits into
Open
[rebase] feat(aya): add support for map-of-maps (HashOfMaps, ArrayOfMaps)#1564OliverGavin wants to merge 18 commits into
OliverGavin wants to merge 18 commits into
Conversation
This adds support for BPF_MAP_TYPE_ARRAY_OF_MAPS and BPF_MAP_TYPE_HASH_OF_MAPS on the eBPF side. Implements: - ArrayOfMaps and HashOfMaps for legacy maps - ArrayOfMaps and HashOfMaps for BTF maps - InnerMap sealed trait to mark types usable as inner maps
Adds the `inner` attribute to specify the inner map type for map-of-maps (ArrayOfMaps and HashOfMaps). Example usage: #[map] static OUTER: ArrayOfMaps<Array<u32>, 4> = ArrayOfMaps::new(0); #[map(inner = "OUTER")] static INNER: Array<u32> = Array::with_max_entries(1, 0);
Adds userspace support for BPF_MAP_TYPE_ARRAY_OF_MAPS and BPF_MAP_TYPE_HASH_OF_MAPS. Key changes: - aya-obj: track inner map definitions and initial map FDs - aya: Array and HashMap of_maps modules with get/set/iter - aya: populate inner maps during EbpfLoader::load() - Automatic inner map creation from BTF map definitions
Tests for ArrayOfMaps and HashOfMaps: - Legacy maps with manual inner map setup - BTF maps with automatic inner map creation - Dynamic inner map allocation at runtime - Also adds prog_array tests for ProgramArray
- Add sealed InnerMap trait; set()/insert() now take &impl InnerMap instead of &MapFd for compile-time validation - Implement InnerMap for all kernel-supported inner map types, MapData, and MapFd - Add pub(crate) map_fd() to PerfEventArray and RingBuf for InnerMap impls (different field layout than other map types) - Remove fd()/map_data() from Array, HashMap; remove fd() from ArrayOfMaps, HashOfMaps - Flatten nested if in bpf.rs inner_map_fd logic - Update integration tests to pass &map instead of map.fd()
Enrich the sealed Map trait with Key and Value associated types so that map-of-maps containers can perform fused two-level lookups without intermediate struct indirection. This reduces BPF verifier state explosion in tight loops. eBPF side: - Add Key/Value to private::Map and public Map with blanket forwarding. - Introduce impl_private_map! macro to replace per-file boilerplate. - Add get_value/get_value_ptr_mut to ArrayOfMaps and HashOfMaps. Userspace side: - Restructure inner map BTF/fallback logic in bpf.rs. - Add V type parameter to ArrayOfMaps and HashOfMaps. - Refactor impl_try_from_map! with @impl internal rule and add impl_try_from_map_of_maps! for unconstrained V.
Test fused lookups on both ArrayOfMaps and HashOfMaps: userspace pre-populates inner maps, the eBPF program reads via get_value and writes via get_value_ptr_mut, then userspace verifies the results.
Replace `map_fd()` with `map_data()` on `RingBuf` and `PerfEventArray`, returning `&MapData`. Update sealed `InnerMap` impls to use `map_data().fd()`. Also clean up `of_maps` docs/tests: - remove untyped-handle wording - remove redundant type ascriptions/default type parameters - use typed literals where inference needs help (`1u32`, `&1u32`)
Remove redundant `Key`/`Value` associated types from the public `Map` trait; they resolve through the sealed `private::Map` supertrait. Drop `impl_private_map!` in favor of explicit `private::Map` impls in map modules, and simplify projections from `<T as Map>::Key` to `T::Key` (and same for `Value`).
Simplify FromMapData and InnerMap into pure marker traits, moving methods into their sealed supertraits. Rename inner_map_fd to fd and error field name to outer_name for clarity. Constrain V to InnerMap in map-of-maps TryFrom impls. Remove explicit MapData type params from of_maps tests in favor of defaults. In integration tests, rename OUTER to ARRAY_OF_MAPS, replace Array<u32, 4> with Array<TestResult, 1> for named fields, and make trigger functions const extern "C" fn.
✅ Deploy Preview for aya-rs-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
6 tasks
- Drop legacy map-of-maps support - Replace impl_create_map macro with a CreatableMap trait - Unify PerfEventArray/RingBuf into impl_from_map_data via accessor arm - Add fused lookups (get_value/get_value_ptr_mut) for BTF map-of-maps - Rename tests to btf_map_of_maps
- Rename new_legacy to new_from_params to reflect actual usage - Move CreatableMap into sealed module with public wrapper trait - Replace impl_create_map macro and 8 manual trait impls with impl_creatable_map macro
- Remove CreatableMap trait, create() is now a direct inherent method - Make lookup_inner generic over M: MapDef instead of separate K, V - Revert ArrayOfMaps test annotations to turbofish form
…r turbofish - Restore CreatableMap as a sealed trait with public wrapper and blanket impl, matching the FromMapData/InnerMap pattern - Revert type ascription on lookup_inner/lookup_inner_ptr_mut callers now that inner_map is NonNull<M>
- Defer inner map template creation in the loader until we know the outer map needs to be created - Change create_pinned_by_name to accept the inner map definition instead of a pre-created fd, creating it only when bpf_get_object fails
2196567 to
b4ed408
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continuation of #1446 (by @Brskt), rebased onto current main to resolve conflicts.
It adds BTF-only support for BPF map-of-maps (
BPF_MAP_TYPE_HASH_OF_MAPSandBPF_MAP_TYPE_ARRAY_OF_MAPS)Conflict resolution notes
bool::thenclippy fix (1 line change)Checklist
cargo +nightly fmt.You can find failing lints with
cargo xtask clippy.cargo test.cargo xtask public-api --bless.This change is