-
Notifications
You must be signed in to change notification settings - Fork 5
Support associating BPF programs with struct_ops #6160
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
Support associating BPF programs with struct_ops #6160
Conversation
|
Upstream branch: 48a97ff |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 3412832984 via email |
631bcf6 to
db45b16
Compare
|
Upstream branch: 48a97ff |
e3d6e8d to
3f91dd0
Compare
db45b16 to
cf0c057
Compare
Allow verifier to fixup kfuncs in kernel module to support kfuncs with __prog arguments. Currently, special kfuncs and kfuncs with __prog arguments are kernel kfuncs. Allowing kernel module kfuncs should not affect existing kfunc fixup as kernel module kfuncs have BTF IDs greater than kernel kfuncs' BTF IDs. Signed-off-by: Amery Hung <[email protected]>
Add a new BPF command BPF_PROG_ASSOC_STRUCT_OPS to allow associating a BPF program with a struct_ops map. This command takes a file descriptor of a struct_ops map and a BPF program and set prog->aux->st_ops_assoc to the kdata of the struct_ops map. The command does not accept a struct_ops program or a non-struct_ops map. Programs of a struct_ops map is automatically associated with the map during map update. If a program is shared between two struct_ops maps, prog->aux->st_ops_assoc will be poisoned to indicate that the associated struct_ops is ambiguous. A kernel helper bpf_prog_get_assoc_struct_ops() can be used to retrieve the pointer. The associated struct_ops map, once set, cannot be changed later. This restriction may be lifted in the future if there is a use case. Each associated programs except struct_ops programs of the map will take a refcount on the map to pin it so that prog->aux->st_ops_assoc, if set, is always valid. However, it is not guaranteed whether the map members are fully updated nor is it attached or not. For example, a BPF program can be associated with a struct_ops map before map_update. The struct_ops implementer will be responsible for maintaining and checking the state of the associated struct_ops map before accessing it. Signed-off-by: Amery Hung <[email protected]>
Add low-level wrapper API for BPF_PROG_ASSOC_STRUCT_OPS command in the bpf() syscall. Signed-off-by: Amery Hung <[email protected]>
Test BPF_PROG_ASSOC_STRUCT_OPS command that associates a BPF program with a struct_ops. The test follows the same logic in commit ba7000f ("selftests/bpf: Test multi_st_ops and calling kfuncs from different programs"), but instead of using map id to identify a specific struct_ops, this test uses the new BPF command to associate a struct_ops with a program. The test consists of two sets of almost identical struct_ops maps and BPF programs associated with the map. Their only difference is the unique value returned by bpf_testmod_multi_st_ops::test_1(). The test first loads the programs and associates them with struct_ops maps. Then, it exercises the BPF programs. They will in turn call kfunc bpf_kfunc_multi_st_ops_test_1_prog_arg() to trigger test_1() of the associated struct_ops map, and then check if the right unique value is returned. Signed-off-by: Amery Hung <[email protected]>
|
Upstream branch: 48a97ff |
3f91dd0 to
1a71fe8
Compare
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1012542 expired. Closing PR. |
Pull request for series with
subject: Support associating BPF programs with struct_ops
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1012542