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 program loading flags #3657

Closed
wants to merge 13 commits into from

Conversation

Alan-Jowett
Copy link
Member

@Alan-Jowett Alan-Jowett commented Jun 20, 2024

Resolves: #3576

Description

This pull request primarily focuses on enhancing the eBPF extension data structures and related functionalities. The changes include the introduction of new fields, versioning of extension data structures, and modifications to improve the handling of program flags.

Key changes:

  1. Changes to eBPF extension data structures:

    • docs/eBpfExtensions.md: Added capabilities field to the struct used for specifying the attach type supported by the extension. Also, introduced versioning for the extension data structure and recommended support for version 1 as version 0 will be deprecated eventually. [1] [2] [3]
    • include/ebpf_extension.h: Introduced ebpf_extension_data_v0_t and ebpf_extension_data_v1_t to represent version 0 and version 1 of the extension data structure respectively. The version 1 structure includes additional fields for capabilities, data size, and program attach flags. [1] [2]
    • include/ebpf_windows.h: Added macros for version 1 of the eBPF extension data structures and warned about the deprecation of version 1 in a future release.
  2. Changes related to program flags:

    • include/bpf/libbpf.h, libs/api/api_internal.h, libs/api/ebpf_api.cpp, libs/api/libbpf_program.cpp, libs/execution_context/ebpf_core.c, libs/execution_context/ebpf_link.c: Added methods to query and set BPF program flags. Also, modified the ebpf_program_t struct to include a flags field. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]
  3. Changes in the ebpfapi/Source.def file:

    • Added bpf_program__flags and bpf_program__set_flags to the list of exports. [1] [2]

Testing

CI/CD

Documentation

Document new EBPF_ATTACH_CLIENT_DATA_VERSION_V1 structure.

Installation

No.

@Alan-Jowett
Copy link
Member Author

Marking as draft until failure is root caused.

@Alan-Jowett Alan-Jowett marked this pull request as ready for review June 20, 2024 22:15
mtfriesen
mtfriesen previously approved these changes Jun 21, 2024
ebpfapi/Source.def Show resolved Hide resolved
docs/eBpfExtensions.md Outdated Show resolved Hide resolved
include/ebpf_extension.h Outdated Show resolved Hide resolved
include/ebpf_windows.h Outdated Show resolved Hide resolved
libs/api/ebpf_api.cpp Show resolved Hide resolved
libs/execution_context/ebpf_link.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@dthaler dthaler left a comment

Choose a reason for hiding this comment

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

Requesting changes since docs are missing as noted in my comment, and development guide says they should be in the same PR.

mikeagun
mikeagun previously approved these changes Jun 25, 2024
include/bpf/libbpf.h Outdated Show resolved Hide resolved
@Alan-Jowett Alan-Jowett marked this pull request as draft June 27, 2024 16:02
@Alan-Jowett
Copy link
Member Author

@dthaler Would you mind taking another look at this? There were some fairly significant changes required to make this work with older extensions (XDP and some internal ones) that weren't correctly checking the version fields.

The updated model requires the attach provider to declare that they support the new version of the data structures to prevent breaking older versions that didn't.

@dthaler dthaler dismissed their stale review June 29, 2024 15:37

PR was updated

include/bpf/libbpf.h Show resolved Hide resolved
include/ebpf_extension.h Outdated Show resolved Hide resolved
libs/execution_context/ebpf_link.c Outdated Show resolved Hide resolved
libs/execution_context/ebpf_link.c Outdated Show resolved Hide resolved
netebpfext/net_ebpf_ext_bind.c Show resolved Hide resolved
dthaler
dthaler previously approved these changes Jul 10, 2024
@dthaler
Copy link
Collaborator

dthaler commented Jul 10, 2024

Tentatively approving though I have two outstanding questions that might warrant changes

Signed-off-by: Alan Jowett <[email protected]>
include/bpf/libbpf.h Outdated Show resolved Hide resolved
include/bpf/libbpf.h Outdated Show resolved Hide resolved
dthaler
dthaler previously approved these changes Jul 16, 2024
@@ -755,3 +755,19 @@ bpf_prog_test_run_opts(int prog_fd, struct bpf_test_run_opts* opts)

return 0;
}

__u32
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be __u64? and also below in set_flags?

structure size.
2. A field for capabilities was added. Currently only prog_attach_flags is used to represent if the prog_attach_flags field is set.
2. Field data_size was added to contain the size of the client data.
3. An extension defined prog_attach_flags field was added.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add some details about what does prog_attach_flags mean.

@@ -1174,6 +1174,7 @@ net_ebpf_ext_sock_addr_register_providers()
_net_ebpf_sock_addr_hook_provider_data[i].bpf_attach_type =
(bpf_attach_type_t)_net_ebpf_extension_sock_addr_bpf_attach_types[i];
_net_ebpf_sock_addr_hook_provider_data[i].link_type = BPF_LINK_TYPE_CGROUP;
_net_ebpf_sock_addr_hook_provider_data[i].capabilities.support_extension_data_v1 = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

question: how do we ensure forward compatibility in such a case? for example, if the extension claims is supports extension_data_v1, but it is deployed on a system with an older eBPF runtime, how do we prevent any crash, etc.

Copy link
Collaborator

@shankarseal shankarseal left a comment

Choose a reason for hiding this comment

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

eBPF does not use version numbers in identifiers. Why cannot _ebpf_extension_data be extended to have the new fields?

@Alan-Jowett
Copy link
Member Author

Closing in favor of #3763

auto-merge was automatically disabled August 22, 2024 15:52

Pull request was closed

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.

Add support for program loading flags
6 participants