From: Alan Maguire <alan.maguire@oracle.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, jolsa@kernel.org,
sunyucong@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
Alan Maguire <alan.maguire@oracle.com>
Subject: [RFC bpf-next 0/3] libbpf: name-based u[ret]probe attach
Date: Thu, 20 Jan 2022 11:42:27 +0000 [thread overview]
Message-ID: <1642678950-19584-1-git-send-email-alan.maguire@oracle.com> (raw)
This patch series is a refinement of the RFC patchset [1], focusing
on support for attach by name for uprobes and uretprobes. Still
marked RFC as there are unresolved questions.
Currently attach for such probes is done by determining the offset
manually, so the aim is to try and mimic the simplicity of kprobe
attach, making use of uprobe opts to specify a name string.
uprobe attach is done by specifying a binary path, a pid (where
0 means "this process" and -1 means "all processes") and an
offset. Here a 'func_name' option is added to 'struct uprobe_opts'
and that name is searched for in symbol tables. If the binary
is a program, relative offset calcuation must be done to the
symbol address as described in [2].
Having a name allows us to support auto-attach via SEC()
specification, for example
SEC("uprobe/usr/lib64/libc.so.6/malloc")
Unresolved questions:
- the current scheme uses
u[ret]probe[/]/path/2/binary/function[+offset]
...as SEC() format for auto-attach, for example
SEC("uprobe/usr/lib64/libc.so.6/malloc")
It would be cleaner to delimit binary and function with ':'
as is done by bcc. One simple way to achieve that would be
to support section string pre-processing, where instances of
':' are replaced by a '/'; this would get us to supporting
a similar probe specification as bcc without the backward
compatibility headaches. I can't think of any valid
cases where SEC() definitions have a ':' that we would
replace with '/' in error, but I might be missing something.
- the current scheme doesn't support a raw offset address, since
it felt un-portable to encourage that, but can add this support
if needed.
- The auto-attach behaviour is to attach to all processes.
It would be good to have a way to specify the attach process
target. A few possibilities that would be compatible with
BPF skeleton support are to use the open opts (feels kind of
wrong conceptually since it's an attach-time attribute) or
to support opts with attach pid field in "struct bpf_prog_skeleton".
Latter would even allow a skeleton to attach to multiple
different processes with prog-level granularity (perhaps a union
of the various attach opts or similar?). There may be other
ways to achieve this.
Changes since RFC [1]:
- focused on uprobe entry/return, omitting USDT attach (Andrii)
- use ELF program headers in calculating relative offsets, as this
works for the case where we do not specify a process. The
previous approach relied on /proc/pid/maps so would not work
for the "all processes" case (where pid is -1).
- add support for auto-attach (patch 2)
- fix selftests to use a real library function. I didn't notice
selftests override the usleep(3) definition, so as a result of
this, the libc function wasn't being called, so usleep() should
not be used to test shared library attach. Also switch to
using libc path as the binary argument for these cases, as
specifying a shared library function name for a program is
not supported. Tests now instrument malloc/free.
- added selftest that verifies auto-attach.
[1] https://lore.kernel.org/bpf/1642004329-23514-1-git-send-email-alan.maguire@oracle.com/
[2] https://www.kernel.org/doc/html/latest/trace/uprobetracer.html
Alan Maguire (3):
libbpf: support function name-based attach for uprobes
libbpf: add auto-attach for uprobes based on section name
selftests/bpf: add tests for u[ret]probe attach by name
tools/lib/bpf/libbpf.c | 259 ++++++++++++++++++++-
tools/lib/bpf/libbpf.h | 10 +-
.../selftests/bpf/prog_tests/attach_probe.c | 114 +++++++--
.../selftests/bpf/progs/test_attach_probe.c | 33 +++
4 files changed, 396 insertions(+), 20 deletions(-)
--
1.8.3.1
next reply other threads:[~2022-01-20 11:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 11:42 Alan Maguire [this message]
2022-01-20 11:42 ` [RFC bpf-next 1/3] libbpf: support function name-based attach for uprobes Alan Maguire
2022-01-21 19:24 ` Andrii Nakryiko
2022-01-20 11:42 ` [RFC bpf-next 2/3] libbpf: add auto-attach for uprobes based on section name Alan Maguire
2022-01-21 19:33 ` Andrii Nakryiko
2022-01-20 11:42 ` [RFC bpf-next 3/3] selftests/bpf: add tests for u[ret]probe attach by name Alan Maguire
2022-01-21 19:40 ` Andrii Nakryiko
2022-01-21 1:44 ` [RFC bpf-next 0/3] libbpf: name-based u[ret]probe attach Alexei Starovoitov
2022-01-21 18:15 ` Andrii Nakryiko
2022-01-21 18:20 ` Alexei Starovoitov
2022-01-21 18:27 ` Andrii Nakryiko
2022-01-24 14:13 ` Alan Maguire
2022-01-24 22:47 ` Andrii Nakryiko
2022-01-27 22:54 ` Alan Maguire
2022-01-21 18:31 ` Andrii Nakryiko
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=1642678950-19584-1-git-send-email-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=sunyucong@gmail.com \
--cc=yhs@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;
as well as URLs for NNTP newsgroup(s).