* [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target
@ 2020-10-05 22:45 Luigi Rizzo
2020-10-06 8:01 ` Petar Penkov
2020-10-06 18:50 ` patchwork-bot+bpf
0 siblings, 2 replies; 3+ messages in thread
From: Luigi Rizzo @ 2020-10-05 22:45 UTC (permalink / raw)
To: bpf, Eelco Chaudron, Daniel Borkmann, rizzo.unipi,
Andrii Nakryiko
Cc: ppenkov, tommaso.burlon, 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()).
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.
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Luigi Rizzo <lrizzo@google.com>
---
tools/lib/bpf/libbpf.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a4f55f8a460d..33bf102259dd 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target
2020-10-05 22:45 [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target Luigi Rizzo
@ 2020-10-06 8:01 ` Petar Penkov
2020-10-06 18:50 ` patchwork-bot+bpf
1 sibling, 0 replies; 3+ messages in thread
From: Petar Penkov @ 2020-10-06 8:01 UTC (permalink / raw)
To: Luigi Rizzo
Cc: bpf, Eelco Chaudron, Daniel Borkmann, rizzo.unipi,
Andrii Nakryiko, tommaso.burlon
On Mon, Oct 5, 2020 at 3:45 PM Luigi Rizzo <lrizzo@google.com> 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().
>
> At some point we may want to opportunistically cache btf_vmlinux
> so it can be reused with multiple programs.
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Petar Penkov <ppenkov@google.com>
> Signed-off-by: Luigi Rizzo <lrizzo@google.com>
> ---
> tools/lib/bpf/libbpf.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index a4f55f8a460d..33bf102259dd 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target
2020-10-05 22:45 [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target Luigi Rizzo
2020-10-06 8:01 ` Petar Penkov
@ 2020-10-06 18:50 ` patchwork-bot+bpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bpf @ 2020-10-06 18:50 UTC (permalink / raw)
To: Luigi Rizzo
Cc: bpf, echaudro, daniel, rizzo.unipi, andriin, ppenkov,
tommaso.burlon
Hello:
This patch was applied to bpf/bpf-next.git (refs/heads/master):
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-06 18:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-05 22:45 [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target Luigi Rizzo
2020-10-06 8:01 ` Petar Penkov
2020-10-06 18:50 ` patchwork-bot+bpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox