[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2328886.iZASKD2KPV@7950hx>
Date: Wed, 05 Nov 2025 11:48:27 +0800
From: Menglong Dong <menglong.dong@...ux.dev>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>,
Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Menglong Dong <menglong8.dong@...il.com>,
Alexei Starovoitov <ast@...nel.org>, Jiri Olsa <jolsa@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
John Fastabend <john.fastabend@...il.com>,
Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard <eddyz87@...il.com>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>,
Matt Bobrowski <mattbobrowski@...gle.com>,
Steven Rostedt <rostedt@...dmis.org>, Masami Hiramatsu <mhiramat@...nel.org>,
Leon Hwang <leon.hwang@...ux.dev>, jiang.biao@...ux.dev,
bpf <bpf@...r.kernel.org>, LKML <linux-kernel@...r.kernel.org>,
linux-trace-kernel <linux-trace-kernel@...r.kernel.org>
Subject:
Re: [PATCH bpf-next v3 4/7] bpf,x86: add tracing session supporting for
x86_64
On 2025/11/5 10:43, Alexei Starovoitov wrote:
> On Tue, Nov 4, 2025 at 4:40 PM Andrii Nakryiko
> <andrii.nakryiko@...il.com> wrote:
> >
> > On Mon, Nov 3, 2025 at 3:29 AM Menglong Dong <menglong.dong@...ux.dev> wrote:
> > >
> > > On 2025/11/1 01:57, Alexei Starovoitov wrote:
> > > > On Thu, Oct 30, 2025 at 8:36 PM Menglong Dong <menglong8.dong@...il.com> wrote:
> > > > >
> > > > > On Fri, Oct 31, 2025 at 9:42 AM Alexei Starovoitov
> > > > > <alexei.starovoitov@...il.com> wrote:
> > > > > >
> > > > > > On Sat, Oct 25, 2025 at 8:02 PM Menglong Dong <menglong8.dong@...il.com> wrote:
> > > > > > >
> > > > > > > Add BPF_TRACE_SESSION supporting to x86_64. invoke_bpf_session_entry and
> > > > > > > invoke_bpf_session_exit is introduced for this purpose.
> > > > > > >
> > > > > > > In invoke_bpf_session_entry(), we will check if the return value of the
> > > > > > > fentry is 0, and set the corresponding session flag if not. And in
> > > > > > > invoke_bpf_session_exit(), we will check if the corresponding flag is
> > > > > > > set. If set, the fexit will be skipped.
> > > > > > >
> > > > > > > As designed, the session flags and session cookie address is stored after
> > > > > > > the return value, and the stack look like this:
> > > > > > >
> > > > > > > cookie ptr -> 8 bytes
> > > > > > > session flags -> 8 bytes
> > > > > > > return value -> 8 bytes
> > > > > > > argN -> 8 bytes
> > > > > > > ...
> > > > > > > arg1 -> 8 bytes
> > > > > > > nr_args -> 8 bytes
> >
> > Let's look at "cookie ptr", "session flags", and "nr_args". We can
> > combine all of them into a single 8 byte slot: assign each session
> > program index 0, 1, ..., Nsession. 1 bit for entry/exit flag, few bits
> > for session prog index, and few more bits for nr_args, and we still
> > will have tons of space for some other additions in the future. From
> > that session program index you can calculate cookieN address to return
> > to user.
Yeah, it should work, and I thought this way too. I didn't do it
this way, because I have to adopt the usage of "nr_args" in all the
arch, which makes this series looks complicated. We can do it this
way if we still use this solution.
> >
> > And we should look whether moving nr_args into bpf_run_ctx would
> > actually minimize amount of trampoline assembly code, as we can
> > implement a bunch of stuff in pure C. (well, BPF verifier inlining is
> > a separate thing, but it can be mostly arch-independent, right?)
If we still on this way, it worth a try.
>
> Instead of all that I have a different suggestion...
>
> how about we introduce this "session" attach type,
> but won't mess with trampoline and whole new session->nr_links.
> Instead the same prog can be added to 'fentry' list
> and 'fexit' list.
> We lose the ability to skip fexit, but I'm still not convinced
> it's necessary.
> The biggest benefit is that it will work for existing JITs and trampolines.
> No new complex asm will be necessary.
> As far as writable session_cookie ...
> let's add another 8 byte space to bpf_tramp_run_ctx
I'm OK with this approach too. In fact, the session cookie can
also be used to store the information that if skip the fexit, and
the user can do the skipping by themselves.
However, we need to implement bpf_session_is_return() to tell
if the current prog is fexit, as we attach the prog to both the
entry and exit of the target function. And it still need to be done
in the trampoline, and maybe we can reuse the nr_args for this
purpose :/
If we don't want to modify the trampoline, I think a way
is that we don't introduce tracing session, and simply add the
"session cookie", and all the fentry and fexit is able to read/write
it.
Wait a minutes......we can directly make the attach cookie writable?
Things become weird now........
> and only allow single 'fsession' prog for a given kernel function.
Maybe we don't need to limit it to give the user more choice?
For example, progA use the first 4-bytes, and progB use the
last 4-bytes. Hmm...it's a little dangerous, things may mess up
if they don't talk it over beforehand.
Thanks!
Menglong Dong
> Again to avoid changing all trampolines.
> This way the feature can be implemented purely in C and no arch
> specific changes.
> It's more limited, but doesn't sound that the use case for multiple
> fsession-s exist. All this is on/off tracing. Not something
> that will be attached 24/7.
>
>
Powered by blists - more mailing lists