From: Yonghong Song <yhs@fb.com>
To: Luigi Rizzo <lrizzo@google.com>, <bpf@vger.kernel.org>,
Eelco Chaudron <echaudro@redhat.com>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: <ppenkov@google.com>
Subject: Re: [PATCH] use valid btf in bpf_program__set_attach_target(prog, 0, ...);
Date: Mon, 5 Oct 2020 09:04:45 -0700 [thread overview]
Message-ID: <102ef3d8-e9fa-24c6-af96-b0d62ccf57c2@fb.com> (raw)
In-Reply-To: <20201005134100.302271-1-lrizzo@google.com>
On 10/5/20 6:41 AM, Luigi Rizzo wrote:
> bpf_program__set_attach_target() will always fail with fd=0 (attach to a
> kernel symbol) because obj->btf_vmlinux is NULL and there is no way to
> set it.
>
> Fix this by explicitly calling libbpf_find_kernel_btf() in the function.
>
> Signed-off-by: Luigi Rizzo <lrizzo@google.com>
> ---
> tools/lib/bpf/libbpf.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index a4f55f8a460d..3a63db86666f 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -10352,10 +10352,13 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
> if (attach_prog_fd)
> 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,
> + else {
> + struct btf *btf = libbpf_find_kernel_btf();
> +
> + btf_id = __find_vmlinux_btf_id(btf, attach_func_name,
> prog->expected_attach_type);
> + btf__free(btf);
> + }
Doesn't feel this is right fix. In libbpf, we have API function
libbpf_find_vmlinux_btf_id
just doing the above.
Also, could you point out why btf_vmlinux is NULL? Is this related
to fd = 0? We probably
should fix the problem there since what if other API functions
like bpf_program__set_attach_target() wants btf_vmlinux. We should
not duplicate this logic to other API functions.
>
> if (btf_id < 0)
> return btf_id;
>
next prev parent reply other threads:[~2020-10-05 16:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-05 13:41 [PATCH] use valid btf in bpf_program__set_attach_target(prog, 0, ...); Luigi Rizzo
2020-10-05 16:04 ` Yonghong Song [this message]
2020-10-05 16:41 ` Luigi Rizzo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=102ef3d8-e9fa-24c6-af96-b0d62ccf57c2@fb.com \
--to=yhs@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=echaudro@redhat.com \
--cc=lrizzo@google.com \
--cc=ppenkov@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox