BPF List
 help / color / mirror / Atom feed
From: Kui-Feng Lee <kuifeng@fb.com>
To: "andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>
Cc: "daniel@iogearbox.net" <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>,
	"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 v5 1/5] bpf, x86: Generate trampolines from bpf_tramp_links
Date: Wed, 13 Apr 2022 17:53:10 +0000	[thread overview]
Message-ID: <dfd67ec4f86552273a89a25f264dcb9e349f3898.camel@fb.com> (raw)
In-Reply-To: <CAEf4BzapYFLns4iDiiRx9PpXftNDOc9jVswwcU_e3ncOeJSvMg@mail.gmail.com>

On Tue, 2022-04-12 at 19:43 -0700, Andrii Nakryiko wrote:
> On Tue, Apr 12, 2022 at 9:56 AM Kui-Feng Lee <kuifeng@fb.com> wrote:
> > 
> > Replace struct bpf_tramp_progs with struct bpf_tramp_links to
> > collect
> > struct bpf_tramp_link(s) for a trampoline.  struct bpf_tramp_link
> > extends bpf_link to act as a linked list node.
> > 
> > arch_prepare_bpf_trampoline() accepts a struct bpf_tramp_links to
> > collects all bpf_tramp_link(s) that a trampoline should call.
> > 
> > Change BPF trampoline and bpf_struct_ops to pass bpf_tramp_links
> > instead of bpf_tramp_progs.
> > 
> > Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
> > ---
> 
> Looks good, see two comments below.
> 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> 
> >  arch/x86/net/bpf_jit_comp.c    | 36 +++++++++--------
> >  include/linux/bpf.h            | 38 ++++++++++++------
> >  include/linux/bpf_types.h      |  1 +
> >  include/uapi/linux/bpf.h       |  1 +
> >  kernel/bpf/bpf_struct_ops.c    | 69 ++++++++++++++++++++++--------
> > --
> >  kernel/bpf/syscall.c           | 23 ++++-------
> >  kernel/bpf/trampoline.c        | 73 +++++++++++++++++++-----------
> > ----
> >  net/bpf/bpf_dummy_struct_ops.c | 35 +++++++++++++---
> >  tools/bpf/bpftool/link.c       |  1 +
> >  tools/include/uapi/linux/bpf.h |  1 +
> >  10 files changed, 175 insertions(+), 103 deletions(-)
> > 
> 
> [...]
> 
> >  /* Different use cases for BPF trampoline:
> > @@ -704,7 +704,7 @@ struct bpf_tramp_progs {
> >  struct bpf_tramp_image;
> >  int arch_prepare_bpf_trampoline(struct bpf_tramp_image *tr, void
> > *image, void *image_end,
> >                                 const struct btf_func_model *m, u32
> > flags,
> > -                               struct bpf_tramp_progs *tprogs,
> > +                               struct bpf_tramp_links *tlinks,
> >                                 void *orig_call);
> >  /* these two functions are called from generated trampoline */
> >  u64 notrace __bpf_prog_enter(struct bpf_prog *prog);
> > @@ -803,9 +803,12 @@ static __always_inline __nocfi unsigned int
> > bpf_dispatcher_nop_func(
> >  {
> >         return bpf_func(ctx, insnsi);
> >  }
> > +
> > +struct bpf_link;
> > +
> 
> is this forward declaration still needed? was it supposed to be a
> struct bpf_tramp_link instead? and also probably higher above, before
> bpf_tramp_links?

You are right, I should remvoe it.

> 
> >  #ifdef CONFIG_BPF_JIT
> > -int bpf_trampoline_link_prog(struct bpf_prog *prog, struct
> > bpf_trampoline *tr);
> > -int bpf_trampoline_unlink_prog(struct bpf_prog *prog, struct
> > bpf_trampoline *tr);
> > +int bpf_trampoline_link_prog(struct bpf_tramp_link *link, struct
> > bpf_trampoline *tr);
> > +int bpf_trampoline_unlink_prog(struct bpf_tramp_link *link, struct
> > bpf_trampoline *tr);
> >  struct bpf_trampoline *bpf_trampoline_get(u64 key,
> >                                           struct
> > bpf_attach_target_info *tgt_info);
> >  void bpf_trampoline_put(struct bpf_trampoline *tr);
> > @@ -856,12 +859,12 @@ int bpf_jit_charge_modmem(u32 size);
> >  void bpf_jit_uncharge_modmem(u32 size);
> >  bool bpf_prog_has_trampoline(const struct bpf_prog *prog);
> >  #else
> > -static inline int bpf_trampoline_link_prog(struct bpf_prog *prog,
> > +static inline int bpf_trampoline_link_prog(struct bpf_tramp_link
> > *link,
> >                                            struct bpf_trampoline
> > *tr)
> >  {
> >         return -ENOTSUPP;
> >  }
> > -static inline int bpf_trampoline_unlink_prog(struct bpf_prog
> > *prog,
> > +static inline int bpf_trampoline_unlink_prog(struct bpf_tramp_link
> > *link,
> >                                              struct bpf_trampoline
> > *tr)
> >  {
> >         return -ENOTSUPP;
> > @@ -960,7 +963,6 @@ struct bpf_prog_aux {
> >         bool tail_call_reachable;
> >         bool xdp_has_frags;
> >         bool use_bpf_prog_pack;
> > -       struct hlist_node tramp_hlist;
> >         /* BTF_KIND_FUNC_PROTO for valid attach_btf_id */
> >         const struct btf_type *attach_func_proto;
> >         /* function name for valid attach_btf_id */
> > @@ -1047,6 +1049,18 @@ struct bpf_link_ops {
> >                               struct bpf_link_info *info);
> >  };
> > 
> > +struct bpf_tramp_link {
> > +       struct bpf_link link;
> > +       struct hlist_node tramp_hlist;
> > +};
> > +
> > https://docs.google.com/document/d/1FYYdi1Hw4pjulbkvI1VmG-kGqTJRCg7bh1vAF4bwjMc/edit?usp=sharing
> > +struct bpf_tracing_link {
> > +       struct bpf_tramp_link link;
> > +       enum bpf_attach_type attach_type;
> > +       struct bpf_trampoline *trampoline;
> > +       struct bpf_prog *tgt_prog;
> > +};
> 
> struct bpf_tracing_link can stay in syscall.c, no? don't see anyone
> needing it outside of syscall.c

It will be used by invoke_bpf_prog() of bpf_jit_comp.c in the 3rd patch
to get the cookie value.

> 
> > +
> >  struct bpf_link_primer {
> >         struct bpf_link *link;
> >         struct file *file;
> > @@ -1084,8 +1098,8 @@ bool bpf_struct_ops_get(const void *kdata);
> >  void bpf_struct_ops_put(const void *kdata);
> >  int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, void
> > *key,
> >                                        void *value);
> > -int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_progs
> > *tprogs,
> > -                                     struct bpf_prog *prog,
> > +int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_links
> > *tlinks,
> > +                                     struct bpf_tramp_link *link,
> >                                       const struct btf_func_model
> > *model,
> >                                       void *image, void *image_end);
> 
> [...]


  reply	other threads:[~2022-04-13 17:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 16:55 [PATCH bpf-next v5 0/5] Attach a cookie to a tracing program Kui-Feng Lee
2022-04-12 16:55 ` [PATCH bpf-next v5 1/5] bpf, x86: Generate trampolines from bpf_tramp_links Kui-Feng Lee
2022-04-13  2:43   ` Andrii Nakryiko
2022-04-13 17:53     ` Kui-Feng Lee [this message]
2022-04-13 19:08       ` Andrii Nakryiko
2022-04-12 16:55 ` [PATCH bpf-next v5 2/5] bpf, x86: Create bpf_tramp_run_ctx on the caller thread's stack Kui-Feng Lee
2022-04-13  2:55   ` Andrii Nakryiko
2022-04-13 18:06     ` Kui-Feng Lee
2022-04-13 20:14     ` Kui-Feng Lee
2022-04-12 16:55 ` [PATCH bpf-next v5 3/5] bpf, x86: Attach a cookie to fentry/fexit/fmod_ret Kui-Feng Lee
2022-04-13  3:03   ` Andrii Nakryiko
2022-04-13 18:14     ` Kui-Feng Lee
2022-04-12 16:55 ` [PATCH bpf-next v5 4/5] lib/bpf: Assign cookies to links in libbpf Kui-Feng Lee
2022-04-13  3:14   ` Andrii Nakryiko
2022-04-12 16:55 ` [PATCH bpf-next v5 5/5] selftest/bpf: The test cses of BPF cookie for fentry/fexit/fmod_ret Kui-Feng Lee
2022-04-13  3:17   ` Andrii Nakryiko
2022-04-13 18:30     ` Kui-Feng Lee

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=dfd67ec4f86552273a89a25f264dcb9e349f3898.camel@fb.com \
    --to=kuifeng@fb.com \
    --cc=Kernel-team@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