From: Dave Marchevsky <davemarchevsky@fb.com>
To: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: kernel-team@fb.com, Alan Maguire <alan.maguire@oracle.com>,
Hengqi Chen <hengqi.chen@gmail.com>
Subject: Re: [PATCH v3 bpf-next 1/7] libbpf: add BPF-side of USDT support
Date: Mon, 4 Apr 2022 21:05:28 -0400 [thread overview]
Message-ID: <1497128d-c44c-4ce9-3526-abf8ce61e0ae@fb.com> (raw)
In-Reply-To: <20220404234202.331384-2-andrii@kernel.org>
On 4/4/22 7:41 PM, Andrii Nakryiko wrote:
> Add BPF-side implementation of libbpf-provided USDT support. This
> consists of single header library, usdt.bpf.h, which is meant to be used
> from user's BPF-side source code. This header is added to the list of
> installed libbpf header, along bpf_helpers.h and others.
>
> BPF-side implementation consists of two BPF maps:
> - spec map, which contains "a USDT spec" which encodes information
> necessary to be able to fetch USDT arguments and other information
> (argument count, user-provided cookie value, etc) at runtime;
> - IP-to-spec-ID map, which is only used on kernels that don't support
> BPF cookie feature. It allows to lookup spec ID based on the place
> in user application that triggers USDT program.
>
> These maps have default sizes, 256 and 1024, which are chosen
> conservatively to not waste a lot of space, but handling a lot of common
> cases. But there could be cases when user application needs to either
> trace a lot of different USDTs, or USDTs are heavily inlined and their
> arguments are located in a lot of differing locations. For such cases it
> might be necessary to size those maps up, which libbpf allows to do by
> overriding BPF_USDT_MAX_SPEC_CNT and BPF_USDT_MAX_IP_CNT macros.
>
> It is an important aspect to keep in mind. Single USDT (user-space
> equivalent of kernel tracepoint) can have multiple USDT "call sites".
> That is, single logical USDT is triggered from multiple places in user
> application. This can happen due to function inlining. Each such inlined
> instance of USDT invocation can have its own unique USDT argument
> specification (instructions about the location of the value of each of
> USDT arguments). So while USDT looks very similar to usual uprobe or
> kernel tracepoint, under the hood it's actually a collection of uprobes,
> each potentially needing different spec to know how to fetch arguments.
>
> User-visible API consists of three helper functions:
> - bpf_usdt_arg_cnt(), which returns number of arguments of current USDT;
> - bpf_usdt_arg(), which reads value of specified USDT argument (by
> it's zero-indexed position) and returns it as 64-bit value;
> - bpf_usdt_cookie(), which functions like BPF cookie for USDT
> programs; this is necessary as libbpf doesn't allow specifying actual
> BPF cookie and utilizes it internally for USDT support implementation.
>
> Each bpf_usdt_xxx() APIs expect struct pt_regs * context, passed into
> BPF program. On kernels that don't support BPF cookie it is used to
> fetch absolute IP address of the underlying uprobe.
>
> usdt.bpf.h also provides BPF_USDT() macro, which functions like
> BPF_PROG() and BPF_KPROBE() and allows much more user-friendly way to
> get access to USDT arguments, if USDT definition is static and known to
> the user. It is expected that majority of use cases won't have to use
> bpf_usdt_arg_cnt() and bpf_usdt_arg() directly and BPF_USDT() will cover
> all their needs.
>
> Last, usdt.bpf.h is utilizing BPF CO-RE for one single purpose: to
> detect kernel support for BPF cookie. If BPF CO-RE dependency is
> undesirable, user application can redefine BPF_USDT_HAS_BPF_COOKIE to
> either a boolean constant (or equivalently zero and non-zero), or even
> point it to its own .rodata variable that can be specified from user's
> application user-space code. It is important that
> BPF_USDT_HAS_BPF_COOKIE is known to BPF verifier as static value (thus
> .rodata and not just .data), as otherwise BPF code will still contain
> bpf_get_attach_cookie() BPF helper call and will fail validation at
> runtime, if not dead-code eliminated.
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
Reviewed-by: Dave Marchevsky <davemarchevsky@fb.com>
next prev parent reply other threads:[~2022-04-05 2:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 23:41 [PATCH v3 bpf-next 0/7] Add libbpf support for USDTs Andrii Nakryiko
2022-04-04 23:41 ` [PATCH v3 bpf-next 1/7] libbpf: add BPF-side of USDT support Andrii Nakryiko
2022-04-05 1:05 ` Dave Marchevsky [this message]
2022-04-07 14:19 ` Ilya Leoshkevich
2022-04-07 23:27 ` Andrii Nakryiko
2022-04-04 23:41 ` [PATCH v3 bpf-next 2/7] libbpf: wire up USDT API and bpf_link integration Andrii Nakryiko
2022-04-04 23:41 ` [PATCH v3 bpf-next 3/7] libbpf: add USDT notes parsing and resolution logic Andrii Nakryiko
2022-04-04 23:41 ` [PATCH v3 bpf-next 4/7] libbpf: wire up spec management and other arch-independent USDT logic Andrii Nakryiko
2022-04-04 23:42 ` [PATCH v3 bpf-next 5/7] libbpf: add x86-specific USDT arg spec parsing logic Andrii Nakryiko
2022-04-06 17:23 ` Andrii Nakryiko
2022-04-06 22:49 ` Ilya Leoshkevich
2022-04-06 23:15 ` Andrii Nakryiko
2022-04-08 14:16 ` Alan Maguire
2022-04-08 16:17 ` Andrii Nakryiko
2022-04-04 23:42 ` [PATCH v3 bpf-next 6/7] selftests/bpf: add basic USDT selftests Andrii Nakryiko
2022-04-04 23:42 ` [PATCH v3 bpf-next 7/7] selftests/bpf: add urandom_read shared lib and USDTs Andrii Nakryiko
2022-04-05 13:23 ` [PATCH v3 bpf-next 0/7] Add libbpf support for USDTs Hengqi Chen
2022-04-05 20:30 ` patchwork-bot+netdevbpf
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=1497128d-c44c-4ce9-3526-abf8ce61e0ae@fb.com \
--to=davemarchevsky@fb.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=hengqi.chen@gmail.com \
--cc=kernel-team@fb.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