From: Delyan Kratunov <delyank@fb.com>
To: "andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>
Cc: "daniel@iogearbox.net" <daniel@iogearbox.net>,
"ast@kernel.org" <ast@kernel.org>,
"andrii@kernel.org" <andrii@kernel.org>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 3/5] libbpf: add subskeleton scaffolding
Date: Fri, 11 Mar 2022 23:28:22 +0000 [thread overview]
Message-ID: <97cd91b96584c7e0d37637b8d4a0ecf04322c964.camel@fb.com> (raw)
In-Reply-To: <CAEf4BzYPRs6wyAsZqcE7ga15Y1jtbNcAV+a+89vXNbW3ZFyEjw@mail.gmail.com>
Thanks Andrii!
On Fri, 2022-03-11 at 15:08 -0800, Andrii Nakryiko wrote:
> On Fri, Mar 11, 2022 at 2:52 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>
> >
[...]
> > > +
> > > + err = populate_skeleton_maps(s->obj, s->maps, s->map_cnt);
> > > + if (err) {
> > > + pr_warn("failed to populate subskeleton maps: %d\n", err);
> > > + return libbpf_err(err);
> > > }
> > >
> > > - for (i = 0; i < s->prog_cnt; i++) {
> > > - struct bpf_program **prog = s->progs[i].prog;
> > > - const char *name = s->progs[i].name;
> > > + err = populate_skeleton_progs(s->obj, s->progs, s->prog_cnt);
> > > + if (err) {
> > > + pr_warn("failed to populate subskeleton maps: %d\n", err);
> > > + return libbpf_err(err);
> > > + }
> > >
> > > - *prog = bpf_object__find_program_by_name(obj, name);
> > > - if (!*prog) {
> > > - pr_warn("failed to find skeleton program '%s'\n", name);
> > > - return libbpf_err(-ESRCH);
> > > + for (var_idx = 0; var_idx < s->var_cnt; var_idx++) {
> > > + var_skel = &s->vars[var_idx];
> > > + map = *var_skel->map;
> > > + map_type_id = bpf_map__btf_value_type_id(map);
> > > + map_type = btf__type_by_id(btf, map_type_id);
> > > +
> >
> > should we double-check that map_type is DATASEC?
Sure, can do.
> >
> > > + len = btf_vlen(map_type);
> > > + var = btf_var_secinfos(map_type);
> > > + for (i = 0; i < len; i++, var++) {
> > > + var_type = btf__type_by_id(btf, var->type);
> > > + if (!var_type) {
> >
> > unless BTF itself is corrupted, this shouldn't ever happen. So
> > checking for DATASEC should be enough and this if (!var_type) is
> > redundant
> >
> > > + pr_warn("Could not find var type for item %1$d in section %2$s",
> > > + i, bpf_map__name(map));
> > > + return libbpf_err(-EINVAL);
> > > + }
> > > + var_name = btf__name_by_offset(btf, var_type->name_off);
> > > + if (strcmp(var_name, var_skel->name) == 0) {
> > > + *var_skel->addr = (char *) map->mmaped + var->offset;
> >
> > is (char *) cast necessary? C allows pointer adjustment on void *, so
> > shouldn't be
>
> oh, wait, it's so that C++ compiler doesn't complain, never mind
This is libbpf code, not subskel code, so it shouldn't get compiled as C++. It's
really because of -Wpointer-arith and -Werror.
>
> >
> > > + break;
> > > + }
> > > }
> > > }
> > > -
> > > return 0;
> > > }
> > >
> >
> > [...]
> >
> > > struct gen_loader_opts {
> > > size_t sz; /* size of this struct, for forward/backward compatiblity */
> > > const char *data;
> > > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> > > index df1b947792c8..d744fbb8612e 100644
> > > --- a/tools/lib/bpf/libbpf.map
> > > +++ b/tools/lib/bpf/libbpf.map
> > > @@ -442,6 +442,8 @@ LIBBPF_0.7.0 {
> > >
> > > LIBBPF_0.8.0 {
> > > global:
> > > + bpf_object__open_subskeleton;
> > > + bpf_object__destroy_subskeleton;
> >
> > nit: should be in alphabetic order
> >
> > > libbpf_register_prog_handler;
> > > libbpf_unregister_prog_handler;
> > > } LIBBPF_0.7.0;
> > > --
> > > 2.34.1
next prev parent reply other threads:[~2022-03-11 23:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 0:11 [PATCH bpf-next v2 0/5] Subskeleton support for BPF libraries Delyan Kratunov
2022-03-11 0:11 ` [PATCH bpf-next v2 1/5] libbpf: add new strict flag for .text subprograms Delyan Kratunov
2022-03-11 22:30 ` Andrii Nakryiko
2022-03-11 0:11 ` [PATCH bpf-next v2 2/5] libbpf: init btf_{key,value}_type_id on internal map open Delyan Kratunov
2022-03-11 22:42 ` Andrii Nakryiko
2022-03-11 0:11 ` [PATCH bpf-next v2 3/5] libbpf: add subskeleton scaffolding Delyan Kratunov
2022-03-11 22:52 ` Andrii Nakryiko
2022-03-11 23:08 ` Andrii Nakryiko
2022-03-11 23:28 ` Delyan Kratunov [this message]
2022-03-11 23:41 ` Andrii Nakryiko
2022-03-11 0:11 ` [PATCH bpf-next v2 4/5] bpftool: add support for subskeletons Delyan Kratunov
2022-03-11 23:27 ` Andrii Nakryiko
2022-03-14 23:18 ` Delyan Kratunov
2022-03-15 17:28 ` Delyan Kratunov
2022-03-15 18:07 ` Andrii Nakryiko
2022-03-15 18:07 ` Andrii Nakryiko
2022-03-11 0:12 ` [PATCH bpf-next v2 5/5] selftests/bpf: test subskeleton functionality Delyan Kratunov
2022-03-11 23:40 ` Andrii Nakryiko
2022-03-14 23:50 ` Delyan Kratunov
2022-03-15 18:31 ` Andrii Nakryiko
2022-03-11 5:10 ` [PATCH bpf-next v2 0/5] Subskeleton support for BPF libraries Yonghong Song
2022-03-11 18:18 ` Delyan Kratunov
2022-03-12 0:39 ` Yonghong Song
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=97cd91b96584c7e0d37637b8d4a0ecf04322c964.camel@fb.com \
--to=delyank@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
/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