BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: David Vernet <void@manifault.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Joanne Koong <joannelkoong@gmail.com>, bpf <bpf@vger.kernel.org>,
	kernel-team@meta.com, Alexei Starovoitov <ast@kernel.org>,
	Song Liu <song@kernel.org>
Subject: Re: bpf helpers freeze. Was: [PATCH v2 bpf-next 0/6] Dynptr convenience helpers
Date: Wed, 4 Jan 2023 16:13:19 -0800	[thread overview]
Message-ID: <5cde0738-67d3-ca70-d025-cbd1769b0900@linux.dev> (raw)
In-Reply-To: <20230104193735.ji4fa5imvjvnhrqf@macbook-pro-6.dhcp.thefacebook.com>

On 1/4/23 11:37 AM, Alexei Starovoitov wrote:
> Would you invest in developing application against unstable syscall API? Absolutely.
> People develop all tons of stuff on top of fuse-fs. People develop apps that interact
> with tracing bpf progs that are clearly unstable. They do suffer when kernel side
> changes and people accept that cost. BPF and tracing in general contributed to that mind change.
> In a datacenter quite a few user apps are tied to kernel internals.
> 
>> Imho, it's one of BPF's strengths and
>> we should keep the door open, not close it.
> The strength of BPF was and still is that it has both stable and unstable interfaces.
> Roughly: networking is stable, tracing is unstable.
> The point is that to be stable one doesn't need to use helpers.
> We can make kfuncs stable too if we focus all our efforts this way and
> for that we need to abandon adding helpers though it's a pain short term.
> 
>>>> to actual BPF helpers by then where we go and say, that kfunc has proven itself in production
>>>> and from an API PoV that it is ready to be a proper BPF helper, and until this point
>>> "Proper BPF helper" model is broken.
>>> static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *) 1;
>>>
>>> is a hack that works only when compiler optimizes the code.
>>> See gcc's attr(kernel_helper) workaround.
>>> This 'proper helper' hack is the reason we cannot compile bpf programs with -O0.
>>> And because it's uapi we cannot even fix this
>>> With kfuncs we will be able to compile with -O0 and debug bpf programs with better tools.
>>> These tools don't exist yet, but we have a way forward whereas with helpers
>>> we are stuck with -O2.
>> Better debugging tools are needed either way, independent of -O0 or -O2. I don't
>> think -O0 is a requirement or barrier for that. It may open up possibilities for
>> new tools, but production is still running with -O2. Proper BPF helper model is
>> broken, but everyone relies on it, and will be for a very very long time to come,
>> whether we like it or not. There is a larger ecosystem around BPF devs outside of
>> kernel, and developers will use the existing means today. There are recommendations /
>> guidelines that we can provide but we also don't have control over what developers
>> are doing. Yet we should make their life easier, not harder.
> Fully fleshed out kfunc infra will make developers job easier. No one is advocating
> to make users suffer.

It is a long discussion. I am replying on a thread with points that I have also 
been thinking about kfunc and helper.

I think bpf helper is a kernel function but helpers need to be defined in a more 
tedious form. It requires to define bpf_func_proto and then wrap into 
BPF_CALL_x. It was not obvious for me to get around to understand the reason 
behind it. With kfunc, it is a more natural way for other kernel developers to 
expose subsystem features to bpf prog. In time, I believe we will be able to 
make kfunc has a similar experience as EXPORT_SYMBOL_*.

Thus, for subsystem (hid, fuse, netdev...etc) exposing functions to bpf prog, I 
think it makes sense to stay with kfunc from now on. The subsystem is not 
exposing something like syscall as an uapi. bpf prog is part of the kernel in 
the sense that it extends that subsystem code. I don't think bpf needs to 
provide extra and more guarantee than the EXPORT_SYMBOL_* in term of api. That 
said, we should still review kfunc in a way that ensuring it is competent to the 
best of our knowledge at that point with the limited initial use cases at hand. 
I won't be surprised some of the existing EXPORT_SYMBOL_* kernel functions will 
be exposed to the bpf prog as kfunc as-is without any change in the future. For 
example, a few tcp cc kfuncs such as tcp_slow_start. They are likely stable 
without much change for a long time. It can be directly exposed as bpf kfunc. 
kfunc is a way to expose subsystem function without needing the bpf_func_proto 
and BPF_CALL_x quirks. When the function can be dual compiled later, the kfunc 
can also be inlined.

If kfunc will be used for subsystem, it is very likely the number of kfunc will 
grow and exceed the bpf helpers soon.  This seems to be a stronger need to work 
on the user experience problems about kfunc that have mentioned in this thread 
sooner than later. They have to be solved regardless. May be start with stable 
kfunc first. If the new helper is guaranteed stable, then why it cannot be kfunc 
but instead needs to go through the bpf_func_proto and BPF_CALL_x?  In time, I 
hope the bpf helper support in the verifier can be quieted down (eg. 
check_helper_call vs check_kfunc_call) and focus energy into kfunc like inlining 
kfunc...etc.

  reply	other threads:[~2023-01-05  0:14 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07 20:55 [PATCH v2 bpf-next 0/6] Dynptr convenience helpers Joanne Koong
2022-12-07 20:55 ` [PATCH v2 bpf-next 1/6] bpf: Add bpf_dynptr_trim and bpf_dynptr_advance Joanne Koong
2022-12-07 20:55 ` [PATCH v2 bpf-next 2/6] bpf: Add bpf_dynptr_is_null and bpf_dynptr_is_rdonly Joanne Koong
2022-12-07 20:55 ` [PATCH v2 bpf-next 3/6] bpf: Add bpf_dynptr_get_size and bpf_dynptr_get_offset Joanne Koong
2022-12-07 20:55 ` [PATCH v2 bpf-next 4/6] bpf: Add bpf_dynptr_clone Joanne Koong
2022-12-07 20:55 ` [PATCH v2 bpf-next 5/6] bpf: Add bpf_dynptr_iterator Joanne Koong
2022-12-07 20:55 ` [PATCH v2 bpf-next 6/6] selftests/bpf: Tests for dynptr convenience helpers Joanne Koong
2022-12-08  1:54 ` [PATCH v2 bpf-next 0/6] Dynptr " Alexei Starovoitov
2022-12-09  0:42   ` Andrii Nakryiko
2022-12-09  1:30     ` Alexei Starovoitov
2022-12-09 22:24       ` Joanne Koong
2022-12-12 20:12       ` Andrii Nakryiko
2022-12-13 23:50         ` Joanne Koong
2022-12-14  0:57           ` Andrii Nakryiko
2022-12-14 21:25             ` Joanne Koong
2022-12-16 17:35         ` Alexei Starovoitov
2022-12-20 19:31           ` Andrii Nakryiko
2022-12-25 21:52             ` bpf helpers freeze. Was: " Alexei Starovoitov
2022-12-29 23:10               ` Andrii Nakryiko
2022-12-30  2:46                 ` Alexei Starovoitov
2022-12-30 18:38                   ` David Vernet
2022-12-30 19:31                     ` Alexei Starovoitov
2022-12-30 21:00                       ` David Vernet
2022-12-31  0:42                         ` Alexei Starovoitov
2023-01-03 11:43                           ` Daniel Borkmann
2023-01-03 23:51                             ` Alexei Starovoitov
2023-01-04 14:25                               ` Daniel Borkmann
2023-01-04 18:59                                 ` Andrii Nakryiko
2023-01-04 20:03                                   ` Alexei Starovoitov
2023-01-04 21:57                                     ` Andrii Nakryiko
2023-01-04 19:37                                 ` Alexei Starovoitov
2023-01-05  0:13                                   ` Martin KaFai Lau [this message]
2023-01-05 17:17                                     ` KP Singh
2023-01-05 21:03                                       ` Andrii Nakryiko
2023-01-06  1:32                                         ` KP Singh
2023-01-05 21:02                                     ` Andrii Nakryiko
2023-01-04 20:50                                 ` David Vernet
2023-01-11 22:56                               ` Maxim Mikityanskiy
2023-01-12  4:48                                 ` Alexei Starovoitov
2023-01-13  9:48                                   ` Jose E. Marchesi
2023-01-13 16:35                                     ` Alexei Starovoitov
2023-01-04  0:55                           ` Jakub Kicinski
2023-01-04 18:44                           ` Andrii Nakryiko
2023-01-04 19:56                             ` Alexei Starovoitov
2023-01-04 18:43                         ` Andrii Nakryiko
2023-01-04 19:51                           ` Alexei Starovoitov
2023-01-04 21:56                             ` Andrii Nakryiko
2023-01-04 18:43                   ` Andrii Nakryiko
2023-01-04 19:44                     ` Alexei Starovoitov
2023-01-04 21:55                       ` Andrii Nakryiko
2023-01-04 23:47                         ` David Vernet
2023-01-05 21:01                           ` Andrii Nakryiko
2023-01-06  2:54                             ` Alexei Starovoitov
2023-01-09 17:46                               ` Andrii Nakryiko
2023-01-11 21:29                                 ` Song Liu
2023-01-12  4:23                                   ` Alexei Starovoitov
2023-01-12  7:35                                     ` Song Liu

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=5cde0738-67d3-ca70-d025-cbd1769b0900@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=joannelkoong@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=song@kernel.org \
    --cc=void@manifault.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