1. 15 6月, 2022 1 次提交
    • Q
      Revert "bpftool: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK" · 6b4384ff
      Quentin Monnet 提交于
      This reverts commit a777e18f.
      
      In commit a777e18f ("bpftool: Use libbpf 1.0 API mode instead of
      RLIMIT_MEMLOCK"), we removed the rlimit bump in bpftool, because the
      kernel has switched to memcg-based memory accounting. Thanks to the
      LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK, we attempted to keep compatibility
      with other systems and ask libbpf to raise the limit for us if
      necessary.
      
      How do we know if memcg-based accounting is supported? There is a probe
      in libbpf to check this. But this probe currently relies on the
      availability of a given BPF helper, bpf_ktime_get_coarse_ns(), which
      landed in the same kernel version as the memory accounting change. This
      works in the generic case, but it may fail, for example, if the helper
      function has been backported to an older kernel. This has been observed
      for Google Cloud's Container-Optimized OS (COS), where the helper is
      available but rlimit is still in use. The probe succeeds, the rlimit is
      not raised, and probing features with bpftool, for example, fails.
      
      A patch was submitted [0] to update this probe in libbpf, based on what
      the cilium/ebpf Go library does [1]. It would lower the soft rlimit to
      0, attempt to load a BPF object, and reset the rlimit. But it may induce
      some hard-to-debug flakiness if another process starts, or the current
      application is killed, while the rlimit is reduced, and the approach was
      discarded.
      
      As a workaround to ensure that the rlimit bump does not depend on the
      availability of a given helper, we restore the unconditional rlimit bump
      in bpftool for now.
      
        [0] https://lore.kernel.org/bpf/20220609143614.97837-1-quentin@isovalent.com/
        [1] https://github.com/cilium/ebpf/blob/v0.9.0/rlimit/rlimit.go#L39Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Cc: Yafang Shao <laoar.shao@gmail.com>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/bpf/20220610112648.29695-2-quentin@isovalent.com
      6b4384ff
  2. 11 4月, 2022 1 次提交
  3. 11 2月, 2022 2 次提交
    • Q
      bpftool: Update versioning scheme, align on libbpf's version number · 9910a74d
      Quentin Monnet 提交于
      Since the notion of versions was introduced for bpftool, it has been
      following the version number of the kernel (using the version number
      corresponding to the tree in which bpftool's sources are located). The
      rationale was that bpftool's features are loosely tied to BPF features
      in the kernel, and that we could defer versioning to the kernel
      repository itself.
      
      But this versioning scheme is confusing today, because a bpftool binary
      should be able to work with both older and newer kernels, even if some
      of its recent features won't be available on older systems. Furthermore,
      if bpftool is ported to other systems in the future, keeping a
      Linux-based version number is not a good option.
      
      Looking at other options, we could either have a totally independent
      scheme for bpftool, or we could align it on libbpf's version number
      (with an offset on the major version number, to avoid going backwards).
      The latter comes with a few drawbacks:
      
      - We may want bpftool releases in-between two libbpf versions. We can
        always append pre-release numbers to distinguish versions, although
        those won't look as "official" as something with a proper release
        number. But at the same time, having bpftool with version numbers that
        look "official" hasn't really been an issue so far.
      
      - If no new feature lands in bpftool for some time, we may move from
        e.g. 6.7.0 to 6.8.0 when libbpf levels up and have two different
        versions which are in fact the same.
      
      - Following libbpf's versioning scheme sounds better than kernel's, but
        ultimately it doesn't make too much sense either, because even though
        bpftool uses the lib a lot, its behaviour is not that much conditioned
        by the internal evolution of the library (or by new APIs that it may
        not use).
      
      Having an independent versioning scheme solves the above, but at the
      cost of heavier maintenance. Developers will likely forget to increase
      the numbers when adding features or bug fixes, and we would take the
      risk of having to send occasional "catch-up" patches just to update the
      version number.
      
      Based on these considerations, this patch aligns bpftool's version
      number on libbpf's. This is not a perfect solution, but 1) it's
      certainly an improvement over the current scheme, 2) the issues raised
      above are all minor at the moment, and 3) we can still move to an
      independent scheme in the future if we realise we need it.
      
      Given that libbpf is currently at version 0.7.0, and bpftool, before
      this patch, was at 5.16, we use an offset of 6 for the major version,
      bumping bpftool to 6.7.0. Libbpf does not export its patch number;
      leave bpftool's patch number at 0 for now.
      
      It remains possible to manually override the version number by setting
      BPFTOOL_VERSION when calling make.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20220210104237.11649-3-quentin@isovalent.com
      9910a74d
    • Q
      bpftool: Add libbpf's version number to "bpftool version" output · 61fce969
      Quentin Monnet 提交于
      To help users check what version of libbpf is being used with bpftool,
      print the number along with bpftool's own version number.
      
      Output:
      
          $ ./bpftool version
          ./bpftool v5.16.0
          using libbpf v0.7
          features: libbfd, libbpf_strict, skeletons
      
          $ ./bpftool version --json --pretty
          {
              "version": "5.16.0",
              "libbpf_version": "0.7",
              "features": {
                  "libbfd": true,
                  "libbpf_strict": true,
                  "skeletons": true
              }
          }
      
      Note that libbpf does not expose its patch number.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20220210104237.11649-2-quentin@isovalent.com
      61fce969
  4. 08 2月, 2022 1 次提交
  5. 21 1月, 2022 1 次提交
    • A
      libbpf: deprecate legacy BPF map definitions · 93b8952d
      Andrii Nakryiko 提交于
      Enact deprecation of legacy BPF map definition in SEC("maps") ([0]). For
      the definitions themselves introduce LIBBPF_STRICT_MAP_DEFINITIONS flag
      for libbpf strict mode. If it is set, error out on any struct
      bpf_map_def-based map definition. If not set, libbpf will print out
      a warning for each legacy BPF map to raise awareness that it goes away.
      
      For any use of BPF_ANNOTATE_KV_PAIR() macro providing a legacy way to
      associate BTF key/value type information with legacy BPF map definition,
      warn through libbpf's pr_warn() error message (but don't fail BPF object
      open).
      
      BPF-side struct bpf_map_def is marked as deprecated. User-space struct
      bpf_map_def has to be used internally in libbpf, so it is left
      untouched. It should be enough for bpf_map__def() to be marked
      deprecated to raise awareness that it goes away.
      
      bpftool is an interesting case that utilizes libbpf to open BPF ELF
      object to generate skeleton. As such, even though bpftool itself uses
      full on strict libbpf mode (LIBBPF_STRICT_ALL), it has to relax it a bit
      for BPF map definition handling to minimize unnecessary disruptions. So
      opt-out of LIBBPF_STRICT_MAP_DEFINITIONS for bpftool. User's code that
      will later use generated skeleton will make its own decision whether to
      enforce LIBBPF_STRICT_MAP_DEFINITIONS or not.
      
      There are few tests in selftests/bpf that are consciously using legacy
      BPF map definitions to test libbpf functionality. For those, temporary
      opt out of LIBBPF_STRICT_MAP_DEFINITIONS mode for the duration of those
      tests.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/272Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20220120060529.1890907-4-andrii@kernel.orgSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      93b8952d
  6. 22 12月, 2021 1 次提交
  7. 16 11月, 2021 1 次提交
    • S
      bpftool: Add current libbpf_strict mode to version output · e47d0bf8
      Stanislav Fomichev 提交于
      + bpftool --legacy --version
      bpftool v5.15.0
      features: libbfd, skeletons
      + bpftool --version
      bpftool v5.15.0
      features: libbfd, libbpf_strict, skeletons
      
      + bpftool --legacy --help
      Usage: bpftool [OPTIONS] OBJECT { COMMAND | help }
             bpftool batch file FILE
             bpftool version
      
             OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter }
             OPTIONS := { {-j|--json} [{-p|--pretty}] | {-d|--debug} | {-l|--legacy} |
                          {-V|--version} }
      + bpftool --help
      Usage: bpftool [OPTIONS] OBJECT { COMMAND | help }
             bpftool batch file FILE
             bpftool version
      
             OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter }
             OPTIONS := { {-j|--json} [{-p|--pretty}] | {-d|--debug} | {-l|--legacy} |
                          {-V|--version} }
      
      + bpftool --legacy
      Usage: bpftool [OPTIONS] OBJECT { COMMAND | help }
             bpftool batch file FILE
             bpftool version
      
             OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter }
             OPTIONS := { {-j|--json} [{-p|--pretty}] | {-d|--debug} | {-l|--legacy} |
                          {-V|--version} }
      + bpftool
      Usage: bpftool [OPTIONS] OBJECT { COMMAND | help }
             bpftool batch file FILE
             bpftool version
      
             OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter }
             OPTIONS := { {-j|--json} [{-p|--pretty}] | {-d|--debug} | {-l|--legacy} |
                          {-V|--version} }
      
      + bpftool --legacy version
      bpftool v5.15.0
      features: libbfd, skeletons
      + bpftool version
      bpftool v5.15.0
      features: libbfd, libbpf_strict, skeletons
      
      + bpftool --json --legacy version
      {"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":false,"skeletons":true}}
      + bpftool --json version
      {"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":true,"skeletons":true}}
      Suggested-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20211116000448.2918854-1-sdf@google.com
      e47d0bf8
  8. 12 11月, 2021 1 次提交
  9. 26 10月, 2021 2 次提交
    • Q
      bpftool: Switch to libbpf's hashmap for PIDs/names references · d6699f8e
      Quentin Monnet 提交于
      In order to show PIDs and names for processes holding references to BPF
      programs, maps, links, or BTF objects, bpftool creates hash maps to
      store all relevant information. This commit is part of a set that
      transitions from the kernel's hash map implementation to the one coming
      with libbpf.
      
      The motivation is to make bpftool less dependent of kernel headers, to
      ease the path to a potential out-of-tree mirror, like libbpf has.
      
      This is the third and final step of the transition, in which we convert
      the hash maps used for storing the information about the processes
      holding references to BPF objects (programs, maps, links, BTF), and at
      last we drop the inclusion of tools/include/linux/hashtable.h.
      
      Note: Checkpatch complains about the use of __weak declarations, and the
      missing empty lines after the bunch of empty function declarations when
      compiling without the BPF skeletons (none of these were introduced in
      this patch). We want to keep things as they are, and the reports should
      be safe to ignore.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-6-quentin@isovalent.com
      d6699f8e
    • Q
      bpftool: Do not expose and init hash maps for pinned path in main.c · 46241271
      Quentin Monnet 提交于
      BPF programs, maps, and links, can all be listed with their pinned paths
      by bpftool, when the "-f" option is provided. To do so, bpftool builds
      hash maps containing all pinned paths for each kind of objects.
      
      These three hash maps are always initialised in main.c, and exposed
      through main.h. There appear to be no particular reason to do so: we can
      just as well make them static to the files that need them (prog.c,
      map.c, and link.c respectively), and initialise them only when we want
      to show objects and the "-f" switch is provided.
      
      This may prevent unnecessary memory allocations if the implementation of
      the hash maps was to change in the future.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-3-quentin@isovalent.com
      46241271
  10. 31 7月, 2021 1 次提交
    • Q
      tools: bpftool: Update and synchronise option list in doc and help msg · c07ba629
      Quentin Monnet 提交于
      All bpftool commands support the options for JSON output and debug from
      libbpf. In addition, some commands support additional options
      corresponding to specific use cases.
      
      The list of options described in the man pages for the different
      commands are not always accurate. The messages for interactive help are
      mostly limited to HELP_SPEC_OPTIONS, and are even less representative of
      the actual set of options supported for the commands.
      
      Let's update the lists:
      
      - HELP_SPEC_OPTIONS is modified to contain the "default" options (JSON
        and debug), and to be extensible (no ending curly bracket).
      - All commands use HELP_SPEC_OPTIONS in their help message, and then
        complete the list with their specific options.
      - The lists of options in the man pages are updated.
      - The formatting of the list for bpftool.rst is adjusted to match
        formatting for the other man pages. This is for consistency, and also
        because it will be helpful in a future patch to automatically check
        that the files are synchronised.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210730215435.7095-5-quentin@isovalent.com
      c07ba629
  11. 12 6月, 2021 1 次提交
  12. 19 5月, 2021 1 次提交
    • A
      bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command. · d510296d
      Alexei Starovoitov 提交于
      Add -L flag to bpftool to use libbpf gen_trace facility and syscall/loader program
      for skeleton generation and program loading.
      
      "bpftool gen skeleton -L" command will generate a "light skeleton" or "loader skeleton"
      that is similar to existing skeleton, but has one major difference:
      $ bpftool gen skeleton lsm.o > lsm.skel.h
      $ bpftool gen skeleton -L lsm.o > lsm.lskel.h
      $ diff lsm.skel.h lsm.lskel.h
      @@ -5,34 +4,34 @@
       #define __LSM_SKEL_H__
      
       #include <stdlib.h>
      -#include <bpf/libbpf.h>
      +#include <bpf/bpf.h>
      
      The light skeleton does not use majority of libbpf infrastructure.
      It doesn't need libelf. It doesn't parse .o file.
      It only needs few sys_bpf wrappers. All of them are in bpf/bpf.h file.
      In future libbpf/bpf.c can be inlined into bpf.h, so not even libbpf.a would be
      needed to work with light skeleton.
      
      "bpftool prog load -L file.o" command is introduced for debugging of syscall/loader
      program generation. Just like the same command without -L it will try to load
      the programs from file.o into the kernel. It won't even try to pin them.
      
      "bpftool prog load -L -d file.o" command will provide additional debug messages
      on how syscall/loader program was generated.
      Also the execution of syscall/loader program will use bpf_trace_printk() for
      each step of loading BTF, creating maps, and loading programs.
      The user can do "cat /.../trace_pipe" for further debug.
      
      An example of fexit_sleep.lskel.h generated from progs/fexit_sleep.c:
      struct fexit_sleep {
      	struct bpf_loader_ctx ctx;
      	struct {
      		struct bpf_map_desc bss;
      	} maps;
      	struct {
      		struct bpf_prog_desc nanosleep_fentry;
      		struct bpf_prog_desc nanosleep_fexit;
      	} progs;
      	struct {
      		int nanosleep_fentry_fd;
      		int nanosleep_fexit_fd;
      	} links;
      	struct fexit_sleep__bss {
      		int pid;
      		int fentry_cnt;
      		int fexit_cnt;
      	} *bss;
      };
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210514003623.28033-18-alexei.starovoitov@gmail.com
      d510296d
  13. 17 3月, 2021 1 次提交
  14. 06 11月, 2020 1 次提交
  15. 11 9月, 2020 1 次提交
    • Q
      tools: bpftool: Print optional built-in features along with version · 82b8cf0a
      Quentin Monnet 提交于
      Bpftool has a number of features that can be included or left aside
      during compilation. This includes:
      
      - Support for libbfd, providing the disassembler for JIT-compiled
        programs.
      - Support for BPF skeletons, used for profiling programs or iterating on
        the PIDs of processes associated with BPF objects.
      
      In order to make it easy for users to understand what features were
      compiled for a given bpftool binary, print the status of the two
      features above when showing the version number for bpftool ("bpftool -V"
      or "bpftool version"). Document this in the main manual page. Example
      invocations:
      
          $ bpftool version
          ./bpftool v5.9.0-rc1
          features: libbfd, skeletons
      
          $ bpftool -p version
          {
              "version": "5.9.0-rc1",
              "features": {
                  "libbfd": true,
                  "skeletons": true
              }
          }
      
      Some other parameters are optional at compilation
      ("DISASM_FOUR_ARGS_SIGNATURE", LIBCAP support) but they do not impact
      significantly bpftool's behaviour from a user's point of view, so their
      status is not reported.
      
      Available commands and supported program types depend on the version
      number, and are therefore not reported either. Note that they are
      already available, albeit without JSON, via bpftool's help messages.
      
      v3:
      - Use a simple list instead of boolean values for plain output.
      
      v2:
      - Fix JSON (object instead or array for the features).
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200909162500.17010-2-quentin@isovalent.com
      82b8cf0a
  16. 23 6月, 2020 2 次提交
    • A
      tools/bpftool: Show info for processes holding BPF map/prog/link/btf FDs · d53dee3f
      Andrii Nakryiko 提交于
      Add bpf_iter-based way to find all the processes that hold open FDs against
      BPF object (map, prog, link, btf). bpftool always attempts to discover this,
      but will silently give up if kernel doesn't yet support bpf_iter BPF programs.
      Process name and PID are emitted for each process (task group).
      
      Sample output for each of 4 BPF objects:
      
      $ sudo ./bpftool prog show
      2694: cgroup_device  tag 8c42dee26e8cd4c2  gpl
              loaded_at 2020-06-16T15:34:32-0700  uid 0
              xlated 648B  jited 409B  memlock 4096B
              pids systemd(1)
      2907: cgroup_skb  name egress  tag 9ad187367cf2b9e8  gpl
              loaded_at 2020-06-16T18:06:54-0700  uid 0
              xlated 48B  jited 59B  memlock 4096B  map_ids 2436
              btf_id 1202
              pids test_progs(2238417), test_progs(22384459)
      
      $ sudo ./bpftool map show
      2436: array  name test_cgr.bss  flags 0x400
              key 4B  value 8B  max_entries 1  memlock 8192B
              btf_id 1202
              pids test_progs(2238417), test_progs(22384459)
      2445: array  name pid_iter.rodata  flags 0x480
              key 4B  value 4B  max_entries 1  memlock 8192B
              btf_id 1214  frozen
              pids bpftool(2239612)
      
      $ sudo ./bpftool link show
      61: cgroup  prog 2908
              cgroup_id 375301  attach_type egress
              pids test_progs(2238417), test_progs(22384459)
      62: cgroup  prog 2908
              cgroup_id 375344  attach_type egress
              pids test_progs(2238417), test_progs(22384459)
      
      $ sudo ./bpftool btf show
      1202: size 1527B  prog_ids 2908,2907  map_ids 2436
              pids test_progs(2238417), test_progs(22384459)
      1242: size 34684B
              pids bpftool(2258892)
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200619231703.738941-9-andriin@fb.com
      d53dee3f
    • A
      tools/bpftool: Minimize bootstrap bpftool · 16e9b187
      Andrii Nakryiko 提交于
      Build minimal "bootstrap mode" bpftool to enable skeleton (and, later,
      vmlinux.h generation), instead of building almost complete, but slightly
      different (w/o skeletons, etc) bpftool to bootstrap complete bpftool build.
      
      Current approach doesn't scale well (engineering-wise) when adding more BPF
      programs to bpftool and other complicated functionality, as it requires
      constant adjusting of the code to work in both bootstrapped mode and normal
      mode.
      
      So it's better to build only minimal bpftool version that supports only BPF
      skeleton code generation and BTF-to-C conversion. Thankfully, this is quite
      easy to accomplish due to internal modularity of bpftool commands. This will
      also allow to keep adding new functionality to bpftool in general, without the
      need to care about bootstrap mode for those new parts of bpftool.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200619231703.738941-6-andriin@fb.com
      16e9b187
  17. 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
  18. 29 4月, 2020 1 次提交
    • A
      bpftool: Add bpf_link show and pin support · c5481f9a
      Andrii Nakryiko 提交于
      Add `bpftool link show` and `bpftool link pin` commands.
      
      Example plain output for `link show` (with showing pinned paths):
      
      [vmuser@archvm bpf]$ sudo ~/local/linux/tools/bpf/bpftool/bpftool -f link
      1: tracing  prog 12
              prog_type tracing  attach_type fentry
              pinned /sys/fs/bpf/my_test_link
              pinned /sys/fs/bpf/my_test_link2
      2: tracing  prog 13
              prog_type tracing  attach_type fentry
      3: tracing  prog 14
              prog_type tracing  attach_type fentry
      4: tracing  prog 15
              prog_type tracing  attach_type fentry
      5: tracing  prog 16
              prog_type tracing  attach_type fentry
      6: tracing  prog 17
              prog_type tracing  attach_type fentry
      7: raw_tracepoint  prog 21
              tp 'sys_enter'
      8: cgroup  prog 25
              cgroup_id 584  attach_type egress
      9: cgroup  prog 25
              cgroup_id 599  attach_type egress
      10: cgroup  prog 25
              cgroup_id 614  attach_type egress
      11: cgroup  prog 25
              cgroup_id 629  attach_type egress
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200429001614.1544-9-andriin@fb.com
      c5481f9a
  19. 20 3月, 2020 1 次提交
    • 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
  20. 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
  21. 21 1月, 2020 1 次提交
  22. 16 12月, 2019 1 次提交
    • 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
  23. 08 10月, 2019 1 次提交
  24. 16 8月, 2019 1 次提交
  25. 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
  26. 28 5月, 2019 2 次提交
    • 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
    • Q
      tools: bpftool: add -d option to get debug output from libbpf · 775bc8ad
      Quentin Monnet 提交于
      libbpf has three levels of priority for output messages: warn, info,
      debug. By default, debug output is not printed to the console.
      
      Add a new "--debug" (short name: "-d") option to bpftool to print libbpf
      logs for all three levels.
      
      Internally, we simply use the function provided by libbpf to replace the
      default printing function by one that prints logs regardless of their
      level.
      
      v2:
      - Remove the possibility to select the log-levels to use (v1 offered a
        combination of "warn", "info" and "debug").
      - Rename option and offer a short name: -d|--debug.
      - Add option description to all bpftool manual pages (instead of
        bpftool-prog.rst only), as all commands use libbpf.
      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>
      775bc8ad
  27. 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
  28. 23 1月, 2019 1 次提交
    • 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
  29. 18 12月, 2018 1 次提交
  30. 13 12月, 2018 1 次提交
  31. 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
  32. 22 10月, 2018 1 次提交
  33. 16 10月, 2018 1 次提交
    • J
      bpf: bpftool, add flag to allow non-compat map definitions · c034a177
      John Fastabend 提交于
      Multiple map definition structures exist and user may have non-zero
      fields in their definition that are not recognized by bpftool and
      libbpf. The normal behavior is to then fail loading the map. Although
      this is a good default behavior users may still want to load the map
      for debugging or other reasons. This patch adds a --mapcompat flag
      that can be used to override the default behavior and allow loading
      the map even when it has additional non-zero fields.
      
      For now the only user is 'bpftool prog' we can switch over other
      subcommands as needed. The library exposes an API that consumes
      a flags field now but I kept the original API around also in case
      users of the API don't want to expose this. The flags field is an
      int in case we need more control over how the API call handles
      errors/features/etc in the future.
      Signed-off-by: NJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      c034a177
  34. 07 9月, 2018 1 次提交
    • Y
      tools/bpf: bpftool: add net support · f6f3bac0
      Yonghong Song 提交于
      Add "bpftool net" support. Networking devices are enumerated
      to dump device index/name associated with xdp progs.
      
      For each networking device, tc classes and qdiscs are enumerated
      in order to check their bpf filters.
      In addition, root handle and clsact ingress/egress are also checked for
      bpf filters.  Not all filter information is printed out. Only ifindex,
      kind, filter name, prog_id and tag are printed out, which are good
      enough to show attachment information. If the filter action
      is a bpf action, its bpf program id, bpf name and tag will be
      printed out as well.
      
      For example,
        $ ./bpftool net
        xdp [
        ifindex 2 devname eth0 prog_id 198
        ]
        tc_filters [
        ifindex 2 kind qdisc_htb name prefix_matcher.o:[cls_prefix_matcher_htb]
                  prog_id 111727 tag d08fe3b4319bc2fd act []
        ifindex 2 kind qdisc_clsact_ingress name fbflow_icmp
                  prog_id 130246 tag 3f265c7f26db62c9 act []
        ifindex 2 kind qdisc_clsact_egress name prefix_matcher.o:[cls_prefix_matcher_clsact]
                  prog_id 111726 tag 99a197826974c876
        ifindex 2 kind qdisc_clsact_egress name cls_fg_dscp
                  prog_id 108619 tag dc4630674fd72dcc act []
        ifindex 2 kind qdisc_clsact_egress name fbflow_egress
                  prog_id 130245 tag 72d2d830d6888d2c
        ]
        $ ./bpftool -jp net
        [{
              "xdp": [{
                      "ifindex": 2,
                      "devname": "eth0",
                      "prog_id": 198
                  }
              ],
              "tc_filters": [{
                      "ifindex": 2,
                      "kind": "qdisc_htb",
                      "name": "prefix_matcher.o:[cls_prefix_matcher_htb]",
                      "prog_id": 111727,
                      "tag": "d08fe3b4319bc2fd",
                      "act": []
                  },{
                      "ifindex": 2,
                      "kind": "qdisc_clsact_ingress",
                      "name": "fbflow_icmp",
                      "prog_id": 130246,
                      "tag": "3f265c7f26db62c9",
                      "act": []
                  },{
                      "ifindex": 2,
                      "kind": "qdisc_clsact_egress",
                      "name": "prefix_matcher.o:[cls_prefix_matcher_clsact]",
                      "prog_id": 111726,
                      "tag": "99a197826974c876"
                  },{
                      "ifindex": 2,
                      "kind": "qdisc_clsact_egress",
                      "name": "cls_fg_dscp",
                      "prog_id": 108619,
                      "tag": "dc4630674fd72dcc",
                      "act": []
                  },{
                      "ifindex": 2,
                      "kind": "qdisc_clsact_egress",
                      "name": "fbflow_egress",
                      "prog_id": 130245,
                      "tag": "72d2d830d6888d2c"
                  }
              ]
          }
        ]
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      f6f3bac0
  35. 01 7月, 2018 1 次提交
  36. 25 5月, 2018 1 次提交
    • Y
      tools/bpftool: add perf subcommand · b04df400
      Yonghong Song 提交于
      The new command "bpftool perf [show | list]" will traverse
      all processes under /proc, and if any fd is associated
      with a perf event, it will print out related perf event
      information. Documentation is also added.
      
      Below is an example to show the results using bcc commands.
      Running the following 4 bcc commands:
        kprobe:     trace.py '__x64_sys_nanosleep'
        kretprobe:  trace.py 'r::__x64_sys_nanosleep'
        tracepoint: trace.py 't:syscalls:sys_enter_nanosleep'
        uprobe:     trace.py 'p:/home/yhs/a.out:main'
      
      The bpftool command line and result:
      
        $ bpftool perf
        pid 21711  fd 5: prog_id 5  kprobe  func __x64_sys_write  offset 0
        pid 21765  fd 5: prog_id 7  kretprobe  func __x64_sys_nanosleep  offset 0
        pid 21767  fd 5: prog_id 8  tracepoint  sys_enter_nanosleep
        pid 21800  fd 5: prog_id 9  uprobe  filename /home/yhs/a.out  offset 1159
      
        $ bpftool -j perf
        [{"pid":21711,"fd":5,"prog_id":5,"fd_type":"kprobe","func":"__x64_sys_write","offset":0}, \
         {"pid":21765,"fd":5,"prog_id":7,"fd_type":"kretprobe","func":"__x64_sys_nanosleep","offset":0}, \
         {"pid":21767,"fd":5,"prog_id":8,"fd_type":"tracepoint","tracepoint":"sys_enter_nanosleep"}, \
         {"pid":21800,"fd":5,"prog_id":9,"fd_type":"uprobe","filename":"/home/yhs/a.out","offset":1159}]
      
        $ bpftool prog
        5: kprobe  name probe___x64_sys  tag e495a0c82f2c7a8d  gpl
      	  loaded_at 2018-05-15T04:46:37-0700  uid 0
      	  xlated 200B  not jited  memlock 4096B  map_ids 4
        7: kprobe  name probe___x64_sys  tag f2fdee479a503abf  gpl
      	  loaded_at 2018-05-15T04:48:32-0700  uid 0
      	  xlated 200B  not jited  memlock 4096B  map_ids 7
        8: tracepoint  name tracepoint__sys  tag 5390badef2395fcf  gpl
      	  loaded_at 2018-05-15T04:48:48-0700  uid 0
      	  xlated 200B  not jited  memlock 4096B  map_ids 8
        9: kprobe  name probe_main_1  tag 0a87bdc2e2953b6d  gpl
      	  loaded_at 2018-05-15T04:49:52-0700  uid 0
      	  xlated 200B  not jited  memlock 4096B  map_ids 9
      
        $ ps ax | grep "python ./trace.py"
        21711 pts/0    T      0:03 python ./trace.py __x64_sys_write
        21765 pts/0    S+     0:00 python ./trace.py r::__x64_sys_nanosleep
        21767 pts/2    S+     0:00 python ./trace.py t:syscalls:sys_enter_nanosleep
        21800 pts/3    S+     0:00 python ./trace.py p:/home/yhs/a.out:main
        22374 pts/1    S+     0:00 grep --color=auto python ./trace.py
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      b04df400