-
Notifications
You must be signed in to change notification settings - Fork 101
feat: add support for uprobe_multi link #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9effc2a to
052ab74
Compare
212413a to
bf641e7
Compare
5ed33df to
276caf5
Compare
|
@maxgio92 Tks for this great contribution. We'll get into it soon. |
|
Thank you @geyslan! |
Perhaps due to the double definition in vmlinux.h? LMK. |
fe675c2 to
26f12b4
Compare
|
My bad @geyslan, I fixed the declarations, thanks. May I ask you a check and possibly a review? |
2ccb0bf to
4d79b3f
Compare
Of course! I'll do it as soon as I have a free slot. And thanks again for your contribution! @yanivagman FYI. |
|
I'll get here soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for multi uprobe and uretprobe attach via a new uprobe_multi link, simplifying the API compared to using individual perf events. Key changes include new methods in the BPFProg API, updated BPF C helper and binding functions, and associated selftests in Go, C, shell script, and Makefile.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| selftest/uprobe-multi/test.go | Added Go selftest exercising multiple probe attachments |
| selftest/uprobe-multi/test.c | Added C selftest for uprobe multi functionality |
| selftest/uprobe-multi/run.sh | Shell script to automate selftests |
| selftest/uprobe-multi/main.go | Main selftest implementation using multi uprobes |
| selftest/uprobe-multi/main.bpf.c | BPF C code for ring buffer event notifications |
| prog.go | New API additions for multi uprobe attach |
| libbpfgo.h & libbpfgo.c | Bindings for the new uprobe_multi attach helper |
| Makefile and go.mod | Build and dependency updates for the new functionality |
| selftest/common/vmlinux.h | Minor adjustments to support the new BPF changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
83943a9 to
f4b1692
Compare
f4b1692 to
a111cd1
Compare
|
Hi @geyslan, thank you so much. I've addressed all the points. |
| // func_pattern argument to libbpf bpf_program__attach_uprobe_multi() which accepts a regular expression | ||
| // to specify functions to attach BPF program to, is currently not supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this it's not available yet, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. We do only in the cgo API as decided to simplify its introduction next - considering the fix
This patch introduces support for multi uprobe attach
via uprobe_multi link [1], to support attach of multiple
uprobes and usdt probes without involving perf events.
Normal uprobe is attached through the perf event and
attaching many uprobes generates one perf event each.
New BPFProg.AttachUprobeMulti and BPFProg.AttachURetprobeMulti
methods are available from this patch, which are
astractions over the libbpf bpf_program__attach_uprobe_multi
helper, to attach uprobes and uretprobes respectively.
Moreover, the API is simplified over the
bpf_program__attach_uprobe_multi, by abstracting the
bpf_uprobe_multi_opts API. Following the libbpf API, only the second set
of inputs of the libbpf API is supported now, that is, mentioning
libbpf:
bpf_program__attach_uprobe_multi() attaches a BPF program to multiple
uprobes with uprobe_multi link.
User can specify 2 mutually exclusive set of inputs:
1) use only path/func_pattern/pid arguments
2) use path/pid with allowed combinations of
syms/offsets/ref_ctr_offsets/cookies/cnt
The Go binding API indeed supports the path and offsets set of inputs,
in a similar fashion the BPFProg.AttachUprobe and
BPFProg.AttachUretprobe provide.
[1]
https://lore.kernel.org/bpf/[email protected]/
Signed-off-by: Massimiliano Giovagnoli <[email protected]>
This commit updates the vmlinux.h header to support intel fred into the stack and data segment registers. Signed-off-by: Massimiliano Giovagnoli <[email protected]>
7611df3 to
7f58ebb
Compare
|
Everything has been addressed @geyslan. Thanks for your patience :-) |
|
No worries. The missing API can be handled next. Thanks again for this new feature. 🚀 |
|
Right. |
Indeed. Shame on me. |
| struct bpf_uprobe_multi_opts opts = {}; | ||
| opts.sz = sizeof(opts); | ||
| opts.offsets = offsets; | ||
| opts.cookies = cookies; | ||
| opts.cnt = cnt; | ||
| opts.retprobe = retprobe; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for the future: Currently, bpf_uprobe_multi_opts is only used by bpf_program__attach_uprobe_multi. If this changes, it may be better to manage it with dedicated _new() and _free() handlers.
|
No problem @geyslan at all. I've just added a facade to |
|
Maybe just placing the Min in the test file or even its logic replacing min would be simpler. WDYT? P.S.: I used min to not pollute logs. |
|
@geyslan What about just removing it? The value this debug brings is not worth it IMO. I mean: diff --git a/selftest/uprobe-multi/main.go b/selftest/uprobe-multi/main.go
index 61fa1a7..eafcbdc 100644
--- a/selftest/uprobe-multi/main.go
+++ b/selftest/uprobe-multi/main.go
@@ -192,10 +192,6 @@ func getFunSyms(name string) ([]elf.Symbol, error) {
return nil, err
}
log.Printf("found %d symbols in %s\n", len(syms), name)
- log.Printf("showing first %d symbols\n", utils.Min(10, len(syms)))
- for i := 0; i < utils.Min(10, len(syms)); i++ {
- log.Printf("symbol %d: %v\n", i, syms[i])
- }
for _, sym := range syms {
// Exclude non-function symbols.
if elf.ST_TYPE(sym.Info) != elf.STT_FUNC {In the meantime, I've simplified the backward compatible |
Signed-off-by: Massimiliano Giovagnoli <[email protected]>
deb7220 to
925afa4
Compare
|
Thank you so much @geyslan ! |
This patch introduces support for multi uprobe attach via uprobe_multi link [1], to support attach of multiple uprobes and usdt probes without involving perf events. Normal uprobe is attached through the perf event and attaching many uprobes generates one perf event each.
New BPFProg.AttachUprobeMulti and BPFProg.AttachURetprobeMulti methods are available from this patch, which are
astractions over the libbpf bpf_program__attach_uprobe_multi helper, to attach uprobes and uretprobes respectively.
Moreover, the API is simplified over the bpf_program__attach_uprobe_multi, by abstracting the bpf_uprobe_multi_opts API. Following the libbpf API, only the second set of inputs of the libbpf API is supported now, that is, mentioning libbpf:
bpf_program__attach_uprobe_multi() attaches a BPF program to multiple
uprobes with uprobe_multi link.
User can specify 2 mutually exclusive set of inputs:
use only path/func_pattern/pid arguments
use path/pid with allowed combinations of
syms/offsets/ref_ctr_offsets/cookies/cnt
The Go binding API indeed supports the path and offsets set of inputs, in a similar fashion the BPFProg.AttachUprobe and
BPFProg.AttachUretprobe provide.
[1]
https://lore.kernel.org/bpf/[email protected]/