Skip to content
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

Implement HashOfMaps and ArrayOfMaps #70

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dave-tucker
Copy link
Member

@dave-tucker dave-tucker commented Oct 18, 2021

This PR adds user and kernel space implementations of HashOfMaps and ArrayOfMaps.


This change is Reviewable

@alessandrod
Copy link
Collaborator

Thanks for taking this up!

I only skimmed through the changes. The user space side looks ok, the ebpf side I think should probably be a bit different. Right now maps of maps return an integer from get() (which is presumably a map id). I think they should return typed maps, eg:

#[map]
static mut OUTER: ArrayOfMaps<HashMap<X, Y>> = ...

fn some_probe(...) -> Result {
    let inner_map: HashMap<X, Y> = unsafe { OUTER.get(0).ok_or(())? };
    inner_map.insert(x_value, y_value);
    ...
}

This will also require adding some kind of from_id(u32) method to all maps, and we'll have to refactor maps to remove the assumption that we always have a bpf_map_def in self.def.

@dave-tucker dave-tucker added aya This is about aya (userspace) aya-bpf This is about aya-bpf (kernel) feature A PR that implements a new feature or enhancement labels Jan 10, 2022
@jeromegn
Copy link

This is of interest to us!

@dave-tucker
Copy link
Member Author

@jeromegn awesome! i'll get back to this after #127... and probably after #151 since may as well handle internal changes to fetching internal maps/programs by id together...

@alessandrod I haven't looked into the kernel side yet, but are all maps in the array/hashmap constrained to being of the same type? if not, it won't be possible to return a strongly typed wrapper....

@kakkoyun
Copy link

@dave-tucker Any interest in continuing on this?
We actually need it and are happy to contribute.

I haven't looked into the kernel side yet, but are all maps in the array/hashmap constrained to being of the same type? if not, it won't be possible to return a strongly typed wrapper....

If I'm not mistaken, all the values are the same for the map of maps. They're refs u32.

@astoycos
Copy link
Member

I'd like to take a stab at getting this up to day/ finishing if need be! WDYT @dave-tucker?

@mergify
Copy link

mergify bot commented Sep 14, 2023

@dave-tucker, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Sep 14, 2023
Copy link

mergify bot commented Feb 6, 2024

@dave-tucker, this pull request is now in conflict and requires a rebase.

@kckeiks
Copy link

kckeiks commented Feb 29, 2024

Our project could use this feature. Any updates? Glad to lend a hand in finishing this up if needed.

@alessandrod
Copy link
Collaborator

Our project could use this feature. Any updates? Glad to lend a hand in finishing this up if needed.

I've needed this too recently so I'd like to get it landed. We've changed the implementation of maps so the code in this PR needs to be updated. Getting it to compile/work would be a good first step I guess?

Copy link

mergify bot commented Jan 1, 2025

@dave-tucker, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Jan 1, 2025
@mergify mergify bot added aya-obj Relating to the aya-obj crate test A PR that improves test cases or CI and removed needs-rebase labels Jan 31, 2025
This adds a new API to test whether a given program type is supported.

This is to support 3 usecases:

1. A project like bpfman (which uses Aya) may wish to prevent users with
   a list of program types that are supported on the target system
2. A user of Aya may wish to test whether Fentry/Fexit programs are
   supported and code their own behaviour to fallback to Kprobes
3. Our own integration tests can be made to skip certain program tests
   when kernel features are missing.

Signed-off-by: Dave Tucker <[email protected]>
Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for aya-rs-docs failed.

Name Link
🔨 Latest commit 26ec01e
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/679cd67b45eeec0008b92436

Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for aya-rs-docs failed.

Name Link
🔨 Latest commit 078c638
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/679cda5a578a4a000842077e

This commit implements the Array of Maps and Hash of Maps to eBPF.

Signed-off-by: Dave Tucker <[email protected]>
@dave-tucker
Copy link
Member Author

Still a work in progress. Remaining TODO items:

  • Add relocations for prog_array map types
  • Add code for BPF_PROG_TEST_RUN to let us simulate running programs to check return codes, which is required for 👇
  • Add integration test for prog_array map types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya This is about aya (userspace) aya-bpf This is about aya-bpf (kernel) aya-obj Relating to the aya-obj crate feature A PR that implements a new feature or enhancement test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants