Skip to content
  1. Apr 13, 2019
  2. Apr 12, 2019
  3. Apr 11, 2019
    • Stanislav Fomichev's avatar
      selftests: bpf: add selftest for __sk_buff context in BPF_PROG_TEST_RUN · 3daf8e70
      Stanislav Fomichev authored
      
      
      Simple test that sets cb to {1,2,3,4,5} and priority to 6, runs bpf
      program that fails if cb is not what we expect and increments cb[i] and
      priority. When the test finishes, we check that cb is now {2,3,4,5,6}
      and priority is 7.
      
      We also test the sanity checks:
      * ctx_in is provided, but ctx_size_in is zero (same for
        ctx_out/ctx_size_out)
      * unexpected non-zero fields in __sk_buff return EINVAL
      
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      3daf8e70
    • Stanislav Fomichev's avatar
      libbpf: add support for ctx_{size, }_{in, out} in BPF_PROG_TEST_RUN · 5e903c65
      Stanislav Fomichev authored
      
      
      Support recently introduced input/output context for test runs.
      We extend only bpf_prog_test_run_xattr. bpf_prog_test_run is
      unextendable and left as is.
      
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      5e903c65
    • Stanislav Fomichev's avatar
      bpf: support input __sk_buff context in BPF_PROG_TEST_RUN · b0b9395d
      Stanislav Fomichev authored
      
      
      Add new set of arguments to bpf_attr for BPF_PROG_TEST_RUN:
      * ctx_in/ctx_size_in - input context
      * ctx_out/ctx_size_out - output context
      
      The intended use case is to pass some meta data to the test runs that
      operate on skb (this has being brought up on recent LPC).
      
      For programs that use bpf_prog_test_run_skb, support __sk_buff input and
      output. Initially, from input __sk_buff, copy _only_ cb and priority into
      skb, all other non-zero fields are prohibited (with EINVAL).
      If the user has set ctx_out/ctx_size_out, copy the potentially modified
      __sk_buff back to the userspace.
      
      We require all fields of input __sk_buff except the ones we explicitly
      support to be set to zero. The expectation is that in the future we might
      add support for more fields and we want to fail explicitly if the user
      runs the program on the kernel where we don't yet support them.
      
      The API is intentionally vague (i.e. we don't explicitly add __sk_buff
      to bpf_attr, but ctx_in) to potentially let other test_run types use
      this interface in the future (this can be xdp_md for xdp types for
      example).
      
      v4:
        * don't copy more than allowed in bpf_ctx_init [Martin]
      
      v3:
        * handle case where ctx_in is NULL, but ctx_out is not [Martin]
        * convert size==0 checks to ptr==NULL checks and add some extra ptr
          checks [Martin]
      
      v2:
        * Addressed comments from Martin Lau
      
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      b0b9395d
    • Prashant Bhole's avatar
      tools/bpftool: show btf id in program information · 569b0c77
      Prashant Bhole authored
      
      
      Let's add a way to know whether a program has btf context.
      Patch adds 'btf_id' in the output of program listing.
      When btf_id is present, it means program has btf context.
      
      Sample output:
      user@test# bpftool prog list
      25: xdp  name xdp_prog1  tag 539ec6ce11b52f98  gpl
      	loaded_at 2019-04-10T11:44:20+0900  uid 0
      	xlated 488B  not jited  memlock 4096B  map_ids 23
      	btf_id 1
      
      Signed-off-by: default avatarPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
      Acked-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      569b0c77
    • Andrey Ignatov's avatar
      libbpf: Fix build with gcc-8 · d5adbdd7
      Andrey Ignatov authored
      Reported in [1].
      
      With gcc 8.3.0 the following error is issued:
      
        cc -Ibpf@sta -I. -I.. -I.././include -I.././include/uapi
        -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer
        -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -g -fPIC -g -O2
        -Werror -Wall -Wno-pointer-arith -Wno-sign-compare  -MD -MQ
        'bpf@sta/src_libbpf.c.o' -MF 'bpf@sta/src_libbpf.c.o.d' -o
        'bpf@sta/src_libbpf.c.o' -c ../src/libbpf.c
        ../src/libbpf.c: In function 'bpf_object__elf_collect':
        ../src/libbpf.c:947:18: error: 'map_def_sz' may be used uninitialized in this
        function [-Werror=maybe-uninitialized]
           if (map_def_sz <= sizeof(struct bpf_map_def)) {
               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ../src/libbpf.c:827:18: note: 'map_def_sz' was declared here
          int i, map_idx, map_def_sz, nr_syms, nr_maps = 0, nr_maps_glob = 0;
                          ^~~~~~~~~~
      
      According to [2] -Wmaybe-uninitialized is enabled by -Wall.
      Same error is generated by clang's -Wconditional-uninitialized.
      
      [1] https://github.com/libbpf/libbpf/pull/29#issuecomment-481902601
      [2] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
      
      Fixes: d859900c
      
       ("bpf, libbpf: support global data/bss/rodata sections")
      Reported-by: default avatarEvgeny Vereshchagin <evvers@ya.ru>
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      d5adbdd7
    • Daniel Borkmann's avatar
      mailmap: add entry for email addresses · fa0dcb3f
      Daniel Borkmann authored
      
      
      Redirect email addresses from git log to the mainly used ones
      for Alexei and myself such that it is consistent with the ones
      in MAINTAINERS file. Useful in particular when git mailmap is
      enabled on broader scope, for example:
      
        $ git config --global log.mailmap true
      
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      fa0dcb3f