From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org, kernel-team@meta.com,
Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH v2 bpf-next 8/9] libbpf: implement __arg_ctx fallback logic
Date: Thu, 04 Jan 2024 01:43:48 +0200 [thread overview]
Message-ID: <7746c6fa67e655b288e069b0c1d6393dc8c46502.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzaB_dOz8QmG9kGM7ViD=iM7P-a1GsMAMyyJhdf1W2Kwng@mail.gmail.com>
On Wed, 2024-01-03 at 15:10 -0800, Andrii Nakryiko wrote:
> On Wed, Jan 3, 2024 at 12:57 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > On Tue, 2024-01-02 at 11:00 -0800, Andrii Nakryiko wrote:
> >
> > [...]
> >
> > > +static int clone_func_btf_info(struct btf *btf, int orig_fn_id, struct bpf_program *prog)
> > > +{
> >
> > [...]
> >
> > > + /* clone FUNC first, btf__add_func() enforces
> > > + * non-empty name, so use entry program's name as
> > > + * a placeholder, which we replace immediately
> > > + */
> > > + fn_id = btf__add_func(btf, prog->name, btf_func_linkage(fn_t), fn_t->type);
> >
> > Nit: Why not call this function near the end, when fn_proto_id is available?
> > Thus avoiding need to "guess" fn_t->type.
> >
>
> I think I did it to not have to remember btf_func_linkage(fn_t)
> (because fn_t will be invalidated) and because name_off will be reused
> for parameters. Neither is a big deal, I'll adjust to your suggestion.
>
> But note, we are not guessing ID, it's guaranteed to be +1, it's an
> API contract of btf__add_xxx() APIs.
Noted, well, maybe just skip this nit in such a case.
> > [...]
> >
> > > +static int bpf_program_fixup_func_info(struct bpf_object *obj, struct bpf_program *prog)
> > > +{
> >
> > [...]
> >
> > > + for (i = 1, n = btf__type_cnt(btf); i < n; i++) {
> >
> > [...]
> >
> > > +
> > > + /* clone fn/fn_proto, unless we already did it for another arg */
> > > + if (func_rec->type_id == orig_fn_id) {
> > > + int fn_id;
> > > +
> > > + fn_id = clone_func_btf_info(btf, orig_fn_id, prog);
> > > + if (fn_id < 0) {
> > > + err = fn_id;
> > > + goto err_out;
> > > + }
> > > +
> > > + /* point func_info record to a cloned FUNC type */
> > > + func_rec->type_id = fn_id;
> >
> > Would it be helpful to add a log here, saying that BTF for function
> > so and so is changed before load?
>
> Would it? We don't have global subprog's name readily available, it
> seems. So I'd need to refetch it by fn_id, then btf__str_by_offset()
> just to emit cryptic (for most users) notifications that something
> about some func info was adjusted. And then the user would get this
> same message for the same subprog but in the context of a different
> entry program. Just confusing, tbh.
>
> Unless you insist, I'd leave it as is. This logic is supposed to be
> bullet-proof, so I'm not worried about debugging regressions with it
> (but maybe I'm delusional).
I was thinking about someone finding out that actual in-kernel BTF
is different from that in the program object file, while debugging
something. Might be a bit surprising. I'm not insisting on this, though.
> > > + }
> > > +
> > > + /* create PTR -> STRUCT type chain to mark PTR_TO_CTX argument;
> > > + * we do it just once per main BPF program, as all global
> > > + * funcs share the same program type, so need only PTR ->
> > > + * STRUCT type chain
> > > + */
> > > + if (ptr_id == 0) {
> > > + struct_id = btf__add_struct(btf, ctx_name, 0);
> >
> > Nit: Maybe try looking up existing id for type ctx_name first?
>
> It didn't feel important and I didn't want to do another linear BTF
> search for each such argument. It's trivial to look it up, but I still
> feel like that's a waste... I tried to avoid many linear searches,
> which is why I structured the logic to do one pass over BTF to find
> all decl_tags instead of going over each function and arg and
> searching for decl_tag.
>
> Let's keep it as is, if there are any reasons to try to reuse struct
> (if it is at all present, which for kprobe, for example, is quite
> unlikely due to fancy bpf_user_pt_regs_t name), then we can easily add
> it with no regressions.
I was thinking about possible interaction with btf_struct_access(),
but that is not used to verify context access at the moment.
So, probably not important.
next prev parent reply other threads:[~2024-01-03 23:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 19:00 [PATCH v2 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 1/9] libbpf: name internal functions consistently Andrii Nakryiko
2024-01-03 23:12 ` Alexei Starovoitov
2024-01-03 23:17 ` Eduard Zingerman
2024-01-04 0:30 ` Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 2/9] libbpf: make uniform use of btf__fd() accessor inside libbpf Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 3/9] libbpf: use explicit map reuse flag to skip map creation steps Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 4/9] libbpf: don't rely on map->fd as an indicator of map being created Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 5/9] libbpf: use stable map placeholder FDs Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
2024-01-03 22:46 ` Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 6/9] libbpf: move exception callbacks assignment logic into relocation step Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 7/9] libbpf: move BTF loading step after " Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 8/9] libbpf: implement __arg_ctx fallback logic Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
2024-01-03 23:10 ` Andrii Nakryiko
2024-01-03 23:43 ` Eduard Zingerman [this message]
2024-01-03 23:59 ` Andrii Nakryiko
2024-01-04 0:09 ` Eduard Zingerman
2024-01-04 0:27 ` Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 9/9] selftests/bpf: add arg:ctx cases to test_global_funcs tests Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
2024-01-03 23:17 ` Andrii Nakryiko
2024-01-03 23:51 ` Eduard Zingerman
2024-01-04 0:26 ` Andrii Nakryiko
2024-01-04 0:28 ` Eduard Zingerman
2024-01-02 19:57 ` [PATCH v2 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
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=7746c6fa67e655b288e069b0c1d6393dc8c46502.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
/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