-
Notifications
You must be signed in to change notification settings - Fork 130
bpf: Implement mprog API on top of existing cgroup progs #8917
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
Conversation
Upstream branch: b69d441 |
8b8229f
to
4b2ad00
Compare
Upstream branch: 32c563d |
758ca27
to
9cd43c0
Compare
4b2ad00
to
13a3aab
Compare
Upstream branch: 0f2d39f |
9cd43c0
to
f4bcb75
Compare
13a3aab
to
f1ad525
Compare
Upstream branch: cf15cdc |
f4bcb75
to
98c5538
Compare
f1ad525
to
d99abbe
Compare
Upstream branch: cb4a119 |
98c5538
to
b6ef7e3
Compare
d99abbe
to
3deadef
Compare
Upstream branch: 5a8cb23 |
b6ef7e3
to
ea76308
Compare
3deadef
to
71504b4
Compare
Upstream branch: c8ce7db |
ea76308
to
7003617
Compare
71504b4
to
4861ed7
Compare
Upstream branch: 7220eab |
7003617
to
1e39891
Compare
4861ed7
to
833154b
Compare
Upstream branch: 149e0cf |
1e39891
to
969751d
Compare
833154b
to
db8d927
Compare
Upstream branch: 1cb0f56 |
fefb4d7
to
d592313
Compare
b62c574
to
7b56de2
Compare
Upstream branch: b615ce5 |
d592313
to
4cbef7a
Compare
7b56de2
to
49174bd
Compare
Upstream branch: b615ce5 |
4cbef7a
to
2ab9034
Compare
49174bd
to
f3a4188
Compare
Upstream branch: 25b6d5d |
2ab9034
to
672bc8f
Compare
f3a4188
to
f10d83e
Compare
Upstream branch: 4e2e684 |
672bc8f
to
bd0cc7e
Compare
f10d83e
to
9857a0f
Compare
Upstream branch: d90f0bc |
bd0cc7e
to
5c35a15
Compare
9857a0f
to
b93b30b
Compare
One of key items in mprog API is revision for prog list. The revision number will be increased if the prog list changed, e.g., attach, detach or replace. Add 'revisions' field to struct cgroup_bpf, representing revisions for all cgroup related attachment types. The initial revision value is set to 1, the same as kernel mprog implementations. Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Yonghong Song <[email protected]>
Current cgroup prog ordering is appending at attachment time. This is not ideal. In some cases, users want specific ordering at a particular cgroup level. To address this, the existing mprog API seems an ideal solution with supporting BPF_F_BEFORE and BPF_F_AFTER flags. But there are a few obstacles to directly use kernel mprog interface. Currently cgroup bpf progs already support prog attach/detach/replace and link-based attach/detach/replace. For example, in struct bpf_prog_array_item, the cgroup_storage field needs to be together with bpf prog. But the mprog API struct bpf_mprog_fp only has bpf_prog as the member, which makes it difficult to use kernel mprog interface. In another case, the current cgroup prog detach tries to use the same flag as in attach. This is different from mprog kernel interface which uses flags passed from user space. So to avoid modifying existing behavior, I made the following changes to support mprog API for cgroup progs: - The support is for prog list at cgroup level. Cross-level prog list (a.k.a. effective prog list) is not supported. - Previously, BPF_F_PREORDER is supported only for prog attach, now BPF_F_PREORDER is also supported by link-based attach. - For attach, BPF_F_BEFORE/BPF_F_AFTER/BPF_F_ID/BPF_F_LINK is supported similar to kernel mprog but with different implementation. - For detach and replace, use the existing implementation. - For attach, detach and replace, the revision for a particular prog list, associated with a particular attach type, will be updated by increasing count by 1. Signed-off-by: Yonghong Song <[email protected]>
Currently libbpf supports bpf_program__attach_cgroup() with signature: LIBBPF_API struct bpf_link * bpf_program__attach_cgroup(const struct bpf_program *prog, int cgroup_fd); To support mprog style attachment, additionsl fields like flags, relative_{fd,id} and expected_revision are needed. Add a new API: LIBBPF_API struct bpf_link * bpf_program__attach_cgroup_opts(const struct bpf_program *prog, int cgroup_fd, const struct bpf_cgroup_opts *opts); where bpf_cgroup_opts contains all above needed fields. Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Yonghong Song <[email protected]>
Move static inline functions id_from_prog_fd() and id_from_link_fd() from prog_tests/tc_helpers.h to test_progs.h so these two functions can be reused for later cgroup mprog selftests. Signed-off-by: Yonghong Song <[email protected]>
Two tests are added: - cgroup_mprog_opts, which mimics tc_opts.c ([1]). Both prog and link attach are tested. Some negative tests are also included. - cgroup_mprog_ordering, which actually runs the program with some mprog API flags. [1] https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/prog_tests/tc_opts.c Signed-off-by: Yonghong Song <[email protected]>
Upstream branch: 5ead949 |
5c35a15
to
510e1e5
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=963862 expired. Closing PR. |
Pull request for series with
subject: bpf: Implement mprog API on top of existing cgroup progs
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=961050