Re: [PATCH v3] kernel/bpf/btf.c: reject to register duplicated kfunc
From: bot+bpf-ci
Date: Sun May 24 2026 - 05:15:43 EST
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 17d4ab0a8206..425c9f5c64fa 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -8673,6 +8673,47 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,
> return 0;
> }
>
> +static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)
> +{
> +#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
> + struct btf_module *btf_mod, *tmp;
> +#endif
> + s32 id;
> + int ret = 0;
> +
> + if (!btf_is_module(btf))
> + goto out;
During v2 review, Alexei Starovoitov suggested a different approach: instead
of rejecting duplicate kfunc registration, he proposed allowing module kfuncs
to override kernel kfuncs, similar to livepatching. He stated: "imo that's a
more interesting use case than helping out-of-tree module to produce nicier
error" and "I'm not convinced that we should be doing it... because ^^^ is
what I think we should be doing instead."
The author requested implementation guidance on how the override mechanism
would determine which kfunc to call, but received no maintainer response.
Should this implementation be reconsidered? The current approach rejects
duplicates, but the maintainer's feedback indicated preference for an
override/livepatching mechanism instead.
Reference: https://lore.kernel.org/bpf/CAADnVQJEjhJH6+2cLJ0jM_fZ366oU3yoK1b5aMk=VgksXhJtoQ@xxxxxxxxxxxxxx/
> +
> + id = btf_find_by_name_kind(bpf_get_btf_vmlinux(),
> + func_name, kind);
> + if (id >= 0) {
> + pr_err("kfunc %s (id: %d) is already present in vmlinux.\n",
> + func_name, id);
> + ret = -EINVAL;
> + goto out;
> + }
> +
> +#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
> + mutex_lock(&btf_module_mutex);
> + list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) {
> + if (btf_mod->btf == btf)
> + continue;
> + id = btf_find_by_name_kind(btf_mod->btf,
> + func_name, kind);
> + if (id >= 0) {
> + pr_err("kfunc %s (id: %d) is already present in module %s.\n",
> + func_name, id, btf_mod->module->name);
> + ret = -EINVAL;
> + break;
> + }
> + }
> + mutex_unlock(&btf_module_mutex);
> +#endif
> +
> +out:
> + return ret;
> +}
> +
> static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags)
> {
> const struct btf_type *func;
> @@ -8686,7 +8727,8 @@ static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags)
>
> /* sanity check kfunc name */
> func_name = btf_name_by_offset(btf, func->name_off);
> - if (!func_name || !func_name[0])
> + if (!func_name || !func_name[0]
> + || btf_check_kfunc_name(btf, func_name, BTF_INFO_KIND(func->info)))
> return -EINVAL;
>
> func = btf_type_by_id(btf, func->type);
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26356787905