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 support for BPF_LD_MAP_FD pseudo instruction #53

Closed
wants to merge 2 commits into from

Conversation

Alan-Jowett
Copy link
Collaborator

@Alan-Jowett Alan-Jowett commented Jan 5, 2021

BPF_LD_MAP_FD pseudo instruction is a LD IMM64 with register SRC == BPF_PSEUDO_MAP_FD(1)
Behavior is to resolve the map file descriptor and replace it with the address of the map.

Add new function ubpf_register_map_resolver to allow caller to provide callback to resolve map FD to address.

Resolves #45

BPF_LD_MAP_FD pseudo instruction is a LD IMM64 with register SRC == BPF_PSEUDO_MAP_FD(1)
Behavior is to resolve the map file descriptor and replace it with the address of the map.
@coveralls
Copy link

coveralls commented Jan 5, 2021

Coverage Status

Coverage decreased (-0.7%) to 95.376% when pulling dce24c5 on Alan-Jowett:lddw_maps into 089f627 on iovisor:master.

@jpsamaroo
Copy link

This should have an interpreter implementation and some tests, including a test with one program using multiple maps. I also think that the callback should accept the ubpf_vm as first argument, so that in the future we can attach map information directly to the vm structure.

@Alan-Jowett
Copy link
Collaborator Author

Agreed about making the map resolver jitter aware. Modified both the register and the callback to accept void * context so that consumers have the choice of how to implement maps.

@Alan-Jowett
Copy link
Collaborator Author

Added tests for BPF_LD_MAP_FD pseudo instruction for both positive and negative (invalid FD) cases.

@Alan-Jowett
Copy link
Collaborator Author

Note: The goal is to allow consumer of ubpf to add support for maps by implementing the BPF syscall. This change allows the consumer to implement fd -> address mapping.

@Alan-Jowett Alan-Jowett deleted the lddw_maps branch March 17, 2021 19:18
@jpsamaroo
Copy link

Any reason why this was closed?

@Alan-Jowett
Copy link
Collaborator Author

Short version

This overlaps with functionality in another library we are using and is redundant.

Background

My team is building a runtime + execution context (environment) that permits eBPF programs to be hosted in either user mode, kernel mode or an enclave. The runtime invokes the prevail eBPF verifier to parse and verify the eBPF program. As part of verification, callbacks are made to create maps. Net result is that ubpf is agnostic of maps in this model.

Post verification, the runtime then does:

  1. Scan the eBPF byte code to extract list of helper functions and map FDs.
  2. Resolve the helper function and map addresses (via call to execution context).
  3. Replace LD_MAP_FD pseudo instructions with LDDW with the real map address.
  4. Provide helper function addresses to jitter.
  5. Loads the code into the execution environment.

Note:
Once I have it ready, there will be a smaller patch that allows makes ubpf more flexible about the environment it runs in. Likewise once we exit POC phase for the project we will be pushing it up to public github and will provide a link if you want.

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.

ubpf needs to support maps
3 participants