Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 5902da6d8a52 ("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>

authored by

Tao Chen and committed by
Alexei Starovoitov
a400d08b 8b334d91

+8 -4
+8 -4
tools/lib/bpf/libbpf.c
··· 7353 7353 opts->prog_flags |= BPF_F_XDP_HAS_FRAGS; 7354 7354 7355 7355 /* special check for usdt to use uprobe_multi link */ 7356 - if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) 7356 + if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) { 7357 + /* for BPF_TRACE_UPROBE_MULTI, user might want to query expected_attach_type 7358 + * in prog, and expected_attach_type we set in kernel is from opts, so we 7359 + * update both. 7360 + */ 7357 7361 prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI; 7362 + opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI; 7363 + } 7358 7364 7359 7365 if ((def & SEC_ATTACH_BTF) && !prog->attach_btf_id) { 7360 7366 int btf_obj_fd = 0, btf_type_id = 0, err; ··· 7450 7444 load_attr.attach_btf_id = prog->attach_btf_id; 7451 7445 load_attr.kern_version = kern_version; 7452 7446 load_attr.prog_ifindex = prog->prog_ifindex; 7447 + load_attr.expected_attach_type = prog->expected_attach_type; 7453 7448 7454 7449 /* specify func_info/line_info only if kernel supports them */ 7455 7450 if (obj->btf && btf__fd(obj->btf) >= 0 && kernel_supports(obj, FEAT_BTF_FUNC)) { ··· 7481 7474 insns = prog->insns; 7482 7475 insns_cnt = prog->insns_cnt; 7483 7476 } 7484 - 7485 - /* allow prog_prepare_load_fn to change expected_attach_type */ 7486 - load_attr.expected_attach_type = prog->expected_attach_type; 7487 7477 7488 7478 if (obj->gen_loader) { 7489 7479 bpf_gen__prog_load(obj->gen_loader, prog->type, prog->name,