1. 21 12月, 2018 17 次提交
  2. 20 12月, 2018 6 次提交
  3. 19 12月, 2018 7 次提交
  4. 18 12月, 2018 10 次提交
    • D
      Merge branch 'bpf-bpftool-mount-tracefs' · a137401d
      Daniel Borkmann 提交于
      Quentin Monnet says:
      
      ====================
      This series focus on mounting (or not mounting) tracefs with bpftool.
      
      First patch makes bpftool attempt to mount tracefs if tracefs is not
      found when running "bpftool prog tracelog".
      
      Second patch adds an option to bpftool to prevent it from attempting
      to mount any file system (tracefs or bpffs), in case this behaviour
      is undesirable for some users.
      ====================
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      a137401d
    • Q
      tools: bpftool: add an option to prevent auto-mount of bpffs, tracefs · 33221307
      Quentin Monnet 提交于
      In order to make life easier for users, bpftool automatically attempts
      to mount the BPF virtual file system, if it is not mounted already,
      before trying to pin objects in it. Similarly, it attempts to mount
      tracefs if necessary before trying to dump the trace pipe to the
      console.
      
      While mounting file systems on-the-fly can improve user experience, some
      administrators might prefer to avoid that. Let's add an option to block
      these mount attempts. Note that it does not prevent automatic mounting
      of tracefs by debugfs for the "bpftool prog tracelog" command.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      33221307
    • Q
      tools: bpftool: attempt to mount tracefs if required for tracelog cmd · be3245e2
      Quentin Monnet 提交于
      As a follow-up to commit 30da46b5 ("tools: bpftool: add a command to
      dump the trace pipe"), attempt to mount the tracefs virtual file system
      if it is not detected on the system before trying to dump content of the
      tracing pipe on an invocation of "bpftool prog tracelog".
      
      Usually, tracefs in automatically mounted by debugfs when the user tries
      to access it (e.g. "ls /sys/kernel/debug/tracing" mounts the tracefs).
      So if we failed to find it, it is probably that debugfs is not here
      either. Therefore, we just attempt a single mount, at a location that
      does not involve debugfs: /sys/kernel/tracing.
      Suggested-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      be3245e2
    • 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
    • P
      bpf: libbpf: fix memleak by freeing line_info · 07a09d1b
      Prashant Bhole 提交于
      This patch fixes a memory leak in libbpf by freeing up line_info
      member of struct bpf_program while unloading a program.
      
      Fixes: 3d650141 ("bpf: libbpf: Add btf_line_info support to libbpf")
      Signed-off-by: NPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      07a09d1b
    • D
      Merge branch 'bpf-btf-type-fixes' · 37c7b1ca
      Daniel Borkmann 提交于
      Yonghong Song says:
      
      ====================
      Commit 69b693f0 ("bpf: btf: Introduce BPF Type Format (BTF)")
      introduced BTF, a debug info format for BTF.
      
      The original design has a couple of issues though.
      First, the bitfield size is only encoded in int type.
      If the struct member bitfield type is enum, pahole ([1])
      or llvm is forced to replace enum with int type. As a result, the original
      type information gets lost.
      
      Second, the original BTF design does not envision the possibility of
      BTF=>header_file conversion ([2]), hence does not encode "struct" or
      "union" info for a forward type. Such information is necessary to
      convert BTF to a header file.
      
      This patch set fixed the issue by introducing kind_flag, using one bit
      in type->info. When kind_flag, the struct/union btf_member->offset
      will encode both bitfield_size and bit_offset, covering both
      int and enum base types. The kind_flag is also used to indicate whether
      the forward type is a union (when set) or a struct.
      
      Patch #1 refactors function btf_int_bits_seq_show() so Patch #2
      can reuse part of the function.
      Patch #2 implemented kind_flag support for struct/union/fwd types.
      Patch #3 added kind_flag support for cgroup local storage map pretty print.
      Patch #4 syncs kernel uapi btf.h to tools directory.
      Patch #5 added unit tests for kind_flag.
      Patch #6 added tests for kernel bpffs based pretty print with kind_flag.
      Patch #7 refactors function btf_dumper_int_bits() so Patch #8
      can reuse part of the function.
      Patch #8 added bpftool support of pretty print with kind_flag set.
      
        [1] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=b18354f64cc215368c3bc0df4a7e5341c55c378c
        [2] https://lwn.net/SubscriberLink/773198/fe3074838f5c3f26/
      
      Change logs:
        v2 -> v3:
          . Relocated comments about bitfield_size/bit_offset interpretation
            of the "offset" field right before the "offset" struct member.
          . Added missing byte alignment checking for non-bitfield enum
            member of a struct with kind_flag set.
          . Added two test cases in unit tests for struct type, kind_flag set,
            non-bitfield int/enum member, not-byte aligned bit offsets.
          . Added comments to help understand there is no overflow for
            total_bits_offset in bpftool function btf_dumper_int_bits().
          . Added explanation of typedef type dumping fix in Patch #8 commit
            message.
      
        v1 -> v2:
          . If kind_flag is set for a structure, ensure an int member,
            whether it is a bitfield or not, is a regular int type.
          . Added support so cgroup local storage map pretty print
            works with kind_flag.
      ====================
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      37c7b1ca
    • Y
      tools: bpftool: support pretty print with kind_flag set · 8772c8bc
      Yonghong Song 提交于
      The following example shows map pretty print with structures
      which include bitfield members.
      
        enum A { A1, A2, A3, A4, A5 };
        typedef enum A ___A;
        struct tmp_t {
             char a1:4;
             int  a2:4;
             int  :4;
             __u32 a3:4;
             int b;
             ___A b1:4;
             enum A b2:4;
        };
        struct bpf_map_def SEC("maps") tmpmap = {
             .type = BPF_MAP_TYPE_ARRAY,
             .key_size = sizeof(__u32),
             .value_size = sizeof(struct tmp_t),
             .max_entries = 1,
        };
        BPF_ANNOTATE_KV_PAIR(tmpmap, int, struct tmp_t);
      
      and the following map update in the bpf program:
      
        key = 0;
        struct tmp_t t = {};
        t.a1 = 2;
        t.a2 = 4;
        t.a3 = 6;
        t.b = 7;
        t.b1 = 8;
        t.b2 = 10;
        bpf_map_update_elem(&tmpmap, &key, &t, 0);
      
      With this patch, I am able to print out the map values
      correctly with this patch:
      bpftool map dump id 187
        [{
              "key": 0,
              "value": {
                  "a1": 0x2,
                  "a2": 0x4,
                  "a3": 0x6,
                  "b": 7,
                  "b1": 0x8,
                  "b2": 0xa
              }
          }
        ]
      
      Previously, if a function prototype argument has a typedef
      type, the prototype is not printed since
      function __btf_dumper_type_only() bailed out with error
      if the type is a typedef. This commit corrected this
      behavior by printing out typedef properly.
      
      The following example shows forward type and
      typedef type can be properly printed in function prototype
      with modified test_btf_haskv.c.
      
        struct t;
        union  u;
      
        __attribute__((noinline))
        static int test_long_fname_1(struct dummy_tracepoint_args *arg,
                                     struct t *p1, union u *p2,
                                     __u32 unused)
        ...
        int _dummy_tracepoint(struct dummy_tracepoint_args *arg) {
          return test_long_fname_1(arg, 0, 0, 0);
        }
      
        $ bpftool p d xlated id 24
        ...
        int test_long_fname_1(struct dummy_tracepoint_args * arg,
                              struct t * p1, union u * p2,
                              __u32 unused)
        ...
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      8772c8bc
    • Y
      tools: bpftool: refactor btf_dumper_int_bits() · 9f95e37e
      Yonghong Song 提交于
      The core dump funcitonality in btf_dumper_int_bits() is
      refactored into a separate function btf_dumper_bitfield()
      which will be used by the next patch.
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      9f95e37e
    • 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