mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-29 12:49:07 +08:00
libbpf: Add uprobe multi link support to bpf_program__attach_usdt
Adding support for usdt_manager_attach_usdt to use uprobe_multi link to attach to usdt probes. The uprobe_multi support is detected before the usdt program is loaded and its expected_attach_type is set accordingly. If uprobe_multi support is detected the usdt_manager_attach_usdt gathers uprobes info and calls bpf_program__attach_uprobe to create all needed uprobes. If uprobe_multi support is not detected the old behaviour stays. Also adding usdt.s program section for sleepable usdt probes. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20230809083440.3209381-18-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
60cf42249b
commit
74188c1740
13
src/libbpf.c
13
src/libbpf.c
@@ -367,6 +367,8 @@ enum sec_def_flags {
|
||||
SEC_SLEEPABLE = 8,
|
||||
/* BPF program support non-linear XDP buffer */
|
||||
SEC_XDP_FRAGS = 16,
|
||||
/* Setup proper attach type for usdt probes. */
|
||||
SEC_USDT = 32,
|
||||
};
|
||||
|
||||
struct bpf_sec_def {
|
||||
@@ -6828,6 +6830,10 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
|
||||
if (prog->type == BPF_PROG_TYPE_XDP && (def & SEC_XDP_FRAGS))
|
||||
opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
|
||||
|
||||
/* special check for usdt to use uprobe_multi link */
|
||||
if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
|
||||
prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
|
||||
|
||||
if ((def & SEC_ATTACH_BTF) && !prog->attach_btf_id) {
|
||||
int btf_obj_fd = 0, btf_type_id = 0, err;
|
||||
const char *attach_name;
|
||||
@@ -6896,7 +6902,6 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
|
||||
if (!insns || !insns_cnt)
|
||||
return -EINVAL;
|
||||
|
||||
load_attr.expected_attach_type = prog->expected_attach_type;
|
||||
if (kernel_supports(obj, FEAT_PROG_NAME))
|
||||
prog_name = prog->name;
|
||||
load_attr.attach_prog_fd = prog->attach_prog_fd;
|
||||
@@ -6932,6 +6937,9 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
|
||||
insns_cnt = prog->insns_cnt;
|
||||
}
|
||||
|
||||
/* allow prog_prepare_load_fn to change expected_attach_type */
|
||||
load_attr.expected_attach_type = prog->expected_attach_type;
|
||||
|
||||
if (obj->gen_loader) {
|
||||
bpf_gen__prog_load(obj->gen_loader, prog->type, prog->name,
|
||||
license, insns, insns_cnt, &load_attr,
|
||||
@@ -8759,7 +8767,8 @@ static const struct bpf_sec_def section_defs[] = {
|
||||
SEC_DEF("uretprobe.multi.s+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_SLEEPABLE, attach_uprobe_multi),
|
||||
SEC_DEF("ksyscall+", KPROBE, 0, SEC_NONE, attach_ksyscall),
|
||||
SEC_DEF("kretsyscall+", KPROBE, 0, SEC_NONE, attach_ksyscall),
|
||||
SEC_DEF("usdt+", KPROBE, 0, SEC_NONE, attach_usdt),
|
||||
SEC_DEF("usdt+", KPROBE, 0, SEC_USDT, attach_usdt),
|
||||
SEC_DEF("usdt.s+", KPROBE, 0, SEC_USDT | SEC_SLEEPABLE, attach_usdt),
|
||||
SEC_DEF("tc/ingress", SCHED_CLS, BPF_TCX_INGRESS, SEC_NONE), /* alias for tcx */
|
||||
SEC_DEF("tc/egress", SCHED_CLS, BPF_TCX_EGRESS, SEC_NONE), /* alias for tcx */
|
||||
SEC_DEF("tcx/ingress", SCHED_CLS, BPF_TCX_INGRESS, SEC_NONE),
|
||||
|
||||
Reference in New Issue
Block a user