-
Notifications
You must be signed in to change notification settings - Fork 5
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
Registrating struct_ops types from modules #598
Conversation
Upstream branch: ba8ea72 |
941c750
to
160e411
Compare
Upstream branch: 0e10fd4 |
f1cb656
to
643c6cb
Compare
160e411
to
6a0ffaf
Compare
Upstream branch: 99c9991 |
643c6cb
to
953df37
Compare
6a0ffaf
to
80792ec
Compare
Upstream branch: 99c9991 |
953df37
to
2a9db91
Compare
80792ec
to
7114db8
Compare
Upstream branch: 99c9991 |
2a9db91
to
24b8dea
Compare
9caa9c3
to
5d0a354
Compare
24b8dea
to
f1c9f77
Compare
Upstream branch: 99c9991 |
f1c9f77
to
e2cf1a5
Compare
5d0a354
to
6c38f9e
Compare
Upstream branch: 44cb03f |
e2cf1a5
to
ef6ac45
Compare
b7b6ef0
to
293e027
Compare
Upstream branch: e80742d |
20dec0e
to
d4a4033
Compare
293e027
to
260b428
Compare
Move the majority of the code to bpf_struct_ops_init_one(), which can then be utilized for the initialization of newly registered dynamically allocated struct_ops types in the following patches. Signed-off-by: Kui-Feng Lee <[email protected]>
Get ready to remove bpf_struct_ops_init() in the future. By using BPF_ID_LIST, it is possible to gather type information while building instead of runtime. Signed-off-by: Kui-Feng Lee <[email protected]>
Move some of members of bpf_struct_ops to bpf_struct_ops_desc. When we introduce the new API to register new bpf_struct_ops types from modules, bpf_struct_ops may destroyed when the module is unloaded. Moving these members to bpf_struct_ops_desc make these data available even when the module is unloaded. type_id is unavailabe in bpf_struct_ops anymore. Modules should get it from the btf received by kmod's init function. Cc: [email protected] Signed-off-by: Kui-Feng Lee <[email protected]>
Maintain a registry of registered struct_ops types in the per-btf (module) struct_ops_tab. This registry allows for easy lookup of struct_ops types that are registered by a specific module. It is a preparation work for supporting kernel module struct_ops in a latter patch. Each struct_ops will be registered under its own kernel module btf and will be stored in the newly added btf->struct_ops_tab. The bpf verifier and bpf syscall (e.g. prog and map cmd) can find the struct_ops and its btf type/size/id... information from btf->struct_ops_tab. Signed-off-by: Kui-Feng Lee <[email protected]>
Once new struct_ops can be registered from modules, btf_vmlinux is not longer the only btf tht struct_ops_map would face. st_map should remember what btf it should use to get type information. Signed-off-by: Kui-Feng Lee <[email protected]>
This is a preparation for searching for struct_ops types from a specified module. BTF is always btf_vmlinux now. This patch passes a pointer of BTF to bpf_struct_ops_find_value() and bpf_struct_ops_find(). Once the new registration API of struct_ops types is used, other BTFs besides btf_vmlinux can also be passed to them. Signed-off-by: Kui-Feng Lee <[email protected]>
Every kernel module has its BTF, comprising information on types defined in the module. The BTF fd (attr->value_type_btf_obj_fd) passed from userspace helps the bpf_struct_ops to lookup type information and description of the struct_ops type, which is necessary for parsing the layout of map element values and registering maps. The descriptions are looked up by matching a type id (attr->btf_vmlinux_value_type_id) against bpf_struct_ops_desc(s) defined in a BTF. If the struct_ops type is defined in a module, the bpf_struct_ops needs to know the module BTF to lookup the bpf_struct_ops_desc. The bpf_prog includes attach_btf in aux which is passed along with the bpf_attr when loading the program. The purpose of attach_btf is to determine the btf type of attach_btf_id. The attach_btf_id is then used to identify the traced function for a trace program. In the case of struct_ops programs, it is used to identify the struct_ops type of the struct_ops object that a program is attached to. Signed-off-by: Kui-Feng Lee <[email protected]>
To ensure that a module remains accessible whenever a struct_ops object of a struct_ops type provided by the module is still in use. Signed-off-by: Kui-Feng Lee <[email protected]>
A value_type should consist of three components: refcnt, state, and data. refcnt and state has been move to struct bpf_struct_ops_common_value to make it easier to check the value type. Signed-off-by: Kui-Feng Lee <[email protected]>
Replace the static list of struct_ops types with per-btf struct_ops_tab to enable dynamic registration. Both bpf_dummy_ops and bpf_tcp_ca now utilize the registration function instead of being listed in bpf_struct_ops_types.h. Cc: [email protected] Signed-off-by: Kui-Feng Lee <[email protected]>
Locate the module BTFs for struct_ops maps and progs and pass them to the kernel. This ensures that the kernel correctly resolves type IDs from the appropriate module BTFs. For the map of a struct_ops object, the FD of the module BTF is set to bpf_map to keep a reference to the module BTF. The FD is passed to the kernel as value_type_btf_obj_fd when the struct_ops object is loaded. For a bpf_struct_ops prog, attach_btf_obj_fd of bpf_prog is the FD of a module BTF in the kernel. Signed-off-by: Kui-Feng Lee <[email protected]> Acked-by: Andrii Nakryiko <[email protected]>
The module requires the use of btf_ctx_access() to invoke bpf_tracing_btf_ctx_access() from a module. This function is valuable for implementing validation functions that ensure proper access to ctx. Signed-off-by: Kui-Feng Lee <[email protected]>
Upstream branch: e80742d |
Create a new struct_ops type called bpf_testmod_ops within the bpf_testmod module. When a struct_ops object is registered, the bpf_testmod module will invoke test_2 from the module. Signed-off-by: Kui-Feng Lee <[email protected]>
d4a4033
to
3bdc24c
Compare
260b428
to
08949e6
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=799210 expired. Closing PR. |
Pull request for series with
subject: Registrating struct_ops types from modules
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=793164