mbox series

[bpf-next,v3,0/5] Attach a cookie to a tracing program.

Message ID 20220407192552.2343076-1-kuifeng@fb.com (mailing list archive)
Headers show
Series Attach a cookie to a tracing program. | expand

Message

Kui-Feng Lee April 7, 2022, 7:25 p.m. UTC
Allow users to attach a 64-bits cookie to a bpf_link of fentry, fexit,
or fmod_ret.

This patchset includes several major changes.

 - Define struct bpf_tramp_links to replace bpf_tramp_prog.
   struct bpf_tramp_links collects bpf_links of a trampoline

 - Generate a trampoline to call bpf_progs of given bpf_links.

 - Trampolines always set/reset bpf_run_ctx before/after
   calling/leaving a tracing program.

 - Attach a cookie to a bpf_link of fentry/fexit/fmod_ret.  The value
   will be available when running the associated bpf_prog.

The major differences from v2:

 - Move the allocations of run_ctx (struct bpf_tramp_run_ctx) out of
   invoke_bpf_prog().

 - Move hlist_node out of bpf_link and introduce struct bpf_tramp_link
   to own hlist_node.

 - Store cookies at struct bpf_tracing_link.

 - Use SIB byte to reduce the number of instructions to set cookie
   values. (Use RSP directly)

v1: https://lore.kernel.org/all/20220126214809.3868787-1-kuifeng@fb.com/
v2: https://lore.kernel.org/bpf/20220316004231.1103318-1-kuifeng@fb.com/

Kui-Feng Lee (5):
  bpf, x86: Generate trampolines from bpf_tramp_links
  bpf, x86: Create bpf_tramp_run_ctx on the caller thread's stack
  bpf, x86: Attach a cookie to fentry/fexit/fmod_ret.
  lib/bpf: Assign cookies to links in libbpf.
  selftest/bpf: The test cses of BPF cookie for fentry/fexit/fmod_ret.

 arch/x86/net/bpf_jit_comp.c                   | 98 +++++++++++++++----
 include/linux/bpf.h                           | 56 ++++++++---
 include/linux/bpf_types.h                     |  1 +
 include/uapi/linux/bpf.h                      |  9 ++
 kernel/bpf/bpf_struct_ops.c                   | 69 ++++++++-----
 kernel/bpf/syscall.c                          | 54 ++++++----
 kernel/bpf/trampoline.c                       | 96 +++++++++++-------
 kernel/trace/bpf_trace.c                      | 17 ++++
 net/bpf/bpf_dummy_struct_ops.c                | 35 ++++++-
 tools/bpf/bpftool/link.c                      |  1 +
 tools/include/uapi/linux/bpf.h                |  8 ++
 tools/lib/bpf/bpf.c                           |  7 ++
 tools/lib/bpf/bpf.h                           |  3 +
 tools/lib/bpf/libbpf.c                        | 33 +++++++
 tools/lib/bpf/libbpf.h                        | 12 +++
 tools/lib/bpf/libbpf.map                      |  1 +
 .../selftests/bpf/prog_tests/bpf_cookie.c     | 52 ++++++++++
 .../selftests/bpf/progs/test_bpf_cookie.c     | 24 +++++
 18 files changed, 459 insertions(+), 117 deletions(-)

Comments

Daniel Borkmann April 8, 2022, 9:33 p.m. UTC | #1
On 4/7/22 9:25 PM, Kui-Feng Lee wrote:
> Allow users to attach a 64-bits cookie to a bpf_link of fentry, fexit,
> or fmod_ret.
> 
> This patchset includes several major changes.
> 
>   - Define struct bpf_tramp_links to replace bpf_tramp_prog.
>     struct bpf_tramp_links collects bpf_links of a trampoline
> 
>   - Generate a trampoline to call bpf_progs of given bpf_links.
> 
>   - Trampolines always set/reset bpf_run_ctx before/after
>     calling/leaving a tracing program.
> 
>   - Attach a cookie to a bpf_link of fentry/fexit/fmod_ret.  The value
>     will be available when running the associated bpf_prog.
> 
> The major differences from v2:
> 
>   - Move the allocations of run_ctx (struct bpf_tramp_run_ctx) out of
>     invoke_bpf_prog().
> 
>   - Move hlist_node out of bpf_link and introduce struct bpf_tramp_link
>     to own hlist_node.
> 
>   - Store cookies at struct bpf_tracing_link.
> 
>   - Use SIB byte to reduce the number of instructions to set cookie
>     values. (Use RSP directly)
> 
> v1: https://lore.kernel.org/all/20220126214809.3868787-1-kuifeng@fb.com/
> v2: https://lore.kernel.org/bpf/20220316004231.1103318-1-kuifeng@fb.com/

Kui-Feng, would be great if you have a chance to rebase, so that the set can
also go through BPF CI.

Thanks a lot,
Daniel
Kui-Feng Lee April 11, 2022, 5:36 p.m. UTC | #2
On Fri, 2022-04-08 at 23:33 +0200, Daniel Borkmann wrote:
> On 4/7/22 9:25 PM, Kui-Feng Lee wrote:
> > Allow users to attach a 64-bits cookie to a bpf_link of fentry,
> > fexit,
> > or fmod_ret.
> > 
> > This patchset includes several major changes.
> > 
> >   - Define struct bpf_tramp_links to replace bpf_tramp_prog.
> >     struct bpf_tramp_links collects bpf_links of a trampoline
> > 
> >   - Generate a trampoline to call bpf_progs of given bpf_links.
> > 
> >   - Trampolines always set/reset bpf_run_ctx before/after
> >     calling/leaving a tracing program.
> > 
> >   - Attach a cookie to a bpf_link of fentry/fexit/fmod_ret.  The
> > value
> >     will be available when running the associated bpf_prog.
> > 
> > The major differences from v2:
> > 
> >   - Move the allocations of run_ctx (struct bpf_tramp_run_ctx) out
> > of
> >     invoke_bpf_prog().
> > 
> >   - Move hlist_node out of bpf_link and introduce struct
> > bpf_tramp_link
> >     to own hlist_node.
> > 
> >   - Store cookies at struct bpf_tracing_link.
> > 
> >   - Use SIB byte to reduce the number of instructions to set cookie
> >     values. (Use RSP directly)
> > 
> > v1:
> > https://lore.kernel.org/all/20220126214809.3868787-1-kuifeng@fb.com/
> > v2:
> > https://lore.kernel.org/bpf/20220316004231.1103318-1-kuifeng@fb.com/
> 
> Kui-Feng, would be great if you have a chance to rebase, so that the
> set can
> also go through BPF CI.
> 
> Thanks a lot,
> Daniel
Yes, just sent new patches out.