From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Xu Kuohai <xukuohai@huaweicloud.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>, KP Singh <kpsingh@kernel.org>,
Amery Hung <ameryhung@gmail.com>,
Eyal Birger <eyal.birger@gmail.com>, Rong Tao <rongtao@cestc.cn>
Subject: Re: [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF
Date: Wed, 1 Jul 2026 04:17:13 +0000 [thread overview]
Message-ID: <akSUyRNYp6hx7BK+@mail.gmail.com> (raw)
In-Reply-To: <5335390d-6627-49fb-9645-ebcce410277b@huaweicloud.com>
On 26/07/01 10:18AM, Xu Kuohai wrote:
> On 7/1/2026 6:07 AM, Alexei Starovoitov wrote:
> > On Sat Jun 27, 2026 at 3:51 PM PDT, Xu Kuohai wrote:
> > > From: Xu Kuohai <xukuohai@huawei.com>
> > >
> > > This series introduces static-defined tracing probes for BPF programs.
> > > BPF SDT (static-defined tracing) works similarly to USDT. User defines
> > > probes in the BPF source code. The probes are built into NOP instructions
> > > in the ELF. At runtime, when an observer is attached, the NOP instruction
> > > is patched to a CALL instruction to the observer prog trampoline.
> > >
> > > Unlike USDT, BPF SDT requires explicit macros to generate the function
> > > prototype BTF for each probe. This allows the verifier to validate the
> > > probe sites against the declared types, and observer programs can be
> > > attached similarly to normal tracing programs using the function prototype
> > > information.
> > >
> > > A probe with two arguments in the target program can be declared and defined
> > > like:
> > >
> > > BPF_SDT_DECLARE2(my_trace, int, int);
> > >
> > > SEC("xdp")
> > > int xdp_prog(struct xdp_md *ctx)
> > > {
> > > int len = ctx->data_end - ctx->data;
> > > int ret = XDP_DROP;
> > > ...
> > > BPF_SDT_PROBE2(my_trace, len, ret);
> > > ...
> > > }
> > >
> > > An observer would be like:
> > >
> > > SEC("bpf_sdt")
> > > int BPF_PROG(observer_prog, int len, int ret)
> > > {
> > > bpf_printk("len=%d ret=%d\n", len, ret);
> > > return 0;
> > > }
> > >
> > > The target program and probe site for the observer program should be set
> > > at load time via bpf_program__set_attach_target() manually, since program
> > > names are not unique and program IDs are allocated at runtime - there is
> > > no static way to identify the target program.
> > >
> > > For BPF_SDT_DECLARE2(my_trace, int, int) and BPF_SDT_PROBE2(my_trace, len, ret)
> > > macros, the compiler produces:
> > >
> > > [code section, e.g. xdp]
> > > goto +0 // NOP, patched to CALL at attach time
> > >
> > > [.bpf_sdt_notes section]
> > > ___sdt_jt_my_trace: // symbol marking this entry's boundary
> > > .quad 0b // 8 bytes: offset of the NOP in the code
> > > // section (resolved by the linker via
> > > // R_BPF_64_ABS64 relocation)
> > > r1 = %[arg1_reg] // 8 bytes per argument: BPF move insn
> > > // whose src_reg field encodes the BPF
> > > // register holding each probe argument
> > > r2 = %[arg2_reg]
> > >
> > > ....
> > >
> > > [.BTF section]
> > > FUNC_PROTO (int, int) -> void // from BPF_SDT_DECLARE2 stub
> > > DECL_TAG "bpf_sdt:my_trace:2" // keyed by name + nargs
> >
> > Interesting idea and encoding scheme, but I don't think we need it.
> > I'd rather see static_branch/jmp work that Anton started to be completed.
> > That would be more generic and folks that need SDT-like observability
> > inside bpf progs can instead guard their debug code with static_branches.
> > SDT equivalent would be static branch plus a call to nop function
> > which can be freplaced.
>
> Sounds like this is similar to the kernel tracepoint approach. I'll
> hold this work and recheck if a dedicated SDT-like function is still
> needed once Anton's static key work is posted.
Yes, one of the reasons for adding static branches was tracing.
I will post an updated patch set soon and cc you.
next prev parent reply other threads:[~2026-07-01 4:07 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-27 22:51 [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF Xu Kuohai
2026-06-27 20:51 ` [syzbot ci] " syzbot ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 01/12] libbpf: Prepare bpf SDT probe section for the linker Xu Kuohai
2026-06-27 17:05 ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 02/12] libbpf: Introduce bpf SDT probe macros Xu Kuohai
2026-06-27 15:01 ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 03/12] libbpf: Add bpf_sdt_notes section parser Xu Kuohai
2026-06-27 15:03 ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 04/12] bpf: Create insn_array map for bpf SDT probe Xu Kuohai
2026-06-27 15:18 ` sashiko-bot
2026-06-27 15:34 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 05/12] bpf: Collect SDT probe BTF IDs from BTF decl tags Xu Kuohai
2026-06-27 15:20 ` sashiko-bot
2026-06-27 15:34 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 06/12] bpf: Add type check for SDT probe site Xu Kuohai
2026-06-27 15:04 ` sashiko-bot
2026-06-27 15:22 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 07/12] bpf: Record probe name in SDT map Xu Kuohai
2026-06-27 15:06 ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 08/12] libbpf: Add libbpf support to load SDT observer program Xu Kuohai
2026-06-27 15:12 ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 09/12] bpf: Add kernel " Xu Kuohai
2026-06-27 15:12 ` sashiko-bot
2026-06-27 15:22 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 10/12] bpf: Support attach and detach for " Xu Kuohai
2026-06-27 17:12 ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 11/12] bpf, x86: Add JIT support SDT for probe Xu Kuohai
2026-06-27 15:13 ` sashiko-bot
2026-06-27 15:22 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 12/12] selftests/bpf: Add tests for bpf SDT probe Xu Kuohai
2026-06-27 15:25 ` sashiko-bot
2026-06-29 2:14 ` [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF Leon Hwang
2026-06-29 3:27 ` Xu Kuohai
2026-06-29 5:26 ` Leon Hwang
2026-06-29 7:51 ` Xu Kuohai
2026-06-29 10:55 ` Leon Hwang
2026-06-29 11:32 ` Xu Kuohai
2026-06-29 13:53 ` Leon Hwang
2026-06-30 1:19 ` Xu Kuohai
2026-06-30 2:14 ` Leon Hwang
2026-06-30 2:29 ` Xu Kuohai
2026-06-30 22:07 ` Alexei Starovoitov
2026-07-01 2:18 ` Xu Kuohai
2026-07-01 4:17 ` Anton Protopopov [this message]
2026-07-01 6:11 ` Xu Kuohai
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=akSUyRNYp6hx7BK+@mail.gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=eyal.birger@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=memxor@gmail.com \
--cc=rongtao@cestc.cn \
--cc=xukuohai@huaweicloud.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox