libbpf: Add support to set kprobe/uprobe attach mode
authorMenglong Dong <imagedong@tencent.com>
Mon, 6 Mar 2023 06:48:31 +0000 (14:48 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 6 Mar 2023 17:38:04 +0000 (09:38 -0800)
commitf8b299bc6a0f8695d4005ecff29773c79a1d29af
tree53a17be54b077eafeb7b1075c52e52002d058334
parentfd4cb29f2a3d54ec7b4e012300321601af10bd68
libbpf: Add support to set kprobe/uprobe attach mode

By default, libbpf will attach the kprobe/uprobe BPF program in the
latest mode that supported by kernel. In this patch, we add the support
to let users manually attach kprobe/uprobe in legacy or perf mode.

There are 3 mode that supported by the kernel to attach kprobe/uprobe:

  LEGACY: create perf event in legacy way and don't use bpf_link
  PERF: create perf event with perf_event_open() and don't use bpf_link

Signed-off-by: Menglong Dong <imagedong@tencent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Biao Jiang <benbjiang@tencent.com>
Link: create perf event with perf_event_open() and use bpf_link
Link: https://lore.kernel.org/bpf/20230113093427.1666466-1-imagedong@tencent.com/
Link: https://lore.kernel.org/bpf/20230306064833.7932-2-imagedong@tencent.com
Users now can manually choose the mode with
bpf_program__attach_uprobe_opts()/bpf_program__attach_kprobe_opts().
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h