From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jakub Sitnicki <jakub@cloudflare.com>
Cc: "Eelco Chaudron" <echaudro@redhat.com>, bpf <bpf@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Networking <netdev@vger.kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Martin Lau" <kafai@fb.com>, "Song Liu" <songliubraving@fb.com>,
"Yonghong Song" <yhs@fb.com>, "Andrii Nakryiko" <andriin@fb.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: [PATCH bpf-next v4 2/3] libbpf: Add support for dynamic program attach target
Date: Tue, 18 Feb 2020 13:24:34 -0800 [thread overview]
Message-ID: <CAEf4BzZ_H7_HVL0uDkxP2hvW7FC=9r_V4X2VzgB+uZMZcxP7aQ@mail.gmail.com> (raw)
In-Reply-To: <877e0jam7z.fsf@cloudflare.com>
On Tue, Feb 18, 2020 at 8:34 AM Jakub Sitnicki <jakub@cloudflare.com> wrote:
>
> Hey Eelco,
>
> On Mon, Feb 17, 2020 at 12:43 PM GMT, Eelco Chaudron wrote:
> > Currently when you want to attach a trace program to a bpf program
> > the section name needs to match the tracepoint/function semantics.
> >
> > However the addition of the bpf_program__set_attach_target() API
> > allows you to specify the tracepoint/function dynamically.
> >
> > The call flow would look something like this:
> >
> > xdp_fd = bpf_prog_get_fd_by_id(id);
> > trace_obj = bpf_object__open_file("func.o", NULL);
> > prog = bpf_object__find_program_by_title(trace_obj,
> > "fentry/myfunc");
> > bpf_program__set_expected_attach_type(prog, BPF_TRACE_FENTRY);
> > bpf_program__set_attach_target(prog, xdp_fd,
> > "xdpfilt_blk_all");
> > bpf_object__load(trace_obj)
> >
> > Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
> > Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> > ---
> > tools/lib/bpf/libbpf.c | 34 ++++++++++++++++++++++++++++++----
> > tools/lib/bpf/libbpf.h | 4 ++++
> > tools/lib/bpf/libbpf.map | 2 ++
> > 3 files changed, 36 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 514b1a524abb..0c25d78fb5d8 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
>
> [...]
>
> > @@ -8132,6 +8133,31 @@ void bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear)
> > }
> > }
> >
> > +int bpf_program__set_attach_target(struct bpf_program *prog,
> > + int attach_prog_fd,
> > + const char *attach_func_name)
> > +{
> > + int btf_id;
> > +
> > + if (!prog || attach_prog_fd < 0 || !attach_func_name)
> > + return -EINVAL;
> > +
> > + 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,
> > + prog->expected_attach_type);
> > +
> > + if (btf_id <= 0)
> > + return btf_id;
>
> Looks like we can get 0 as return value on both error and success
> (below)? Is that intentional?
Neither libbpf_find_prog_btf_id nor __find_vmlinux_btf_id are going to
return 0 on failure. But I do agree that if (btf_id < 0) check would
be better here.
With that minor nit:
Acked-by: Andrii Nakryiko <andriin@fb.com>
>
> > +
> > + prog->attach_btf_id = btf_id;
> > + prog->attach_prog_fd = attach_prog_fd;
> > + return 0;
> > +}
> > +
> > int parse_cpu_mask_str(const char *s, bool **mask, int *mask_sz)
> > {
> > int err = 0, n, len, start, end = -1;
>
> [...]
next prev parent reply other threads:[~2020-02-18 21:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 12:42 [PATCH bpf-next v4 0/3] libbpf: Add support for dynamic program attach target Eelco Chaudron
2020-02-17 12:43 ` [PATCH bpf-next v4 1/3] libbpf: Bump libpf current version to v0.0.8 Eelco Chaudron
2020-02-17 12:43 ` [PATCH bpf-next v4 2/3] libbpf: Add support for dynamic program attach target Eelco Chaudron
2020-02-18 16:34 ` Jakub Sitnicki
2020-02-18 21:24 ` Andrii Nakryiko [this message]
2020-02-19 11:06 ` Eelco Chaudron
2020-02-19 17:41 ` Andrii Nakryiko
2020-02-20 13:21 ` Eelco Chaudron
2020-02-17 12:43 ` [PATCH bpf-next v4 3/3] selftests/bpf: update xdp_bpf2bpf test to use new set_attach_target API Eelco Chaudron
2020-02-18 21:21 ` Andrii Nakryiko
2020-02-19 10:54 ` Eelco Chaudron
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='CAEf4BzZ_H7_HVL0uDkxP2hvW7FC=9r_V4X2VzgB+uZMZcxP7aQ@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=echaudro@redhat.com \
--cc=jakub@cloudflare.com \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=yhs@fb.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).