Skip to content

Commit 2f38d36

Browse files
committed
libbpf: Fix expected_attach_type set handling in program load callback
JIRA: https://issues.redhat.com/browse/RHEL-85485 commit a400d08 Author: Tao Chen <chen.dylane@gmail.com> Date: Wed Sep 25 23:30:12 2024 +0800 libbpf: Fix expected_attach_type set handling in program load callback Referenced commit broke the logic of resetting expected_attach_type to zero for allowed program types if kernel doesn't yet support such field. We do need to overwrite and preserve expected_attach_type for multi-uprobe though, but that can be done explicitly in libbpf_prepare_prog_load(). Fixes: 5902da6 ("libbpf: Add uprobe multi link support to bpf_program__attach_usdt") Suggested-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Tao Chen <chen.dylane@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20240925153012.212866-1-chen.dylane@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Viktor Malik <vmalik@redhat.com>
1 parent 06792db commit 2f38d36

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
73527352
opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
73537353

73547354
/* special check for usdt to use uprobe_multi link */
7355-
if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
7355+
if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
7356+
/* for BPF_TRACE_UPROBE_MULTI, user might want to query expected_attach_type
7357+
* in prog, and expected_attach_type we set in kernel is from opts, so we
7358+
* update both.
7359+
*/
73567360
prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
7361+
opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
7362+
}
73577363

73587364
if ((def & SEC_ATTACH_BTF) && !prog->attach_btf_id) {
73597365
int btf_obj_fd = 0, btf_type_id = 0, err;
@@ -7443,6 +7449,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
74437449
load_attr.attach_btf_id = prog->attach_btf_id;
74447450
load_attr.kern_version = kern_version;
74457451
load_attr.prog_ifindex = prog->prog_ifindex;
7452+
load_attr.expected_attach_type = prog->expected_attach_type;
74467453

74477454
/* specify func_info/line_info only if kernel supports them */
74487455
if (obj->btf && btf__fd(obj->btf) >= 0 && kernel_supports(obj, FEAT_BTF_FUNC)) {
@@ -7474,9 +7481,6 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
74747481
insns_cnt = prog->insns_cnt;
74757482
}
74767483

7477-
/* allow prog_prepare_load_fn to change expected_attach_type */
7478-
load_attr.expected_attach_type = prog->expected_attach_type;
7479-
74807484
if (obj->gen_loader) {
74817485
bpf_gen__prog_load(obj->gen_loader, prog->type, prog->name,
74827486
license, insns, insns_cnt, &load_attr,

0 commit comments

Comments
 (0)