Skip to contentSkip to conversation

bpf, libbpf: use valid btf in bpf_program__set_attach_target

PATCH Applied Luigi Rizzo 3 participants 3 messages Oct 5, 2020 – Oct 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 bpf, libbpf: use valid btf in bpf_program__set_attach_target

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.

---
 tools/lib/bpf/libbpf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/lib/bpf/libbpf.c +2 -3
index a4f55f8a460d..33bf102259dd 100644
@@ -10353,9 +10353,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;
Signature · 1 line
2.28.0.806.g8561365e88-goog
Acked-by on v3 1/1
#1 lore raw
Quoted 6 lines · Luigi Rizzo

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()).

Quoted 6 lines

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.

Quoted 24 lines
---
 tools/lib/bpf/libbpf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/lib/bpf/libbpf.c +2 -4
index a4f55f8a460d..33bf102259dd 100644
@@ -10353,9 +10353,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;
--

2.28.0.806.g8561365e88-goog

#2 lore raw
In reply to Luigi Rizzo
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 8 lines · On Mon, 5 Oct 2020 15:45:28 -0700 you wrote:

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().

[...]

Here is the summary with links:
- [v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target

    https://git.kernel.org/bpf/bpf-next/c/8cee9107e72c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html