1. 22 7月, 2020 1 次提交
  2. 25 6月, 2020 2 次提交
  3. 23 6月, 2020 3 次提交
  4. 20 5月, 2020 1 次提交
  5. 12 5月, 2020 1 次提交
  6. 10 5月, 2020 1 次提交
    • Y
      tools/bpftool: Add bpf_iter support for bptool · 9406b485
      Yonghong Song 提交于
      Currently, only one command is supported
        bpftool iter pin <bpf_prog.o> <path>
      
      It will pin the trace/iter bpf program in
      the object file <bpf_prog.o> to the <path>
      where <path> should be on a bpffs mount.
      
      For example,
        $ bpftool iter pin ./bpf_iter_ipv6_route.o \
          /sys/fs/bpf/my_route
      User can then do a `cat` to print out the results:
        $ cat /sys/fs/bpf/my_route
          fe800000000000000000000000000000 40 00000000000000000000000000000000 ...
          00000000000000000000000000000000 00 00000000000000000000000000000000 ...
          00000000000000000000000000000001 80 00000000000000000000000000000000 ...
          fe800000000000008c0162fffebdfd57 80 00000000000000000000000000000000 ...
          ff000000000000000000000000000000 08 00000000000000000000000000000000 ...
          00000000000000000000000000000000 00 00000000000000000000000000000000 ...
      
      The implementation for ipv6_route iterator is in one of subsequent
      patches.
      
      This patch also added BPF_LINK_TYPE_ITER to link query.
      
      In the future, we may add additional parameters to pin command
      by parameterizing the bpf iterator. For example, a map_id or pid
      may be added to let bpf program only traverses a single map or task,
      similar to kernel seq_file single_open().
      
      We may also add introspection command for targets/iterators by
      leveraging the bpf_iter itself.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200509175920.2477247-1-yhs@fb.com
      9406b485
  7. 29 4月, 2020 2 次提交
  8. 20 3月, 2020 2 次提交
    • M
      bpftool: Add struct_ops support · 65c93628
      Martin KaFai Lau 提交于
      This patch adds struct_ops support to the bpftool.
      
      To recap a bit on the recent bpf_struct_ops feature on the kernel side:
      It currently supports "struct tcp_congestion_ops" to be implemented
      in bpf.  At a high level, bpf_struct_ops is struct_ops map populated
      with a number of bpf progs.  bpf_struct_ops currently supports the
      "struct tcp_congestion_ops".  However, the bpf_struct_ops design is
      generic enough that other kernel struct ops can be supported in
      the future.
      
      Although struct_ops is map+progs at a high lever, there are differences
      in details.  For example,
      1) After registering a struct_ops, the struct_ops is held by the kernel
         subsystem (e.g. tcp-cc).  Thus, there is no need to pin a
         struct_ops map or its progs in order to keep them around.
      2) To iterate all struct_ops in a system, it iterates all maps
         in type BPF_MAP_TYPE_STRUCT_OPS.  BPF_MAP_TYPE_STRUCT_OPS is
         the current usual filter.  In the future, it may need to
         filter by other struct_ops specific properties.  e.g. filter by
         tcp_congestion_ops or other kernel subsystem ops in the future.
      3) struct_ops requires the running kernel having BTF info.  That allows
         more flexibility in handling other kernel structs.  e.g. it can
         always dump the latest bpf_map_info.
      4) Also, "struct_ops" command is not intended to repeat all features
         already provided by "map" or "prog".  For example, if there really
         is a need to pin the struct_ops map, the user can use the "map" cmd
         to do that.
      
      While the first attempt was to reuse parts from map/prog.c,  it ended up
      not a lot to share.  The only obvious item is the map_parse_fds() but
      that still requires modifications to accommodate struct_ops map specific
      filtering (for the immediate and the future needs).  Together with the
      earlier mentioned differences, it is better to part away from map/prog.c.
      
      The initial set of subcmds are, register, unregister, show, and dump.
      
      For register, it registers all struct_ops maps that can be found in an
      obj file.  Option can be added in the future to specify a particular
      struct_ops map.  Also, the common bpf_tcp_cc is stateless (e.g.
      bpf_cubic.c and bpf_dctcp.c).  The "reuse map" feature is not
      implemented in this patch and it can be considered later also.
      
      For other subcmds, please see the man doc for details.
      
      A sample output of dump:
      [root@arch-fb-vm1 bpf]# bpftool struct_ops dump name cubic
      [{
              "bpf_map_info": {
                  "type": 26,
                  "id": 64,
                  "key_size": 4,
                  "value_size": 256,
                  "max_entries": 1,
                  "map_flags": 0,
                  "name": "cubic",
                  "ifindex": 0,
                  "btf_vmlinux_value_type_id": 18452,
                  "netns_dev": 0,
                  "netns_ino": 0,
                  "btf_id": 52,
                  "btf_key_type_id": 0,
                  "btf_value_type_id": 0
              }
          },{
              "bpf_struct_ops_tcp_congestion_ops": {
                  "refcnt": {
                      "refs": {
                          "counter": 1
                      }
                  },
                  "state": "BPF_STRUCT_OPS_STATE_INUSE",
                  "data": {
                      "list": {
                          "next": 0,
                          "prev": 0
                      },
                      "key": 0,
                      "flags": 0,
                      "init": "void (struct sock *) bictcp_init/prog_id:138",
                      "release": "void (struct sock *) 0",
                      "ssthresh": "u32 (struct sock *) bictcp_recalc_ssthresh/prog_id:141",
                      "cong_avoid": "void (struct sock *, u32, u32) bictcp_cong_avoid/prog_id:140",
                      "set_state": "void (struct sock *, u8) bictcp_state/prog_id:142",
                      "cwnd_event": "void (struct sock *, enum tcp_ca_event) bictcp_cwnd_event/prog_id:139",
                      "in_ack_event": "void (struct sock *, u32) 0",
                      "undo_cwnd": "u32 (struct sock *) tcp_reno_undo_cwnd/prog_id:144",
                      "pkts_acked": "void (struct sock *, const struct ack_sample *) bictcp_acked/prog_id:143",
                      "min_tso_segs": "u32 (struct sock *) 0",
                      "sndbuf_expand": "u32 (struct sock *) 0",
                      "cong_control": "void (struct sock *, const struct rate_sample *) 0",
                      "get_info": "size_t (struct sock *, u32, int *, union tcp_cc_info *) 0",
                      "name": "bpf_cubic",
                      "owner": 0
                  }
              }
          }
      ]
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200318171656.129650-1-kafai@fb.com
      65c93628
    • M
      bpftool: Translate prog_id to its bpf prog_name · d5ae04da
      Martin KaFai Lau 提交于
      The kernel struct_ops obj has kernel's func ptrs implemented by bpf_progs.
      The bpf prog_id is stored as the value of the func ptr for introspection
      purpose.  In the latter patch, a struct_ops dump subcmd will be added
      to introspect these func ptrs.  It is desired to print the actual bpf
      prog_name instead of only printing the prog_id.
      
      Since struct_ops is the only usecase storing prog_id in the func ptr,
      this patch adds a prog_id_as_func_ptr bool (default is false) to
      "struct btf_dumper" in order not to mis-interpret the ptr value
      for the other existing use-cases.
      
      While printing a func_ptr as a bpf prog_name,
      this patch also prefix the bpf prog_name with the ptr's func_proto.
      [ Note that it is the ptr's func_proto instead of the bpf prog's
        func_proto ]
      It reuses the current btf_dump_func() to obtain the ptr's func_proto
      string.
      
      Here is an example from the bpf_cubic.c:
      "void (struct sock *, u32, u32) bictcp_cong_avoid/prog_id:140"
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200318171650.129252-1-kafai@fb.com
      d5ae04da
  9. 14 3月, 2020 1 次提交
    • Q
      tools: bpftool: Restore message on failure to guess program type · 6ae32b29
      Quentin Monnet 提交于
      In commit 4a3d6c6a ("libbpf: Reduce log level for custom section
      names"), log level for messages for libbpf_attach_type_by_name() and
      libbpf_prog_type_by_name() was downgraded from "info" to "debug". The
      latter function, in particular, is used by bpftool when attempting to
      load programs, and this change caused bpftool to exit with no hint or
      error message when it fails to detect the type of the program to load
      (unless "-d" option was provided).
      
      To help users understand why bpftool fails to load the program, let's do
      a second run of the function with log level in "debug" mode in case of
      failure.
      
      Before:
      
          # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          # echo $?
          255
      
      Or really verbose with -d flag:
      
          # bpftool -d prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          libbpf: loading sample_ret0.o
          libbpf: section(1) .strtab, size 134, link 0, flags 0, type=3
          libbpf: skip section(1) .strtab
          libbpf: section(2) .text, size 16, link 0, flags 6, type=1
          libbpf: found program .text
          libbpf: section(3) .debug_abbrev, size 55, link 0, flags 0, type=1
          libbpf: skip section(3) .debug_abbrev
          libbpf: section(4) .debug_info, size 75, link 0, flags 0, type=1
          libbpf: skip section(4) .debug_info
          libbpf: section(5) .rel.debug_info, size 32, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_info(5) for section(4)
          libbpf: section(6) .debug_str, size 150, link 0, flags 30, type=1
          libbpf: skip section(6) .debug_str
          libbpf: section(7) .BTF, size 155, link 0, flags 0, type=1
          libbpf: section(8) .BTF.ext, size 80, link 0, flags 0, type=1
          libbpf: section(9) .rel.BTF.ext, size 32, link 14, flags 0, type=9
          libbpf: skip relo .rel.BTF.ext(9) for section(8)
          libbpf: section(10) .debug_frame, size 40, link 0, flags 0, type=1
          libbpf: skip section(10) .debug_frame
          libbpf: section(11) .rel.debug_frame, size 16, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_frame(11) for section(10)
          libbpf: section(12) .debug_line, size 74, link 0, flags 0, type=1
          libbpf: skip section(12) .debug_line
          libbpf: section(13) .rel.debug_line, size 16, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_line(13) for section(12)
          libbpf: section(14) .symtab, size 96, link 1, flags 0, type=2
          libbpf: looking for externs among 4 symbols...
          libbpf: collected 0 externs total
          libbpf: failed to guess program type from ELF section '.text'
          libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]
      
      After:
      
          # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          libbpf: failed to guess program type from ELF section '.text'
          libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20200311021205.9755-1-quentin@isovalent.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      6ae32b29
  10. 13 3月, 2020 1 次提交
  11. 26 2月, 2020 1 次提交
  12. 16 12月, 2019 3 次提交
    • A
      bpftool: Add skeleton codegen command · 985ead41
      Andrii Nakryiko 提交于
      Add `bpftool gen skeleton` command, which takes in compiled BPF .o object file
      and dumps a BPF skeleton struct and related code to work with that skeleton.
      Skeleton itself is tailored to a specific structure of provided BPF object
      file, containing accessors (just plain struct fields) for every map and
      program, as well as dedicated space for bpf_links. If BPF program is using
      global variables, corresponding structure definitions of compatible memory
      layout are emitted as well, making it possible to initialize and subsequently
      read/update global variables values using simple and clear C syntax for
      accessing fields. This skeleton majorly improves usability of
      opening/loading/attaching of BPF object, as well as interacting with it
      throughout the lifetime of loaded BPF object.
      
      Generated skeleton struct has the following structure:
      
      struct <object-name> {
      	/* used by libbpf's skeleton API */
      	struct bpf_object_skeleton *skeleton;
      	/* bpf_object for libbpf APIs */
      	struct bpf_object *obj;
      	struct {
      		/* for every defined map in BPF object: */
      		struct bpf_map *<map-name>;
      	} maps;
      	struct {
      		/* for every program in BPF object: */
      		struct bpf_program *<program-name>;
      	} progs;
      	struct {
      		/* for every program in BPF object: */
      		struct bpf_link *<program-name>;
      	} links;
      	/* for every present global data section: */
      	struct <object-name>__<one of bss, data, or rodata> {
      		/* memory layout of corresponding data section,
      		 * with every defined variable represented as a struct field
      		 * with exactly the same type, but without const/volatile
      		 * modifiers, e.g.:
      		 */
      		 int *my_var_1;
      		 ...
      	} *<one of bss, data, or rodata>;
      };
      
      This provides great usability improvements:
      - no need to look up maps and programs by name, instead just
        my_obj->maps.my_map or my_obj->progs.my_prog would give necessary
        bpf_map/bpf_program pointers, which user can pass to existing libbpf APIs;
      - pre-defined places for bpf_links, which will be automatically populated for
        program types that libbpf knows how to attach automatically (currently
        tracepoints, kprobe/kretprobe, raw tracepoint and tracing programs). On
        tearing down skeleton, all active bpf_links will be destroyed (meaning BPF
        programs will be detached, if they are attached). For cases in which libbpf
        doesn't know how to auto-attach BPF program, user can manually create link
        after loading skeleton and they will be auto-detached on skeleton
        destruction:
      
      	my_obj->links.my_fancy_prog = bpf_program__attach_cgroup_whatever(
      		my_obj->progs.my_fancy_prog, <whatever extra param);
      
      - it's extremely easy and convenient to work with global data from userspace
        now. Both for read-only and read/write variables, it's possible to
        pre-initialize them before skeleton is loaded:
      
      	skel = my_obj__open(raw_embed_data);
      	my_obj->rodata->my_var = 123;
      	my_obj__load(skel); /* 123 will be initialization value for my_var */
      
        After load, if kernel supports mmap() for BPF arrays, user can still read
        (and write for .bss and .data) variables values, but at that point it will
        be directly mmap()-ed to BPF array, backing global variables. This allows to
        seamlessly exchange data with BPF side. From userspace program's POV, all
        the pointers and memory contents stay the same, but mapped kernel memory
        changes to point to created map.
        If kernel doesn't yet support mmap() for BPF arrays, it's still possible to
        use those data section structs to pre-initialize .bss, .data, and .rodata,
        but after load their pointers will be reset to NULL, allowing user code to
        gracefully handle this condition, if necessary.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Link: https://lore.kernel.org/bpf/20191214014341.3442258-14-andriin@fb.com
      985ead41
    • P
      bpftool: Match maps by name · 99f9863a
      Paul Chaignon 提交于
      This patch implements lookup by name for maps and changes the behavior of
      lookups by tag to be consistent with prog subcommands.  Similarly to
      program subcommands, the show and dump commands will return all maps with
      the given name (or tag), whereas other commands will error out if several
      maps have the same name (resp. tag).
      
      When a map has BTF info, it is dumped in JSON with available BTF info.
      This patch requires that all matched maps have BTF info before switching
      the output format to JSON.
      Signed-off-by: NPaul Chaignon <paul.chaignon@orange.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/8de1c9f273860b3ea1680502928f4da2336b853e.1576263640.git.paul.chaignon@gmail.com
      99f9863a
    • P
      bpftool: Match programs by name · a7d22ca2
      Paul Chaignon 提交于
      When working with frequently modified BPF programs, both the ID and the
      tag may change.  bpftool currently doesn't provide a "stable" way to match
      such programs.
      
      This patch implements lookup by name for programs.  The show and dump
      commands will return all programs with the given name, whereas other
      commands will error out if several programs have the same name.
      Signed-off-by: NPaul Chaignon <paul.chaignon@orange.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Link: https://lore.kernel.org/bpf/b5fc1a5dcfaeb5f16fc80295cdaa606dd2d91534.1576263640.git.paul.chaignon@gmail.com
      a7d22ca2
  13. 08 10月, 2019 1 次提交
  14. 16 8月, 2019 1 次提交
  15. 12 7月, 2019 1 次提交
  16. 06 7月, 2019 1 次提交
    • Q
      tools: bpftool: add "prog run" subcommand to test-run programs · ba95c745
      Quentin Monnet 提交于
      Add a new "bpftool prog run" subcommand to run a loaded program on input
      data (and possibly with input context) passed by the user.
      
      Print output data (and output context if relevant) into a file or into
      the console. Print return value and duration for the test run into the
      console.
      
      A "repeat" argument can be passed to run the program several times in a
      row.
      
      The command does not perform any kind of verification based on program
      type (Is this program type allowed to use an input context?) or on data
      consistency (Can I work with empty input data?), this is left to the
      kernel.
      
      Example invocation:
      
          # perl -e 'print "\x0" x 14' | ./bpftool prog run \
                  pinned /sys/fs/bpf/sample_ret0 \
                  data_in - data_out - repeat 5
          0000000 0000 0000 0000 0000 0000 0000 0000      | ........ ......
          Return value: 0, duration (average): 260ns
      
      When one of data_in or ctx_in is "-", bpftool reads from standard input,
      in binary format. Other formats (JSON, hexdump) might be supported (via
      an optional command line keyword like "data_fmt_in") in the future if
      relevant, but this would require doing more parsing in bpftool.
      
      v2:
      - Fix argument names for function check_single_stdin(). (Yonghong)
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      ba95c745
  17. 28 6月, 2019 1 次提交
  18. 28 5月, 2019 1 次提交
    • Q
      tools: bpftool: make -d option print debug output from verifier · 55d77807
      Quentin Monnet 提交于
      The "-d" option is used to require all logs available for bpftool. So
      far it meant telling libbpf to print even debug-level information. But
      there is another source of info that can be made more verbose: when we
      attemt to load programs with bpftool, we can pass a log_level parameter
      to the verifier in order to control the amount of information that is
      printed to the console.
      
      Reuse the "-d" option to print all information the verifier can tell. At
      this time, this means logs related to BPF_LOG_LEVEL1, BPF_LOG_LEVEL2 and
      BPF_LOG_STATS. As mentioned in the discussion on the first version of
      this set, these macros are internal to the kernel
      (include/linux/bpf_verifier.h) and are not meant to be part of the
      stable user API, therefore we simply use the related constants to print
      whatever we can at this time, without trying to tell users what is
      log_level1 or what is statistics.
      
      Verifier logs are only used when loading programs for now (In the
      future: for loading BTF objects with bpftool? Although libbpf does not
      currently offer to print verifier info at debug level if no error
      occurred when loading BTF objects), so bpftool.rst and bpftool-prog.rst
      are the only man pages to get the update.
      
      v3:
      - Add details on log level and BTF loading at the end of commit log.
      
      v2:
      - Remove the possibility to select the log levels to use (v1 offered a
        combination of "log_level1", "log_level2" and "stats").
      - The macros from kernel header bpf_verifier.h are not used (and
        therefore not moved to UAPI header).
      - In v1 this was a distinct option, but is now merged in the only "-d"
        switch to activate libbpf and verifier debug-level logs all at the
        same time.
      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>
      55d77807
  19. 26 4月, 2019 1 次提交
    • A
      bpftool: add ability to dump BTF types · c93cc690
      Andrii Nakryiko 提交于
      Add new `btf dump` sub-command to bpftool. It allows to dump
      human-readable low-level BTF types representation of BTF types. BTF can
      be retrieved from few different sources:
        - from BTF object by ID;
        - from PROG, if it has associated BTF;
        - from MAP, if it has associated BTF data; it's possible to narrow
          down types to either key type, value type, both, or all BTF types;
        - from ELF file (.BTF section).
      
      Output format mostly follows BPF verifier log format with few notable
      exceptions:
        - all the type/field/param/etc names are enclosed in single quotes to
          allow easier grepping and to stand out a little bit more;
        - FUNC_PROTO output follows STRUCT/UNION/ENUM format of having one
          line per each argument; this is more uniform and allows easy
          grepping, as opposed to succinct, but inconvenient format that BPF
          verifier log is using.
      
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Alexei Starovoitov <ast@fb.com>
      Cc: Yonghong Song <yhs@fb.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      c93cc690
  20. 17 4月, 2019 1 次提交
    • A
      bpftool: Support sysctl hook · f25377ee
      Andrey Ignatov 提交于
      Add support for recently added BPF_PROG_TYPE_CGROUP_SYSCTL program type
      and BPF_CGROUP_SYSCTL attach type.
      
      Example of bpftool output with sysctl program from selftests:
      
        # bpftool p load ./test_sysctl_prog.o /mnt/bpf/sysctl_prog type cgroup/sysctl
        # bpftool p l
        9: cgroup_sysctl  name sysctl_tcp_mem  tag 0dd05f81a8d0d52e  gpl
                loaded_at 2019-04-16T12:57:27-0700  uid 0
                xlated 1008B  jited 623B  memlock 4096B
        # bpftool c a /mnt/cgroup2/bla sysctl id 9
        # bpftool c t
        CgroupPath
        ID       AttachType      AttachFlags     Name
        /mnt/cgroup2/bla
            9        sysctl                          sysctl_tcp_mem
        # bpftool c d /mnt/cgroup2/bla sysctl id 9
        # bpftool c t
        CgroupPath
        ID       AttachType      AttachFlags     Name
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      f25377ee
  21. 23 1月, 2019 2 次提交
    • Q
      tools: bpftool: add probes for eBPF map types · f99e1663
      Quentin Monnet 提交于
      Add new probes for eBPF map types, to detect what are the ones available
      on the system. Try creating one map of each type, and see if the kernel
      complains.
      
      Sample output:
      
          # bpftool feature probe kernel
          ...
          Scanning eBPF map types...
          eBPF map_type hash is available
          eBPF map_type array is available
          eBPF map_type prog_array is available
          ...
      
          # bpftool --json --pretty feature probe kernel
          {
              ...
              "map_types": {
                  "have_hash_map_type": true,
                  "have_array_map_type": true,
                  "have_prog_array_map_type": true,
                  ...
              }
          }
      
      v5:
      - In libbpf.map, move global symbol to the new LIBBPF_0.0.2 section.
      
      v3:
      - Use a switch with all enum values for setting specific map parameters,
        so that gcc complains at compile time (-Wswitch-enum) if new map types
        were added to the kernel but libbpf was not updated.
      
      v2:
      - Move probes from bpftool to libbpf.
      - Remove C-style macros output from this patch.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      f99e1663
    • Q
      tools: bpftool: add basic probe capability, probe syscall availability · 49eb7ab3
      Quentin Monnet 提交于
      Add a new component and command for bpftool, in order to probe the
      system to dump a set of eBPF-related parameters so that users can know
      what features are available on the system.
      
      Parameters are dumped in plain or JSON output (with -j/-p options).
      
      The current patch introduces probing of one simple parameter:
      availability of the bpf() system call. Later commits
      will add other probes.
      
      Sample output:
      
          # bpftool feature probe kernel
          Scanning system call availability...
          bpf() syscall is available
      
          # bpftool --json --pretty feature probe kernel
          {
              "syscall_config": {
                  "have_bpf_syscall": true
              }
          }
      
      The optional "kernel" keyword enforces probing of the current system,
      which is the only possible behaviour at this stage. It can be safely
      omitted.
      
      The feature comes with the relevant man page, but bash completion will
      come in a dedicated commit.
      
      v3:
      - Do not probe kernel version. Contrarily to what is written below for
        v2, we can have the kernel version retrieved in libbpf instead of
        bpftool (in the patch adding probing for program types).
      
      v2:
      - Remove C-style macros output from this patch.
      - Even though kernel version is no longer needed for testing kprobes
        availability, note that we still collect it in this patch so that
        bpftool gets able to probe (in next patches) older kernels as well.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      49eb7ab3
  22. 18 12月, 2018 2 次提交
  23. 15 12月, 2018 1 次提交
  24. 13 12月, 2018 1 次提交
  25. 11 12月, 2018 1 次提交
  26. 10 12月, 2018 1 次提交
    • M
      bpf: libbpf: bpftool: Print bpf_line_info during prog dump · b053b439
      Martin KaFai Lau 提交于
      This patch adds print bpf_line_info function in 'prog dump jitted'
      and 'prog dump xlated':
      
      [root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv
      [...]
      int test_long_fname_2(struct dummy_tracepoint_args * arg):
      bpf_prog_44a040bf25481309_test_long_fname_2:
      ; static int test_long_fname_2(struct dummy_tracepoint_args *arg)
         0:	push   %rbp
         1:	mov    %rsp,%rbp
         4:	sub    $0x30,%rsp
         b:	sub    $0x28,%rbp
         f:	mov    %rbx,0x0(%rbp)
        13:	mov    %r13,0x8(%rbp)
        17:	mov    %r14,0x10(%rbp)
        1b:	mov    %r15,0x18(%rbp)
        1f:	xor    %eax,%eax
        21:	mov    %rax,0x20(%rbp)
        25:	xor    %esi,%esi
      ; int key = 0;
        27:	mov    %esi,-0x4(%rbp)
      ; if (!arg->sock)
        2a:	mov    0x8(%rdi),%rdi
      ; if (!arg->sock)
        2e:	cmp    $0x0,%rdi
        32:	je     0x0000000000000070
        34:	mov    %rbp,%rsi
      ; counts = bpf_map_lookup_elem(&btf_map, &key);
        37:	add    $0xfffffffffffffffc,%rsi
        3b:	movabs $0xffff8881139d7480,%rdi
        45:	add    $0x110,%rdi
        4c:	mov    0x0(%rsi),%eax
        4f:	cmp    $0x4,%rax
        53:	jae    0x000000000000005e
        55:	shl    $0x3,%rax
        59:	add    %rdi,%rax
        5c:	jmp    0x0000000000000060
        5e:	xor    %eax,%eax
      ; if (!counts)
        60:	cmp    $0x0,%rax
        64:	je     0x0000000000000070
      ; counts->v6++;
        66:	mov    0x4(%rax),%edi
        69:	add    $0x1,%rdi
        6d:	mov    %edi,0x4(%rax)
        70:	mov    0x0(%rbp),%rbx
        74:	mov    0x8(%rbp),%r13
        78:	mov    0x10(%rbp),%r14
        7c:	mov    0x18(%rbp),%r15
        80:	add    $0x28,%rbp
        84:	leaveq
        85:	retq
      [...]
      
      With linum:
      [root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv linum
      int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
      bpf_prog_b07ccb89267cf242__dummy_tracepoint:
      ; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:9]
         0:	push   %rbp
         1:	mov    %rsp,%rbp
         4:	sub    $0x28,%rsp
         b:	sub    $0x28,%rbp
         f:	mov    %rbx,0x0(%rbp)
        13:	mov    %r13,0x8(%rbp)
        17:	mov    %r14,0x10(%rbp)
        1b:	mov    %r15,0x18(%rbp)
        1f:	xor    %eax,%eax
        21:	mov    %rax,0x20(%rbp)
        25:	callq  0x000000000000851e
      ; return test_long_fname_1(arg); [file:/data/users/kafai/fb-kernel/linux/tools/testing/selftests/bpf/test_btf_haskv.c line_num:54 line_col:2]
        2a:	xor    %eax,%eax
        2c:	mov    0x0(%rbp),%rbx
        30:	mov    0x8(%rbp),%r13
        34:	mov    0x10(%rbp),%r14
        38:	mov    0x18(%rbp),%r15
        3c:	add    $0x28,%rbp
        40:	leaveq
        41:	retq
      [...]
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      b053b439
  27. 05 12月, 2018 1 次提交
  28. 01 12月, 2018 1 次提交
    • Q
      tools: bpftool: add owner_prog_type and owner_jited to bpftool output · 99a44bef
      Quentin Monnet 提交于
      For prog array maps, the type of the owner program, and the JIT-ed state
      of that program, are available from the file descriptor information
      under /proc. Add them to "bpftool map show" output. Example output:
      
          # bpftool map show
          158225: prog_array  name jmp_table  flags 0x0
              key 4B  value 4B  max_entries 8  memlock 4096B
              owner_prog_type flow_dissector  owner jited
          # bpftool --json --pretty map show
          [{
                  "id": 1337,
                  "type": "prog_array",
                  "name": "jmp_table",
                  "flags": 0,
                  "bytes_key": 4,
                  "bytes_value": 4,
                  "max_entries": 8,
                  "bytes_memlock": 4096,
                  "owner_prog_type": "flow_dissector",
                  "owner_jited": true
              }
          ]
      
      As we move the table used for associating names to program types,
      complete it with the missing types (lwt_seg6local and sk_reuseport).
      Also add missing types to the help message for "bpftool prog"
      (sk_reuseport and flow_dissector).
      Suggested-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      99a44bef
  29. 21 11月, 2018 1 次提交
    • Y
      tools/bpf: bpftool: add support for func types · 254471e5
      Yonghong Song 提交于
      This patch added support to print function signature
      if btf func_info is available. Note that ksym
      now uses function name instead of prog_name as
      prog_name has a limit of 16 bytes including
      ending '\0'.
      
      The following is a sample output for selftests
      test_btf with file test_btf_haskv.o for translated insns
      and jited insns respectively.
      
        $ bpftool prog dump xlated id 1
        int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
           0: (85) call pc+2#bpf_prog_2dcecc18072623fc_test_long_fname_1
           1: (b7) r0 = 0
           2: (95) exit
        int test_long_fname_1(struct dummy_tracepoint_args * arg):
           3: (85) call pc+1#bpf_prog_89d64e4abf0f0126_test_long_fname_2
           4: (95) exit
        int test_long_fname_2(struct dummy_tracepoint_args * arg):
           5: (b7) r2 = 0
           6: (63) *(u32 *)(r10 -4) = r2
           7: (79) r1 = *(u64 *)(r1 +8)
           ...
           22: (07) r1 += 1
           23: (63) *(u32 *)(r0 +4) = r1
           24: (95) exit
      
        $ bpftool prog dump jited id 1
        int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
        bpf_prog_b07ccb89267cf242__dummy_tracepoint:
           0:   push   %rbp
           1:   mov    %rsp,%rbp
          ......
          3c:   add    $0x28,%rbp
          40:   leaveq
          41:   retq
      
        int test_long_fname_1(struct dummy_tracepoint_args * arg):
        bpf_prog_2dcecc18072623fc_test_long_fname_1:
           0:   push   %rbp
           1:   mov    %rsp,%rbp
          ......
          3a:   add    $0x28,%rbp
          3e:   leaveq
          3f:   retq
      
        int test_long_fname_2(struct dummy_tracepoint_args * arg):
        bpf_prog_89d64e4abf0f0126_test_long_fname_2:
           0:   push   %rbp
           1:   mov    %rsp,%rbp
          ......
          80:   add    $0x28,%rbp
          84:   leaveq
          85:   retq
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      254471e5
  30. 17 11月, 2018 1 次提交
    • S
      bpftool: make libbfd optional · 29a9c10e
      Stanislav Fomichev 提交于
      Make it possible to build bpftool without libbfd. libbfd and libopcodes are
      typically provided in dev/dbg packages (binutils-dev in debian) which we
      usually don't have installed on the fleet machines and we'd like a way to have
      bpftool version that works without installing any additional packages.
      This excludes support for disassembling jit-ted code and prints an error if
      the user tries to use these features.
      
      Tested by:
      cat > FEATURES_DUMP.bpftool <<EOF
      feature-libbfd=0
      feature-disassembler-four-args=1
      feature-reallocarray=0
      feature-libelf=1
      feature-libelf-mmap=1
      feature-bpf=1
      EOF
      FEATURES_DUMP=$PWD/FEATURES_DUMP.bpftool make
      ldd bpftool | grep libbfd
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      29a9c10e
  31. 11 11月, 2018 1 次提交