From: Song Chen I had an ebpf program which calls a kfunc defined and implemented in one of my kernel modules, they were working fine in 6.16, but was broken by libbpf in 6.19, the error message was: libbpf: extern (func ksym) 'bpf_strstr': func_proto [5] incompatible with vmlinux [94389] yes, the reason is there is a new added kfunc in kernel 6.19 which happens to be the same name with my kfunc. However the error message is not obvious enough to address problem immediately. Therefore, this patches searches duplicated kfunc in btf_vmlinux before a kernel module attempts to register kfuncs through register_btf_kfunc_id_set, it prints clear error message and returns error code if same name kfunc has already implemented and registered, then developer knows at the first place. Signed-off-by: Song Chen --- kernel/bpf/btf.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 0de8fc8a0e0b..1f3879fe163c 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -8498,12 +8498,23 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name, return 0; } -static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags) +static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags, + const struct module *module) { const struct btf_type *func; const char *func_name; int err; + /* check if there is any duplicated kfunc in vmlinux */ + if (module) { + func = btf_type_by_id(btf_vmlinux, func_id); + if (func) { + pr_err("kfunc %s is already present in vmlinux\n", + btf_name_by_offset(btf_vmlinux, func->name_off)); + return -EINVAL; + } + } + /* any kfunc should be FUNC -> FUNC_PROTO */ func = btf_type_by_id(btf, func_id); if (!func || !btf_type_is_func(func)) @@ -8757,7 +8768,7 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook, for (i = 0; i < kset->set->cnt; i++) { ret = btf_check_kfunc_protos(btf, btf_relocate_id(btf, kset->set->pairs[i].id), - kset->set->pairs[i].flags); + kset->set->pairs[i].flags, kset->owner); if (ret) goto err_out; } -- 2.43.0