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

Add Unsupported Map type #520

Merged
merged 2 commits into from
Jul 13, 2023
Merged

Add Unsupported Map type #520

merged 2 commits into from
Jul 13, 2023

Conversation

astoycos
Copy link
Member

Just because aya doesn't support working with some map types doesn't mean we should't allow them to be loaded.

Add a new Unsupported map type to facilitate this, also add a debug log to let the user know we just loaded and unsupported map type.

@netlify
Copy link

netlify bot commented Feb 10, 2023

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 17930a8
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/6492056877b1c6000860e33c
😎 Deploy Preview https://deploy-preview-520--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

aya/src/maps/mod.rs Outdated Show resolved Hide resolved
@astoycos astoycos force-pushed the unsupported-map branch 2 times, most recently from 50deb73 to 56498fe Compare February 15, 2023 03:01
@dave-tucker dave-tucker added api/needs-review Makes an API change that needs review feature A PR that implements a new feature or enhancement aya This is about aya (userspace) labels Feb 23, 2023
Copy link
Member

@dave-tucker dave-tucker left a comment

Choose a reason for hiding this comment

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

Hey @astoycos thanks for the PR!

I do think we need this BUT I also think that we need to protect users from footguns.
Therefore could we add a new option to BpfLoader called allow_unsupported_maps() that will enable this?

Then in the normal load() path we'd be able to iter the maps list and return a nice error to users if we encounter unsupported maps (and allow_unsupported_maps is not set). For example:

The map ${map name} is of type ${map_type} which is currently unsupported in Aya

@astoycos
Copy link
Member Author

Yep I agree, let me work on adding this!

@astoycos astoycos force-pushed the unsupported-map branch 4 times, most recently from 49fa4cf to 05b7744 Compare March 7, 2023 21:41
@astoycos
Copy link
Member Author

astoycos commented Mar 7, 2023

Ok I think this should do it @dave-tucker.

The way I had to re-write the parse_map function as an impl of bpfLoader in order to get access to the new allow_unsupported_maps field within it was a bit tricky....so If you want me to redo that just let me know

Also are there existing tests for these bpfLoader impl functions? I couldn't find any.

aya/src/bpf.rs Outdated Show resolved Hide resolved
@astoycos astoycos force-pushed the unsupported-map branch 2 times, most recently from 82fb951 to b03cf2c Compare March 9, 2023 18:32
Copy link
Member

@dave-tucker dave-tucker left a comment

Choose a reason for hiding this comment

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

LGTM

aya/src/bpf.rs Outdated Show resolved Hide resolved
@dave-tucker
Copy link
Member

dave-tucker commented Mar 10, 2023

@alessandrod for the API changes:

  • BpfLoader::allow_unsupported_maps()

And the functional change, which is:

  • If you attempt to load bytecode which uses an unimplemented map type, you get BpfError::UnsupportedMap. This was previously a BpfError::MapError
  • If you set BpfLoader::allow_unsupported_maps() then we allow the bytecode to be loaded anyway, even if the map can't be interacted with from the Aya code. This is to support usecases like bpfd, where we're loading code on behalf of others, but aren't interacting with their maps.

@astoycos
Copy link
Member Author

astoycos commented May 2, 2023

/assign @alessandrod

@astoycos
Copy link
Member Author

astoycos commented May 2, 2023

Shoot that won't work and I still can't assign folks here :(

Copy link
Collaborator

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

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

Thanks and sorry it took so long to review

aya/src/bpf.rs Outdated Show resolved Hide resolved
aya/src/bpf.rs Outdated
&& maps
.iter()
.filter(|(_, x)| matches!(x, Map::Unsupported(_)))
.count()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should use any

Copy link
Member Author

@astoycos astoycos Jun 20, 2023

Choose a reason for hiding this comment

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

So I ended up changing this logic a bit in order to support MapError::Unsupported { map_type: u32 }

More specifically we only search our maps if allow_unsupported_maps is set and use try_for_each to decide if the map is unsupported and build the error to return.

aya/src/bpf.rs Outdated Show resolved Hide resolved
aya/src/bpf.rs Outdated Show resolved Hide resolved
@alessandrod
Copy link
Collaborator

Shoot that won't work and I still can't assign folks here :(

Just sent you an invite

Just because aya doesn't support working with some map
types doesn't mean we should't allow them to be loaded.

Add a new `Unsupported` map type to facilitate this,

Next add a user configurable option `allow_unsupported_maps()`
which can be called against the `bpfLoader`.  Additionally
add a nice warning log message when a program is being loaded
by Aya and contains an unsupported map type.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
Move BpfError::UnsupportedMap into MapError and add a map_type field to
the error.

Update the `allow_unsupported_maps` function comment.

Update the logic to check if any unsupported maps are being used. More
specifically only search a program's maps if `allow_unsupported_maps` is
set and then use the iter function `try_for_each` with a match statement
which allows us to return the inner map type if it's unsupported.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
@alessandrod alessandrod merged commit eb60d65 into aya-rs:main Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/needs-review Makes an API change that needs review aya This is about aya (userspace) feature A PR that implements a new feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants