From: Luigi Rizzo <lrizzo@google.com>
To: bpf@vger.kernel.org, Eelco Chaudron <echaudro@redhat.com>,
Daniel Borkmann <daniel@iogearbox.net>,
rizzo.unipi@gmail.com, Andrii Nakryiko <andriin@fb.com>
Cc: ppenkov@google.com, tommaso.burlon@gmail.com,
Luigi Rizzo <lrizzo@google.com>
Subject: [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target
Date: Mon, 5 Oct 2020 15:45:28 -0700 [thread overview]
Message-ID: <20201005224528.389097-1-lrizzo@google.com> (raw)
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
next reply other threads:[~2020-10-05 22:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-05 22:45 Luigi Rizzo [this message]
2020-10-06 8:01 ` [PATCH v3] bpf, libbpf: use valid btf in bpf_program__set_attach_target Petar Penkov
2020-10-06 18:50 ` patchwork-bot+bpf
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=20201005224528.389097-1-lrizzo@google.com \
--to=lrizzo@google.com \
--cc=andriin@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=echaudro@redhat.com \
--cc=ppenkov@google.com \
--cc=rizzo.unipi@gmail.com \
--cc=tommaso.burlon@gmail.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;
as well as URLs for NNTP newsgroup(s).