1. 16 9月, 2020 1 次提交
  2. 14 8月, 2020 1 次提交
  3. 25 4月, 2020 1 次提交
    • S
      selftests/bpf: Fix a couple of broken test_btf cases · e1cebd84
      Stanislav Fomichev 提交于
      Commit 51c39bb1 ("bpf: Introduce function-by-function verification")
      introduced function linkage flag and changed the error message from
      "vlen != 0" to "Invalid func linkage" and broke some fake BPF programs.
      
      Adjust the test accordingly.
      
      AFACT, the programs don't really need any arguments and only look
      at BTF for maps, so let's drop the args altogether.
      
      Before:
      BTF raw test[103] (func (Non zero vlen)): do_test_raw:3703:FAIL expected
      err_str:vlen != 0
      magic: 0xeb9f
      version: 1
      flags: 0x0
      hdr_len: 24
      type_off: 0
      type_len: 72
      str_off: 72
      str_len: 10
      btf_total_size: 106
      [1] INT (anon) size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
      [2] INT (anon) size=4 bits_offset=0 nr_bits=32 encoding=(none)
      [3] FUNC_PROTO (anon) return=0 args=(1 a, 2 b)
      [4] FUNC func type_id=3 Invalid func linkage
      
      BTF libbpf test[1] (test_btf_haskv.o): libbpf: load bpf program failed:
      Invalid argument
      libbpf: -- BEGIN DUMP LOG ---
      libbpf:
      Validating test_long_fname_2() func#1...
      Arg#0 type PTR in test_long_fname_2() is not supported yet.
      processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
      peak_states 0 mark_read 0
      
      libbpf: -- END LOG --
      libbpf: failed to load program 'dummy_tracepoint'
      libbpf: failed to load object 'test_btf_haskv.o'
      do_test_file:4201:FAIL bpf_object__load: -4007
      BTF libbpf test[2] (test_btf_newkv.o): libbpf: load bpf program failed:
      Invalid argument
      libbpf: -- BEGIN DUMP LOG ---
      libbpf:
      Validating test_long_fname_2() func#1...
      Arg#0 type PTR in test_long_fname_2() is not supported yet.
      processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
      peak_states 0 mark_read 0
      
      libbpf: -- END LOG --
      libbpf: failed to load program 'dummy_tracepoint'
      libbpf: failed to load object 'test_btf_newkv.o'
      do_test_file:4201:FAIL bpf_object__load: -4007
      BTF libbpf test[3] (test_btf_nokv.o): libbpf: load bpf program failed:
      Invalid argument
      libbpf: -- BEGIN DUMP LOG ---
      libbpf:
      Validating test_long_fname_2() func#1...
      Arg#0 type PTR in test_long_fname_2() is not supported yet.
      processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
      peak_states 0 mark_read 0
      
      libbpf: -- END LOG --
      libbpf: failed to load program 'dummy_tracepoint'
      libbpf: failed to load object 'test_btf_nokv.o'
      do_test_file:4201:FAIL bpf_object__load: -4007
      
      Fixes: 51c39bb1 ("bpf: Introduce function-by-function verification")
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200422003753.124921-1-sdf@google.com
      e1cebd84
  4. 11 3月, 2020 1 次提交
  5. 21 1月, 2020 1 次提交
  6. 16 7月, 2019 1 次提交
  7. 18 6月, 2019 1 次提交
  8. 25 5月, 2019 1 次提交
  9. 28 4月, 2019 1 次提交
  10. 16 4月, 2019 1 次提交
  11. 10 4月, 2019 1 次提交
    • D
      bpf, selftest: add test cases for BTF Var and DataSec · c861168b
      Daniel Borkmann 提交于
      Extend test_btf with various positive and negative tests around
      BTF verification of kind Var and DataSec. All passing as well:
      
        # ./test_btf
        [...]
        BTF raw test[4] (global data test #1): OK
        BTF raw test[5] (global data test #2): OK
        BTF raw test[6] (global data test #3): OK
        BTF raw test[7] (global data test #4, unsupported linkage): OK
        BTF raw test[8] (global data test #5, invalid var type): OK
        BTF raw test[9] (global data test #6, invalid var type (fwd type)): OK
        BTF raw test[10] (global data test #7, invalid var type (fwd type)): OK
        BTF raw test[11] (global data test #8, invalid var size): OK
        BTF raw test[12] (global data test #9, invalid var size): OK
        BTF raw test[13] (global data test #10, invalid var size): OK
        BTF raw test[14] (global data test #11, multiple section members): OK
        BTF raw test[15] (global data test #12, invalid offset): OK
        BTF raw test[16] (global data test #13, invalid offset): OK
        BTF raw test[17] (global data test #14, invalid offset): OK
        BTF raw test[18] (global data test #15, not var kind): OK
        BTF raw test[19] (global data test #16, invalid var referencing sec): OK
        BTF raw test[20] (global data test #17, invalid var referencing var): OK
        BTF raw test[21] (global data test #18, invalid var loop): OK
        BTF raw test[22] (global data test #19, invalid var referencing var): OK
        BTF raw test[23] (global data test #20, invalid ptr referencing var): OK
        BTF raw test[24] (global data test #21, var included in struct): OK
        BTF raw test[25] (global data test #22, array of var): OK
        [...]
        PASS:167 SKIP:0 FAIL:0
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      c861168b
  12. 01 4月, 2019 1 次提交
    • Y
      bpf: add bpffs multi-dimensional array tests in test_btf · 9de2640b
      Yonghong Song 提交于
      For multiple dimensional arrays like below,
        int a[2][3]
      both llvm and pahole generated one BTF_KIND_ARRAY type like
        . element_type: int
        . index_type: unsigned int
        . number of elements: 6
      
      Such a collapsed BTF_KIND_ARRAY type will cause the divergence
      in BTF vs. the user code. In the compile-once-run-everywhere
      project, the header file is generated from BTF and used for bpf
      program, and the definition in the header file will be different
      from what user expects.
      
      But the kernel actually supports chained multi-dimensional array
      types properly. The above "int a[2][3]" can be represented as
        Type #n:
          . element_type: int
          . index_type: unsigned int
          . number of elements: 3
        Type #(n+1):
          . element_type: type #n
          . index_type: unsigned int
          . number of elements: 2
      
      The following llvm commit
        https://reviews.llvm.org/rL357215
      also enables llvm to generated proper chained multi-dimensional arrays.
      
      The test_btf already has a raw test ("struct test #1") for chained
      multi-dimensional arrays. This patch added amended bpffs test for
      chained multi-dimensional arrays.
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      9de2640b
  13. 27 3月, 2019 1 次提交
  14. 15 3月, 2019 1 次提交
  15. 01 3月, 2019 2 次提交
  16. 09 2月, 2019 1 次提交
  17. 06 2月, 2019 1 次提交
    • Y
      tools/bpf: fix a selftest test_btf failure · 206dafb0
      Yonghong Song 提交于
      Commit 9c651127 ("selftests/btf: add initial BTF dedup tests")
      added dedup tests in test_btf.c.
      It broke the raw test:
       BTF raw test[71] (func proto (Bad arg name_off)):
          btf_raw_create:2905:FAIL Error getting string #65535, strs_cnt:1
      
      The test itself encodes invalid func_proto parameter name
      offset 0xffffFFFF as a negative test for the kernel.
      The above commit changed the meaning of that offset and
      resulted in a user space error.
        #define NAME_NTH(N) (0xffff0000 | N)
        #define IS_NAME_NTH(X) ((X & 0xffff0000) == 0xffff0000)
        #define GET_NAME_NTH_IDX(X) (X & 0x0000ffff)
      
      Currently, the kernel permits maximum name offset 0xffff.
      Set the test name off as 0x0fffFFFF to trigger the kernel
      verification failure.
      
      Cc: Andrii Nakryiko <andriin@fb.com>
      Fixes: 9c651127 ("selftests/btf: add initial BTF dedup tests")
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      206dafb0
  18. 05 2月, 2019 3 次提交
  19. 30 1月, 2019 1 次提交
  20. 24 1月, 2019 1 次提交
  21. 17 1月, 2019 3 次提交
  22. 11 1月, 2019 1 次提交
    • Y
      tools/bpf: test btf bitfield with >=256 struct member offset · e43207fa
      Yonghong Song 提交于
      This patch modified test_btf pretty print test to cover
      the bitfield with struct member equal to or greater 256.
      
      Without the previous kernel patch fix, the modified test will fail:
      
        $ test_btf -p
        ......
        BTF pretty print array(#1)......unexpected pprint output
        expected: 0: {0,0,0,0x3,0x0,0x3,{0|[0,0,0,0,0,0,0,0]},ENUM_ZERO,4,0x1}
            read: 0: {0,0,0,0x3,0x0,0x3,{0|[0,0,0,0,0,0,0,0]},ENUM_ZERO,4,0x0}
      
        BTF pretty print array(#2)......unexpected pprint output
        expected: 0: {0,0,0,0x3,0x0,0x3,{0|[0,0,0,0,0,0,0,0]},ENUM_ZERO,4,0x1}
            read: 0: {0,0,0,0x3,0x0,0x3,{0|[0,0,0,0,0,0,0,0]},ENUM_ZERO,4,0x0}
      
        PASS:6 SKIP:0 FAIL:2
      
      With the kernel fix, the modified test will succeed:
        $ test_btf -p
        ......
        BTF pretty print array(#1)......OK
        BTF pretty print array(#2)......OK
        PASS:8 SKIP:0 FAIL:0
      
      Fixes: 9d5f9f70 ("bpf: btf: fix struct/union/fwd types with kind_flag")
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      e43207fa
  23. 20 12月, 2018 1 次提交
  24. 18 12月, 2018 3 次提交
    • Y
      tools/bpf: check precise {func, line, jited_line}_info_rec_size in test_btf · 0d7410ea
      Yonghong Song 提交于
      Current btf func_info, line_info and jited_line are designed to be
      extensible. The record sizes for {func,line}_info are passed to kernel,
      and the record sizes for {func,line,jited_line}_info are returned to
      userspace during bpf_prog_info query.
      
      In bpf selftests test_btf.c, when testing whether kernel returns
      a legitimate {func,line, jited_line)_info rec_size, the test only
      compares to the minimum allowed size. If the returned rec_size is smaller
      than the minimum allowed size, it is considered incorrect.
      The minimum allowed size for these three info sizes are equal to
      current value of sizeof(struct bpf_func_info), sizeof(struct bpf_line_info)
      and sizeof(__u64).
      
      The original thinking was that in the future when rec_size is increased
      in kernel, the same test should run correctly. But this sacrificed
      the precision of testing under the very kernel the test is shipped with,
      and bpf selftest is typically run with the same repo kernel.
      
      So this patch changed the testing of rec_size such that the
      kernel returned value should be equal to the size defined by
      tools uapi header bpf.h which syncs with kernel uapi header.
      
      Martin discovered a bug in one of rec_size comparisons.
      Instead of comparing to minimum func_info rec_size 8, it compares to 4.
      This patch fixed that issue as well.
      
      Fixes: 999d82cb ("tools/bpf: enhance test_btf file testing to test func info")
      Fixes: 05687352 ("bpf: Refactor and bug fix in test_func_type in test_btf.c")
      Fixes: 4d6304c7 ("bpf: Add unit tests for bpf_line_info")
      Suggested-by: NMartin KaFai Lau <kafai@fb.com>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      0d7410ea
    • Y
      tools/bpf: test kernel bpffs map pretty print with struct kind_flag · d0ebce68
      Yonghong Song 提交于
      The new tests are added to test bpffs map pretty print in kernel with kind_flag
      for structure type.
      
        $ test_btf -p
        ......
        BTF pretty print array(#1)......OK
        BTF pretty print array(#2)......OK
        PASS:8 SKIP:0 FAIL:0
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      d0ebce68
    • Y
      tools/bpf: add test_btf unit tests for kind_flag · cd9de5d3
      Yonghong Song 提交于
      This patch added unit tests for different types handling
      type->info.kind_flag. The following new tests are added:
        $ test_btf
        ...
        BTF raw test[82] (invalid int kind_flag): OK
        BTF raw test[83] (invalid ptr kind_flag): OK
        BTF raw test[84] (invalid array kind_flag): OK
        BTF raw test[85] (invalid enum kind_flag): OK
        BTF raw test[86] (valid fwd kind_flag): OK
        BTF raw test[87] (invalid typedef kind_flag): OK
        BTF raw test[88] (invalid volatile kind_flag): OK
        BTF raw test[89] (invalid const kind_flag): OK
        BTF raw test[90] (invalid restrict kind_flag): OK
        BTF raw test[91] (invalid func kind_flag): OK
        BTF raw test[92] (invalid func_proto kind_flag): OK
        BTF raw test[93] (valid struct kind_flag, bitfield_size = 0): OK
        BTF raw test[94] (valid struct kind_flag, int member, bitfield_size != 0): OK
        BTF raw test[95] (valid union kind_flag, int member, bitfield_size != 0): OK
        BTF raw test[96] (valid struct kind_flag, enum member, bitfield_size != 0): OK
        BTF raw test[97] (valid union kind_flag, enum member, bitfield_size != 0): OK
        BTF raw test[98] (valid struct kind_flag, typedef member, bitfield_size != 0): OK
        BTF raw test[99] (valid union kind_flag, typedef member, bitfield_size != 0): OK
        BTF raw test[100] (invalid struct type, bitfield_size greater than struct size): OK
        BTF raw test[101] (invalid struct type, kind_flag bitfield base_type int not regular): OK
        BTF raw test[102] (invalid struct type, kind_flag base_type int not regular): OK
        BTF raw test[103] (invalid union type, bitfield_size greater than struct size): OK
        ...
        PASS:122 SKIP:0 FAIL:0
      
      The second parameter name of macro
        BTF_INFO_ENC(kind, root, vlen)
      in selftests test_btf.c is also renamed from "root" to "kind_flag".
      Note that before this patch "root" is not used and always 0.
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      cd9de5d3
  25. 13 12月, 2018 1 次提交
  26. 11 12月, 2018 1 次提交
  27. 10 12月, 2018 2 次提交
    • M
      bpf: Add unit tests for bpf_line_info · 4d6304c7
      Martin KaFai Lau 提交于
      Add unit tests for bpf_line_info for both BPF_PROG_LOAD and
      BPF_OBJ_GET_INFO_BY_FD.
      
      jit enabled:
      [root@arch-fb-vm1 bpf]# ./test_btf -k 0
      BTF prog info raw test[5] (line_info (No subprog)): OK
      BTF prog info raw test[6] (line_info (No subprog. insn_off >= prog->len)): OK
      BTF prog info raw test[7] (line_info (No subprog. zero tailing line_info): OK
      BTF prog info raw test[8] (line_info (No subprog. nonzero tailing line_info)): OK
      BTF prog info raw test[9] (line_info (subprog)): OK
      BTF prog info raw test[10] (line_info (subprog + func_info)): OK
      BTF prog info raw test[11] (line_info (subprog. missing 1st func line info)): OK
      BTF prog info raw test[12] (line_info (subprog. missing 2nd func line info)): OK
      BTF prog info raw test[13] (line_info (subprog. unordered insn offset)): OK
      
      jit disabled:
      BTF prog info raw test[5] (line_info (No subprog)): not jited. skipping jited_line_info check. OK
      BTF prog info raw test[6] (line_info (No subprog. insn_off >= prog->len)): OK
      BTF prog info raw test[7] (line_info (No subprog. zero tailing line_info): not jited. skipping jited_line_info check. OK
      BTF prog info raw test[8] (line_info (No subprog. nonzero tailing line_info)): OK
      BTF prog info raw test[9] (line_info (subprog)): not jited. skipping jited_line_info check. OK
      BTF prog info raw test[10] (line_info (subprog + func_info)): not jited. skipping jited_line_info check. OK
      BTF prog info raw test[11] (line_info (subprog. missing 1st func line info)): OK
      BTF prog info raw test[12] (line_info (subprog. missing 2nd func line info)): OK
      BTF prog info raw test[13] (line_info (subprog. unordered insn offset)): OK
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      4d6304c7
    • M
      bpf: Refactor and bug fix in test_func_type in test_btf.c · 05687352
      Martin KaFai Lau 提交于
      1) bpf_load_program_xattr() is absorbing the EBIG error
         which makes testing this case impossible.  It is replaced
         with a direct syscall(__NR_bpf, BPF_PROG_LOAD,...).
      2) The test_func_type() is renamed to test_info_raw() to
         prepare for the new line_info test in the next patch.
      3) The bpf_obj_get_info_by_fd() testing for func_info
         is refactored to test_get_finfo().  A new
         test_get_linfo() will be added in the next patch
         for testing line_info purpose.
      4) The test->func_info_cnt is checked instead of
         a static value "2".
      5) Remove unnecessary "\n" in error message.
      6) Adding back info_raw_test_num to the cmd arg such
         that a specific test case can be tested, like
         all other existing tests.
      
      7) Fix a bug in handling expected_prog_load_failure.
         A test could pass even if prog_fd != -1 while
         expected_prog_load_failure is true.
      8) The min rec_size check should be < 8 instead of < 4.
      
      Fixes: 4798c4ba ("tools/bpf: extends test_btf to test load/retrieve func_type info")
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      05687352
  28. 06 12月, 2018 1 次提交
  29. 29 11月, 2018 2 次提交
    • Y
      tools/bpf: add addition type tests to test_btf · d0848912
      Yonghong Song 提交于
      The following additional unit testcases are added to test_btf:
      ...
      BTF raw test[42] (typedef (invalid name, name_off = 0)): OK
      BTF raw test[43] (typedef (invalid name, invalid identifier)): OK
      BTF raw test[44] (ptr type (invalid name, name_off <> 0)): OK
      BTF raw test[45] (volatile type (invalid name, name_off <> 0)): OK
      BTF raw test[46] (const type (invalid name, name_off <> 0)): OK
      BTF raw test[47] (restrict type (invalid name, name_off <> 0)): OK
      BTF raw test[48] (fwd type (invalid name, name_off = 0)): OK
      BTF raw test[49] (fwd type (invalid name, invalid identifier)): OK
      BTF raw test[50] (array type (invalid name, name_off <> 0)): OK
      BTF raw test[51] (struct type (name_off = 0)): OK
      BTF raw test[52] (struct type (invalid name, invalid identifier)): OK
      BTF raw test[53] (struct member (name_off = 0)): OK
      BTF raw test[54] (struct member (invalid name, invalid identifier)): OK
      BTF raw test[55] (enum type (name_off = 0)): OK
      BTF raw test[56] (enum type (invalid name, invalid identifier)): OK
      BTF raw test[57] (enum member (invalid name, name_off = 0)): OK
      BTF raw test[58] (enum member (invalid name, invalid identifier)): OK
      ...
      
      Fixes: c0fa1b6c ("bpf: btf: Add BTF tests")
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      d0848912
    • M
      tools/bpf: fix two test_btf unit test cases · 8800cd03
      Martin KaFai Lau 提交于
      There are two unit test cases, which should encode
      TYPEDEF type, but instead encode PTR type.
      The error is flagged out after enforcing name
      checking in the previous patch.
      
      Fixes: c0fa1b6c ("bpf: btf: Add BTF tests")
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      8800cd03
  30. 27 11月, 2018 2 次提交