Register two kfunc variants in bpf_testmod that differ only in a struct pointee: int bpf_kfunc_variant(struct task_struct *p); int bpf_kfunc_variant___v2(struct file *p); Check that a declaration of each resolves to it, and that a __weak declaration with struct inode * stays unresolved. Signed-off-by: Ihor Solodrai --- .../selftests/bpf/prog_tests/verifier.c | 3 ++ .../selftests/bpf/progs/kfunc_variants.c | 32 +++++++++++++++++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 12 +++++++ .../bpf/test_kmods/bpf_testmod_kfunc.h | 3 ++ 4 files changed, 50 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/kfunc_variants.c diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c index 57ff2578a991..3684670791a8 100644 --- a/tools/testing/selftests/bpf/prog_tests/verifier.c +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c @@ -8,6 +8,7 @@ #include "cap_helpers.h" #include "sysctl_helpers.h" #include "cb_refs.skel.h" +#include "kfunc_variants.skel.h" #include "verifier_aggregate_arg.skel.h" #include "verifier_aggregate_ret.skel.h" #include "verifier_alu_range.skel.h" @@ -220,6 +221,8 @@ void test_arena_kfunc_jit(void) { RUN_TESTS(arena_kfunc_jit); } void test_cb_refs(void) { RUN_TESTS(cb_refs); } +void test_kfunc_variants(void) { RUN_TESTS(kfunc_variants); } + void test_verifier_aggregate_arg(void) { RUN_TESTS(verifier_aggregate_arg); } void test_verifier_aggregate_ret(void) { RUN_TESTS(verifier_aggregate_ret); } void test_verifier_alu_range(void) { RUN(verifier_alu_range); } diff --git a/tools/testing/selftests/bpf/progs/kfunc_variants.c b/tools/testing/selftests/bpf/progs/kfunc_variants.c new file mode 100644 index 000000000000..a9c393ea9d82 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/kfunc_variants.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include "bpf_misc.h" +#include "../test_kmods/bpf_testmod_kfunc.h" + +extern int bpf_kfunc_variant___none(struct inode *p) __weak __ksym; + +char _license[] SEC("license") = "GPL"; + +SEC("syscall") +__retval(1) +int unsuffixed_name(void *ctx) +{ + return bpf_kfunc_variant(NULL); +} + +SEC("syscall") +__retval(2) +int kernel_variant(void *ctx) +{ + return bpf_kfunc_variant___v2(NULL); +} + +SEC("syscall") +__retval(0) +int no_match(void *ctx) +{ + return bpf_ksym_exists(bpf_kfunc_variant___none); +} diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c index 1fbc0061cc24..764877cdce6e 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c @@ -1928,6 +1928,16 @@ __bpf_kfunc void bpf_kfunc_trigger_ctx_check(void) irq_work_queue(&ctx_check_irq); } +__bpf_kfunc int bpf_kfunc_variant(struct task_struct *p__nullable) +{ + return 1; +} + +__bpf_kfunc int bpf_kfunc_variant___v2(struct file *p__nullable) +{ + return 2; +} + BTF_KFUNCS_START(bpf_testmod_check_kfunc_ids) BTF_ID_FLAGS(func, bpf_testmod_test_mod_kfunc, KF_SPINLOCK_SAFE) BTF_ID_FLAGS(func, bpf_kfunc_call_test1) @@ -2019,6 +2029,8 @@ BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg_legacy, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, bpf_kfunc_implicit_arg_legacy_impl) BTF_ID_FLAGS(func, bpf_kfunc_trigger_ctx_check) +BTF_ID_FLAGS(func, bpf_kfunc_variant) +BTF_ID_FLAGS(func, bpf_kfunc_variant___v2) BTF_KFUNCS_END(bpf_testmod_check_kfunc_ids) static int bpf_testmod_ops_init(struct btf *btf) diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h index 0a7df1798603..ce579eede88d 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h @@ -381,4 +381,7 @@ void bpf_testmod_test_hardirq_fn(void); void bpf_testmod_test_softirq_fn(void); void bpf_kfunc_trigger_ctx_check(void) __ksym; +int bpf_kfunc_variant(struct task_struct *p__nullable) __ksym; +int bpf_kfunc_variant___v2(struct file *p__nullable) __ksym; + #endif /* _BPF_TESTMOD_KFUNC_H */ -- 2.56.1