From: Leon Hwang <hffilwlqm@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Menglong Dong <menglong8.dong@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Matt Bobrowski <mattbobrowski@google.com>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Leon Hwang <leon.hwang@linux.dev>,
jiang.biao@linux.dev, bpf <bpf@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-trace-kernel <linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v3 4/7] bpf,x86: add tracing session supporting for x86_64
Date: Mon, 3 Nov 2025 14:00:33 +0800 [thread overview]
Message-ID: <bac1bb8a-b9fb-46e5-ae96-cf963d0a337c@gmail.com> (raw)
In-Reply-To: <CAADnVQKDza_ueBFRkZS8rmUVJriynWi_0FqsZE8=VbTzQYuM4w@mail.gmail.com>
On 1/11/25 01:57, Alexei Starovoitov wrote:
> On Thu, Oct 30, 2025 at 8:36 PM Menglong Dong <menglong8.dong@gmail.com> wrote:
>>
>> On Fri, Oct 31, 2025 at 9:42 AM Alexei Starovoitov
>> <alexei.starovoitov@gmail.com> wrote:
>>>
>>> On Sat, Oct 25, 2025 at 8:02 PM Menglong Dong <menglong8.dong@gmail.com> wrote:
[...]
>>
>> Without the session cookie, it will be much easier to implement
>> in another arch. And with the hepler of AI(such as cursor), it can
>> be done easily ;)
>
> The reality is the opposite. We see plenty of AI generated garbage.
> Please stay human.
>
>>
>>> At this point I'm not sure that "symmetry with kprobe_multi_session"
>>> is justified as a reason to add all that.
>>> We don't have a kprobe_session for individual kprobes after all.
>>
>> As for my case, the tracing session can make my code much
>> simpler, as I always use the fentry+fexit to hook a function. And
>> the fexit skipping according to the return value of fentry can also
>> achieve better performance.
>
> I don't buy the argument that 'if (cond) goto skip_fexit_prog'
> in the generated trampoline is measurably faster than
> 'if (cond) return' inside the fexit program.
>
>> AFAIT, the mast usage of session cookie in kprobe is passing the
>> function arguments to the exit. For tracing, we can get the args
>> in the fexit. So the session cookie in tracing is not as important as
>> in kprobe.
>
> Since kprobe_multi was introduced, retsnoop and tetragon adopted
> it to do mass attach, and both use bpf_get_attach_cookie().
> While both don't use bpf_session_cookie().
> Searching things around I also didn't find a single real user
> of bpf_session_cookie() other than selftests/bpf and Jiri's slides :)
>
> So, doing all this work in trampoline for bpf_session_cookie()
> doesn't seem warranted, but with that doing session in trampoline
> also doesn't look useful, since the only benefit vs a pair
> of fentry/fexit is skip of fexit, which can be done already.
> Plus complexity in all JITs... so, I say, let's shelve the whole thing for now.
>
As for bpfsnoop[1], the new attach type is indeed helpful.
For example, when tracing hundreds of kernel functions with both fentry
and fexit programs on a 48-core bare-metal server, the following results
were observed:
bpfsnoop -k 'tcp_connect' --output-fgraph --limit-events 1 -D
2025/11/03 13:32:11 Tracing 586 tracees costs 10.190874525s
2025/11/03 13:32:14 bpfsnoop is exiting..
2025/11/03 13:32:45 Untracing 586 tracees costs 30.667462289s
With the new attach type, about half of the time can be saved.
For bpfsnoop, the return-value control could help avoid redundant
filtering in fexit programs, though it's not strictly necessary.
For instance, when tracing udp_rcv with both packet and argument filters:
bpfsnoop -k '(b)udp_rcv' --filter-pkt 'host 1.1.1.1 and udp src port 53'
--filter-arg 'skb->dev->ifindex == 6' -v
2025/11/03 13:52:55 Tracing(fentry) kernel function udp_rcv
2025/11/03 13:52:55 Tracing(fexit) kernel function udp_rcv
With return-value control, the filtering in fexit could be skipped.
Links:
[1] https://github.com/bpfsnoop/bpfsnoop
Thanks,
Leon
next prev parent reply other threads:[~2025-11-03 6:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-26 3:01 [PATCH bpf-next v3 0/7] bpf: tracing session supporting Menglong Dong
2025-10-26 3:01 ` [PATCH bpf-next v3 1/7] bpf: add tracing session support Menglong Dong
2025-10-26 3:01 ` [PATCH bpf-next v3 2/7] bpf: add two kfunc for TRACE_SESSION Menglong Dong
2025-10-26 4:42 ` kernel test robot
2025-10-27 2:44 ` kernel test robot
2025-10-29 2:54 ` Menglong Dong
2025-11-05 0:40 ` Andrii Nakryiko
2025-10-26 3:01 ` [PATCH bpf-next v3 3/7] bpf,x86: add ret_off to invoke_bpf() Menglong Dong
2025-10-26 3:01 ` [PATCH bpf-next v3 4/7] bpf,x86: add tracing session supporting for x86_64 Menglong Dong
2025-10-31 1:42 ` Alexei Starovoitov
2025-10-31 3:36 ` Menglong Dong
2025-10-31 17:57 ` Alexei Starovoitov
2025-11-03 6:00 ` Leon Hwang [this message]
2025-11-03 11:24 ` Menglong Dong
2025-11-05 0:40 ` Andrii Nakryiko
2025-11-05 2:43 ` Alexei Starovoitov
2025-11-05 3:48 ` Menglong Dong
2025-11-05 17:29 ` Andrii Nakryiko
2025-11-05 22:00 ` Alexei Starovoitov
2025-11-06 12:14 ` Menglong Dong
2025-11-06 17:03 ` Andrii Nakryiko
2025-10-26 3:01 ` [PATCH bpf-next v3 5/7] libbpf: add support for tracing session Menglong Dong
2025-10-26 3:01 ` [PATCH bpf-next v3 6/7] selftests/bpf: add testcases " Menglong Dong
2025-10-26 3:01 ` [PATCH bpf-next v3 7/7] selftests/bpf: test fsession mixed with fentry and fexit Menglong Dong
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=bac1bb8a-b9fb-46e5-ae96-cf963d0a337c@gmail.com \
--to=hffilwlqm@gmail.com \
--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=haoluo@google.com \
--cc=jiang.biao@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
--cc=menglong8.dong@gmail.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.