Re: [PATCH bpf-next v5 1/5] bpf, x86: Generate trampolines from bpf_tramp_links

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 13, 2022 at 10:53 AM Kui-Feng Lee <kuifeng@xxxxxx> wrote:
>
> 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@xxxxxx> 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@xxxxxx>
> > > ---
> >
> > Looks good, see two comments below.
> >
> > Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
> >
> > >  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.
>

Yep, saw it when I got to it, forgot to mention it here. Ignore this suggestion.

> >
> > > +
> > >  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);
> >
> > [...]
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux