Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Add tests for KF_IMPLICIT_ARGS

Add trivial end-to-end tests to validate that KF_IMPLICIT_ARGS flag is
properly handled by both resolve_btfids and the verifier.

Declare kfuncs in bpf_testmod. Check that bpf_prog_aux pointer is set
in the kfunc implementation. Verify that calls with implicit args and
a legacy case all work.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260120222638.3976562-7-ihor.solodrai@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Ihor Solodrai and committed by
Alexei Starovoitov
e939f3d1 9d199965

+77
+10
tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ 3 + 4 + #include <test_progs.h> 5 + #include "kfunc_implicit_args.skel.h" 6 + 7 + void test_kfunc_implicit_args(void) 8 + { 9 + RUN_TESTS(kfunc_implicit_args); 10 + }
+41
tools/testing/selftests/bpf/progs/kfunc_implicit_args.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ 3 + 4 + #include <vmlinux.h> 5 + #include <bpf/bpf_helpers.h> 6 + #include "bpf_misc.h" 7 + 8 + extern int bpf_kfunc_implicit_arg(int a) __weak __ksym; 9 + extern int bpf_kfunc_implicit_arg_impl(int a, struct bpf_prog_aux *aux) __weak __ksym; /* illegal */ 10 + extern int bpf_kfunc_implicit_arg_legacy(int a, int b) __weak __ksym; 11 + extern int bpf_kfunc_implicit_arg_legacy_impl(int a, int b, struct bpf_prog_aux *aux) __weak __ksym; 12 + 13 + char _license[] SEC("license") = "GPL"; 14 + 15 + SEC("syscall") 16 + __retval(5) 17 + int test_kfunc_implicit_arg(void *ctx) 18 + { 19 + return bpf_kfunc_implicit_arg(5); 20 + } 21 + 22 + SEC("syscall") 23 + __failure __msg("cannot find address for kernel function bpf_kfunc_implicit_arg_impl") 24 + int test_kfunc_implicit_arg_impl_illegal(void *ctx) 25 + { 26 + return bpf_kfunc_implicit_arg_impl(5, NULL); 27 + } 28 + 29 + SEC("syscall") 30 + __retval(7) 31 + int test_kfunc_implicit_arg_legacy(void *ctx) 32 + { 33 + return bpf_kfunc_implicit_arg_legacy(3, 4); 34 + } 35 + 36 + SEC("syscall") 37 + __retval(11) 38 + int test_kfunc_implicit_arg_legacy_impl(void *ctx) 39 + { 40 + return bpf_kfunc_implicit_arg_legacy_impl(5, 6, NULL); 41 + }
+26
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
··· 1142 1142 __bpf_kfunc int bpf_kfunc_multi_st_ops_test_1(struct st_ops_args *args, u32 id); 1143 1143 __bpf_kfunc int bpf_kfunc_multi_st_ops_test_1_impl(struct st_ops_args *args, void *aux_prog); 1144 1144 1145 + __bpf_kfunc int bpf_kfunc_implicit_arg(int a, struct bpf_prog_aux *aux); 1146 + __bpf_kfunc int bpf_kfunc_implicit_arg_legacy(int a, int b, struct bpf_prog_aux *aux); 1147 + __bpf_kfunc int bpf_kfunc_implicit_arg_legacy_impl(int a, int b, struct bpf_prog_aux *aux); 1148 + 1145 1149 BTF_KFUNCS_START(bpf_testmod_check_kfunc_ids) 1146 1150 BTF_ID_FLAGS(func, bpf_testmod_test_mod_kfunc) 1147 1151 BTF_ID_FLAGS(func, bpf_kfunc_call_test1) ··· 1188 1184 BTF_ID_FLAGS(func, bpf_kfunc_st_ops_inc10) 1189 1185 BTF_ID_FLAGS(func, bpf_kfunc_multi_st_ops_test_1) 1190 1186 BTF_ID_FLAGS(func, bpf_kfunc_multi_st_ops_test_1_impl) 1187 + BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg, KF_IMPLICIT_ARGS) 1188 + BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg_legacy, KF_IMPLICIT_ARGS) 1189 + BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg_legacy_impl) 1191 1190 BTF_KFUNCS_END(bpf_testmod_check_kfunc_ids) 1192 1191 1193 1192 static int bpf_testmod_ops_init(struct btf *btf) ··· 1680 1673 ret = st_ops->test_1(args); 1681 1674 1682 1675 return ret; 1676 + } 1677 + 1678 + int bpf_kfunc_implicit_arg(int a, struct bpf_prog_aux *aux) 1679 + { 1680 + if (aux && a > 0) 1681 + return a; 1682 + return -EINVAL; 1683 + } 1684 + 1685 + int bpf_kfunc_implicit_arg_legacy(int a, int b, struct bpf_prog_aux *aux) 1686 + { 1687 + if (aux) 1688 + return a + b; 1689 + return -EINVAL; 1690 + } 1691 + 1692 + int bpf_kfunc_implicit_arg_legacy_impl(int a, int b, struct bpf_prog_aux *aux) 1693 + { 1694 + return bpf_kfunc_implicit_arg_legacy(a, b, aux); 1683 1695 } 1684 1696 1685 1697 static int multi_st_ops_reg(void *kdata, struct bpf_link *link)