public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>, bpf <bpf@vger.kernel.org>,
	Kernel Team <kernel-team@meta.com>
Subject: Re: [PATCH bpf-next v3 1/2] bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS
Date: Mon, 23 Mar 2026 12:58:30 -0700	[thread overview]
Message-ID: <b040711c-0fd1-475f-b807-e4e0b4324f6e@linux.dev> (raw)
In-Reply-To: <CAADnVQ+iXJK46cFcGN-Ta8KGxe7Y+m_DxgWNS=QC-gOWT=WxCw@mail.gmail.com>

On 3/21/26 1:27 PM, Alexei Starovoitov wrote:
> On Wed, Mar 18, 2026 at 4:42 PM Ihor Solodrai <ihor.solodrai@linux.dev> wrote:
>>
>>                                         const struct btf *btf,
>> @@ -12594,6 +12620,14 @@ enum special_kfunc_type {
>>         KF_bpf_session_is_return,
>>         KF_bpf_stream_vprintk,
>>         KF_bpf_stream_print_stack,
>> +       KF_bpf_obj_new,
>> +       KF_bpf_percpu_obj_new,
>> +       KF_bpf_obj_drop,
>> +       KF_bpf_percpu_obj_drop,
>> +       KF_bpf_refcount_acquire,
>> +       KF_bpf_list_push_front,
>> +       KF_bpf_list_push_back,
>> +       KF_bpf_rbtree_add,
>>  };
> 
> it's not an uapi. no need to add them to the end.
> Pls add them next to _impl flavors.
> 
> The whole thing needs a full refactor in a long term.
> special_kfunc* thingy got out of hand.

I thought about this a little and tried a couple of ideas.  Here is
one that looks a bit better to me than KF_* enum: BTF_ID_LIST_NAMED()
and BTF_ID_NAMED().

I vibe-coded a PoC [1]. Essentially, we add a set of macros to
generate source-level stable symbol for each BTF_ID_LIST entry. Then
it is possible to refer to the associated value directly by name.

It looks like this:

+#define BTF_ID_LIST_NAMED(name)                                \
+       __BTF_ID_LIST(name, local)                      \
+       extern u32 name[];
+
+#define BTF_ID_NAMED(list, prefix, name)               \
+       __BTF_ID(__BTF_ID__##prefix##__##name##__##list, "") \
+       extern u32 __btf_id_##list##__##prefix##__##name \
+               asm("__BTF_ID__" #prefix "__" #name "__" #list);
+
+#define btf_id_named(list, prefix, name) \
+       (__btf_id_##list##__##prefix##__##name)
+

And then:

+BTF_ID_LIST_NAMED(special_kfunc_list)
+BTF_ID_NAMED(special_kfunc_list, func, bpf_obj_new_impl)
+BTF_ID_NAMED(special_kfunc_list, func, bpf_obj_drop_impl)

  [...]

+#define special_kfunc_id(name) btf_id_named(special_kfunc_list, func, name)

  [...]

 static bool is_bpf_obj_new_kfunc(u32 func_id)
 {
-       return func_id == special_kfunc_list[KF_bpf_obj_new] ||
-              func_id == special_kfunc_list[KF_bpf_obj_new_impl];
+       return func_id == special_kfunc_id(bpf_obj_new) ||
+              func_id == special_kfunc_id(bpf_obj_new_impl);
 }


The benefit of this is that we can delete enum special_kfunc_type, and
there is only one list where a special kfunc has to be defined (and this
may work for other similar use cases).

The downside is additional BTF_ID macrology, and potentially changes
in resolve_btfids.

What do people think, is this worth pursuing?

[1] https://github.com/theihor/bpf/commit/be38dde0a027d7ab84d8d20ac266251fb938ceb6

> 
> pw-bot: cr


  reply	other threads:[~2026-03-23 19:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 23:42 [PATCH bpf-next v3 1/2] bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS Ihor Solodrai
2026-03-18 23:42 ` [PATCH bpf-next v3 2/2] selftests/bpf: Update kfuncs using btf_struct_meta to new variants Ihor Solodrai
2026-03-19 12:30   ` Jiri Olsa
2026-03-19 20:43     ` Ihor Solodrai
2026-03-20 11:06       ` Jiri Olsa
2026-03-20 14:50   ` Mykyta Yatsenko
2026-03-19 12:25 ` [PATCH bpf-next v3 1/2] bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS Jiri Olsa
2026-03-19 20:37   ` Ihor Solodrai
2026-03-20 15:49 ` Mykyta Yatsenko
2026-03-27  0:16   ` Ihor Solodrai
2026-03-27 19:19     ` Mykyta Yatsenko
2026-03-21 20:27 ` Alexei Starovoitov
2026-03-23 19:58   ` Ihor Solodrai [this message]
2026-03-24 17:22     ` Alexei Starovoitov
2026-03-26 19:13       ` Ihor Solodrai
2026-03-27 20:48         ` Alexei Starovoitov
2026-03-27 20:55           ` Ihor Solodrai
2026-03-27 21:00             ` Alexei Starovoitov
2026-03-27 21:08               ` Ihor Solodrai
2026-03-27 21:47                 ` Alexei Starovoitov
2026-03-27 22:06                   ` Ihor Solodrai

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=b040711c-0fd1-475f-b807-e4e0b4324f6e@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    /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