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

UM API to write into a ring buffer map. #3562

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shankarseal
Copy link
Collaborator

@shankarseal shankarseal commented May 21, 2024

Description

Addressess #3572.

Add a new API in eBPF API.dll to write into a ring buffer map from user mode. This API issues an IOCTL which calls bpf_ring_buffer_output function to write user specified data into the ring buffer.

Testing

Updated unit and api tests to write messages into ring buffer interleaved with events that invoke eBPF programs (which in turn write into the same ring buffer).

Documentation

No documentation impact.

Installation

No installation impact.

@@ -39,6 +39,7 @@ typedef enum _ebpf_operation_id
EBPF_OPERATION_BIND_MAP,
EBPF_OPERATION_RING_BUFFER_MAP_QUERY_BUFFER,
EBPF_OPERATION_RING_BUFFER_MAP_ASYNC_QUERY,
EBPF_OPERATION_RING_BUFFER_MAP_WRITE_DATA,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we insert new values in the middle of the list? That will change the operation IDs for the rest of the enums.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since the ebpf API will always ship in conjunction with the ebpf core.sys, why is this a problem?

ebpfapi/Source.def Show resolved Hide resolved
@dthaler

This comment was marked as resolved.

@dthaler
Copy link
Collaborator

dthaler commented May 28, 2024

Per email thread with Andrii, the correct map type is BPF_MAP_TYPE_USER_RINGBUF and the UM APIs are:

struct ring_buffer_user *
ring_buffer_user__new(int map_fd,
                      const struct ring_buffer_user_opts *opts);
void ring_buffer_user__free(struct ring_buffer_user *rb);
void *ring_buffer_user__reserve(struct ring_buffer_user *rb,
				uint32_t size);
void *ring_buffer_user__poll(struct ring_buffer_user *rb, uint32_t size,
			     int timeout_ms);
void ring_buffer_user__discard(struct ring_buffer_user *rb, void *sample);
void ring_buffer_user__submit(struct ring_buffer_user *rb, void *sample);

per https://lwn.net/Articles/907056/

@Alan-Jowett
Copy link
Member

Based on a brief examination of the BPF_MAP_TYPE_USER_RINGBUF map type, I think this will require some heavy lifting from the verifier and/or slightly different implementation in Windows.

  1. Support for passing pointers to other functions to a helper function.
  2. Dynptr support.

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.

None yet

4 participants