libbpf: Fix expected_attach_type set when kernel not support
PATCH v4 1/1 libbpf: Fix expected_attach_type set when kernel not support
The commit "5902da6d8a52" set expected_attach_type again with field of bpf_program after libbpf_prepare_prog_load, which makes expected_attach_type = 0 no sense when kernel not support the attach_type feature, so fix it.
--- tools/lib/bpf/libbpf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
Change list:
- v3 -> v4:
- fix some typo
- v2 -> v3:
- update BPF_TRACE_UPROBE_MULTI both in prog and opts suggested by Andrri
- v1 -> v2:
- restore the original initialization way suggested by Jiri
tools/lib/bpf/libbpf.c +8 -4
@@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog, 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 )) +if ((def &SEC_USDT ) &&kernel_supports (prog->obj,FEAT_UPROBE_MULTI_LINK )) { +/* for BPF_TRACE_UPROBE_MULTI, user might want to query expected_attach_type +* in prog, and expected_attach_type we set in kernel is from opts, so we +* update both. +*/ prog->expected_attach_type =BPF_TRACE_UPROBE_MULTI ; + opts->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;
@@ -7443,6 +7449,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog load_attr.attach_btf_id = prog->attach_btf_id; load_attr.kern_version = kern_version; load_attr.prog_ifindex = prog->prog_ifindex; + load_attr.expected_attach_type = prog->expected_attach_type;/* specify func_info/line_info only if kernel supports them */ 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 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,
Signature · 1 line
2.25.1
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 10 lines · On Wed, 25 Sep 2024 23:30:12 +0800 you wrote:
The commit "
5902da6d8a52" setexpected_attach_typeagain with field ofbpf_programafterlibbpf_prepare_prog_load, which makesexpected_attach_type= 0 no sense when kernel not support theattach_typefeature, so fix it.Fixes 5902da6d8a52 ("libbpf: Add uprobe multi link support to bpf_program__attach_usdt")Suggested-by Jiri Olsa <[email protected]>Signed-off-by Tao Chen <[email protected]>[...]
Here is the summary with links:
- [bpf-next,v4] libbpf: Fix expected_attach_type set when kernel not support
https://git.kernel.org/bpf/bpf-next/c/c51003e23373
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html