Skip to content

Commit

Permalink
bpf, libbpf: Use valid btf in bpf_program__set_attach_target
Browse files Browse the repository at this point in the history
bpf_program__set_attach_target(prog, fd, ...) will always fail when
fd = 0 (attach to a kernel symbol) because obj->btf_vmlinux is NULL
and there is no way to set it (at the moment btf_vmlinux is meant
to be temporary storage for use in bpf_object__load_xattr()).

Fix this by using libbpf_find_vmlinux_btf_id().

At some point we may want to opportunistically cache btf_vmlinux
so it can be reused with multiple programs.

Signed-off-by: Luigi Rizzo <lrizzo@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Petar Penkov <ppenkov@google.com>
Link: https://lore.kernel.org/bpf/20201005224528.389097-1-lrizzo@google.com
  • Loading branch information
Luigi Rizzo authored and Alexei Starovoitov committed Oct 6, 2020
1 parent fd08f94 commit 8cee910
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -10451,9 +10451,8 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
btf_id = libbpf_find_prog_btf_id(attach_func_name,
attach_prog_fd);
else
btf_id = __find_vmlinux_btf_id(prog->obj->btf_vmlinux,
attach_func_name,
prog->expected_attach_type);
btf_id = libbpf_find_vmlinux_btf_id(attach_func_name,
prog->expected_attach_type);

if (btf_id < 0)
return btf_id;
Expand Down

0 comments on commit 8cee910

Please sign in to comment.