The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Song Chen <chensong_2000@126.com>, Kaitao Cheng <kaitao.cheng@linux.dev>
Cc: bpf@vger.kernel.org, martin.lau@linux.dev, ast@kernel.org,
	alexei.starovoitov@gmail.com, daniel@iogearbox.net,
	andrii@kernel.org, eddyz87@gmail.com, song@kernel.org,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] kernel/bpf/btf.c: reject to register duplicated kfunc
Date: Mon, 1 Jun 2026 09:09:47 -0700	[thread overview]
Message-ID: <3e1cf732-bb65-415e-afc0-3b54a2fb1aee@linux.dev> (raw)
In-Reply-To: <83a466d3-d715-4208-b7c8-1cdcd6d99575@126.com>



On 6/1/26 2:39 AM, Song Chen wrote:
> Hi Kaitao,
>
> 在 2026/5/25 17:18, Kaitao Cheng 写道:
>> 在 2026/5/24 16:29, Song Chen 写道:
>>> I had an ebpf program which calls a kfunc defined and
>>> implemented in one of my kernel modules, it was working
>>> fine in 6.16, but was rejected to run by libbpf in 6.19,
>>> the error message was:
>>>
>>> libbpf: extern (func ksym) 'bpf_strstr': func_proto [5]
>>> incompatible with vmlinux [94389]
>>>
>>> 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
>>> both btf_vmlinux and btf_modules list 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.
>>>
>>> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
>>> Suggested-by: Kaitao Cheng <kaitao.cheng@linux.dev>
>>> Signed-off-by: Song Chen <chensong_2000@126.com>
>>>
>>> ---
>>> changelog:
>>> v1 --- v2:
>>> libbpf has already specified which module this kfunc belongs to as
>>> ebpf code onwer's expectation, then verifier uses
>>> find_kallsyms_symbol_value to search kfunc's addr.
>>>
>>> v2 --- v3:
>>> After v2, I tried a new idea of introducing a namespace in libbpf
>>> to specify kfunc owner in an ebpf program suggested by Kaitao Cheng,
>>> please see [1]. Alex suggested to go back to report an error during
>>> kmod load on conflicting kfunc name for now. What's more, v2 only
>>> searched bpf_vmlinux, v3 also traverses btf_modules list.
>>>
>>> [1]:https://lore.kernel.org/all/CAADnVQ+jYGMjAC9aNygmhyppUO9foWN4z9cjSpwCEXAFHpRVJQ@mail.gmail.com/ 
>>>
>>> ---
>>>   kernel/bpf/btf.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
>>>   1 file changed, 43 insertions(+), 1 deletion(-)
>>>
>>
>> btf: reject to register duplicated kfunc
>>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>>> index 4872d2a6c42d..a14ad3720872 100644
>>> --- a/kernel/bpf/btf.c
>>> +++ b/kernel/bpf/btf.c
>>> @@ -8618,6 +8618,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;
>>
>> This ret variable may be unnecessary.
>>
>>> +
>>> +    if (!btf_is_module(btf))
>>> +        goto out;
>>> +
>>> +    id = btf_find_by_name_kind(bpf_get_btf_vmlinux(),
>>> +                    func_name, kind);
>>
>> It seems unnecessary to split this call across multiple lines. Also,
>> some of the continuation-line indentation elsewhere does not appear
>> to follow the kernel coding style.
>>
>>> +    if (id >= 0) {
>>> +        pr_err("kfunc %s (id: %d) is already present in vmlinux.\n",
>>> +                    func_name, id);
>>> +        ret = -EINVAL;
>>> +        goto out;
>>
>> return -EINVAL;
>>
>>> +    }
>>> +
>>> +#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);
>>
>> follow the kernel coding style
>
> I understood the rest part of your comments, but this one "follow the 
> kernel coding style", is it an indentation problem? checkpatch didn't 
> say anything about it.

See Documentation/process/coding-style.rst.

[...]


  reply	other threads:[~2026-06-01 16:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24  8:29 [PATCH v3] kernel/bpf/btf.c: reject to register duplicated kfunc Song Chen
2026-05-24  9:15 ` bot+bpf-ci
2026-05-24  9:42   ` Alexei Starovoitov
2026-05-25  7:47     ` Song Chen
2026-05-25  9:18 ` Kaitao Cheng
2026-05-29  3:01   ` Alexei Starovoitov
2026-06-01  9:23     ` Song Chen
2026-06-01  9:21   ` Song Chen
2026-06-01  9:39   ` Song Chen
2026-06-01 16:09     ` Yonghong Song [this message]
2026-06-02 11:01       ` Song Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3e1cf732-bb65-415e-afc0-3b54a2fb1aee@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chensong_2000@126.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kaitao.cheng@linux.dev \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox