Skip to content

Conversation

ameryhung
Copy link
Contributor

No description provided.

@ameryhung ameryhung force-pushed the st_ops_assoc_prog branch 2 times, most recently from 62bd726 to 0975a99 Compare October 9, 2025 05:27
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. As there is no safety reason that prevents
a kernel module kfunc from accessing prog->aux, allow it by removing the
kernel BTF check.

Signed-off-by: Amery Hung <[email protected]>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 2 times, most recently from 2add806 to 3e2829c Compare October 9, 2025 22:13
@ameryhung ameryhung force-pushed the st_ops_assoc_prog branch 2 times, most recently from 4eb8431 to d311cc5 Compare October 10, 2025 03:59
Add a new BPF command BPF_STRUCT_OPS_ASSOCIATE_PROG to allow associating
a BPF program with a struct_ops. 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, the first one will be the map associated with the program. 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_STRUCT_OPS_ASSOCIATE_PROG command in
bpf() syscall.

Signed-off-by: Amery Hung <[email protected]>
Test BPF_STRUCT_OPS_ASSOCIATE_PROG 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 set of almost identical struct_ops maps and BPF
programs associated with the map. Their only difference is a 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, the test 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]>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 5 times, most recently from a4b455f to 4038f13 Compare October 12, 2025 01:33
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.

1 participant