1. 23 Jan, 2020 36 commits
  2. 22 Jan, 2020 4 commits
    • Daniel Borkmann's avatar
      Merge branch 'bpf-dynamic-relinking' · 1b2fd38d
      Daniel Borkmann authored
      Alexei Starovoitov says:
      
      ====================
      The last few month BPF community has been discussing an approach to call
      chaining, since exiting bpt_tail_call() mechanism used in production XDP
      programs has plenty of downsides. The outcome of these discussion was a
      conclusion to implement dynamic re-linking of BPF programs. Where rootlet XDP
      program attached to a netdevice can programmatically define a policy of
      execution of other XDP programs. Such rootlet would be compiled as normal XDP
      program and provide a number of placeholder global functions which later can be
      replaced with future XDP programs. BPF trampoline, function by function
      verification were building blocks towards that goal. The patch 1 is a final
      building block. It introduces dynamic program extensions. A number of
      improvements like more flexible function by function verification and better
      libbpf api will be implemented in future patches.
      
      v1->v2:
      - addressed Andrii's comments
      - rebase
      ====================
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      1b2fd38d
    • Alexei Starovoitov's avatar
      selftests/bpf: Add tests for program extensions · 7805fe84
      Alexei Starovoitov authored
      Add program extension tests that build on top of fexit_bpf2bpf tests.
      Replace three global functions in previously loaded test_pkt_access.c program
      with three new implementations:
      int get_skb_len(struct __sk_buff *skb);
      int get_constant(long val);
      int get_skb_ifindex(int val, struct __sk_buff *skb, int var);
      New function return the same results as original only if arguments match.
      
      new_get_skb_ifindex() demonstrates that 'skb' argument doesn't have to be first
      and only argument of BPF program. All normal skb based accesses are available.
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Acked-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20200121005348.2769920-4-ast@kernel.org
      7805fe84
    • Alexei Starovoitov's avatar
      libbpf: Add support for program extensions · 2db6eab1
      Alexei Starovoitov authored
      Add minimal support for program extensions. bpf_object_open_opts() needs to be
      called with attach_prog_fd = target_prog_fd and BPF program extension needs to
      have in .c file section definition like SEC("freplace/func_to_be_replaced").
      libbpf will search for "func_to_be_replaced" in the target_prog_fd's BTF and
      will pass it in attach_btf_id to the kernel. This approach works for tests, but
      more compex use case may need to request function name (and attach_btf_id that
      kernel sees) to be more dynamic. Such API will be added in future patches.
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Acked-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20200121005348.2769920-3-ast@kernel.org
      2db6eab1
    • Alexei Starovoitov's avatar
      bpf: Introduce dynamic program extensions · be8704ff
      Alexei Starovoitov authored
      Introduce dynamic program extensions. The users can load additional BPF
      functions and replace global functions in previously loaded BPF programs while
      these programs are executing.
      
      Global functions are verified individually by the verifier based on their types only.
      Hence the global function in the new program which types match older function can
      safely replace that corresponding function.
      
      This new function/program is called 'an extension' of old program. At load time
      the verifier uses (attach_prog_fd, attach_btf_id) pair to identify the function
      to be replaced. The BPF program type is derived from the target program into
      extension program. Technically bpf_verifier_ops is copied from target program.
      The BPF_PROG_TYPE_EXT program type is a placeholder. It has empty verifier_ops.
      The extension program can call the same bpf helper functions as target program.
      Single BPF_PROG_TYPE_EXT type is used to extend XDP, SKB and all other program
      types. The verifier allows only one level of replacement. Meaning that the
      extension program cannot recursively extend an extension. That also means that
      the maximum stack size is increasing from 512 to 1024 bytes and maximum
      function nesting level from 8 to 16. The programs don't always consume that
      much. The stack usage is determined by the number of on-stack variables used by
      the program. The verifier could have enforced 512 limit for combined original
      plus extension program, but it makes for difficult user experience. The main
      use case for extensions is to provide generic mechanism to plug external
      programs into policy program or function call chaining.
      
      BPF trampoline is used to track both fentry/fexit and program extensions
      because both are using the same nop slot at the beginning of every BPF
      function. Attaching fentry/fexit to a function that was replaced is not
      allowed. The opposite is true as well. Replacing a function that currently
      being analyzed with fentry/fexit is not allowed. The executable page allocated
      by BPF trampoline is not used by program extensions. This inefficiency will be
      optimized in future patches.
      
      Function by function verification of global function supports scalars and
      pointer to context only. Hence program extensions are supported for such class
      of global functions only. In the future the verifier will be extended with
      support to pointers to structures, arrays with sizes, etc.
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Acked-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20200121005348.2769920-2-ast@kernel.org
      be8704ff