1. 10 Nov, 2022 1 commit
  2. 30 Sep, 2022 1 commit
  3. 29 Jul, 2022 1 commit
  4. 08 Jul, 2022 1 commit
  5. 06 Jul, 2022 1 commit
  6. 07 Jun, 2022 1 commit
    • Yonghong Song's avatar
      bpftool: Add btf enum64 support · 58a53978
      Yonghong Song authored
      
      Add BTF_KIND_ENUM64 support.
      For example, the following enum is defined in uapi bpf.h.
        $ cat core.c
        enum A {
              BPF_F_INDEX_MASK                = 0xffffffffULL,
              BPF_F_CURRENT_CPU               = BPF_F_INDEX_MASK,
              BPF_F_CTXLEN_MASK               = (0xfffffULL << 32),
        } g;
      Compiled with
        clang -target bpf -O2 -g -c core.c
      Using bpftool to dump types and generate format C file:
        $ bpftool btf dump file core.o
        ...
        [1] ENUM64 'A' encoding=UNSIGNED size=8 vlen=3
              'BPF_F_INDEX_MASK' val=4294967295ULL
              'BPF_F_CURRENT_CPU' val=4294967295ULL
              'BPF_F_CTXLEN_MASK' val=4503595332403200ULL
        $ bpftool btf dump file core.o format c
        ...
        enum A {
              BPF_F_INDEX_MASK = 4294967295ULL,
              BPF_F_CURRENT_CPU = 4294967295ULL,
              BPF_F_CTXLEN_MASK = 4503595332403200ULL,
        };
        ...
      
      Note that for raw btf output, the encoding (UNSIGNED or SIGNED)
      is printed out as well. The 64bit value is also represented properly
      in BTF and C dump.
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220607062652.3722649-1-yhs@fb.com
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      58a53978
  7. 02 Jun, 2022 1 commit
  8. 10 May, 2022 2 commits
  9. 30 Mar, 2022 1 commit
  10. 29 Mar, 2022 1 commit
  11. 21 Mar, 2022 1 commit
    • Yonghong Song's avatar
      bpftool: Fix a bug in subskeleton code generation · f97b8b9b
      Yonghong Song authored
      Compiled with clang by adding LLVM=1 both kernel and selftests/bpf
      build, I hit the following compilation error:
      
      In file included from /.../tools/testing/selftests/bpf/prog_tests/subskeleton.c:6:
        ./test_subskeleton_lib.subskel.h:168:6: error: variable 'err' is used uninitialized whenever
            'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (!s->progs)
                    ^~~~~~~~~
        ./test_subskeleton_lib.subskel.h:181:11: note: uninitialized use occurs here
                errno = -err;
                         ^~~
        ./test_subskeleton_lib.subskel.h:168:2: note: remove the 'if' if its condition is always false
                if (!s->progs)
                ^~~~~~~~~~~~~~
      
      The compilation error is triggered by the following code
              ...
              int err;
      
              obj = (struct test_subskeleton_lib *)calloc(1, sizeof(*obj));
              if (!obj) {
                      errno = ENOMEM;
                      goto err;
              }
              ...
      
        err:
              test_subskeleton_lib__destroy(obj);
              errno = -err;
              ...
      in test_subskeleton_lib__open(). The 'err' is not initialized, yet it
      is used in 'errno = -err' later.
      
      The fix is to remove 'errno = -err' since errno has been set properly
      in all incoming branches.
      
      Fixes: 00389c58
      
       ("bpftool: Add support for subskeletons")
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20220320032009.3106133-1-yhs@fb.com
      f97b8b9b
  12. 18 Mar, 2022 1 commit
  13. 24 Feb, 2022 1 commit
  14. 17 Feb, 2022 1 commit
  15. 16 Feb, 2022 3 commits
  16. 15 Feb, 2022 1 commit
    • Andrii Nakryiko's avatar
      bpftool: Add C++-specific open/load/etc skeleton wrappers · bb8ffe61
      Andrii Nakryiko authored
      
      Add C++-specific static methods for code-generated BPF skeleton for each
      skeleton operation: open, open_opts, open_and_load, load, attach,
      detach, destroy, and elf_bytes. This is to facilitate easier C++
      templating on top of pure C BPF skeleton.
      
      In C, open/load/destroy/etc "methods" are of the form
      <skeleton_name>__<method>() to avoid name collision with similar
      "methods" of other skeletons withint the same application. This works
      well, but is very inconvenient for C++ applications that would like to
      write generic (templated) wrappers around BPF skeleton to fit in with
      C++ code base and take advantage of destructors and other convenient C++
      constructs.
      
      This patch makes it easier to build such generic templated wrappers by
      additionally defining C++ static methods for skeleton's struct with
      fixed names. This allows to refer to, say, open method as `T::open()`
      instead of having to somehow generate `T__open()` function call.
      
      Next patch adds an example template to test_cpp selftest to demonstrate
      how it's possible to have all the operations wrapped in a generic
      Skeleton<my_skeleton> type without explicitly passing function references.
      
      An example of generated declaration section without %1$s placeholders:
      
        #ifdef __cplusplus
            static struct test_attach_probe *open(const struct bpf_object_open_opts *opts = nullptr);
            static struct test_attach_probe *open_and_load();
            static int load(struct test_attach_probe *skel);
            static int attach(struct test_attach_probe *skel);
            static void detach(struct test_attach_probe *skel);
            static void destroy(struct test_attach_probe *skel);
            static const void *elf_bytes(size_t *sz);
        #endif /* __cplusplus */
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20220212055733.539056-2-andrii@kernel.org
      bb8ffe61
  17. 10 Feb, 2022 1 commit
  18. 01 Feb, 2022 2 commits
  19. 26 Jan, 2022 1 commit
  20. 13 Jan, 2022 2 commits
  21. 10 Dec, 2021 1 commit
  22. 15 Nov, 2021 1 commit
  23. 12 Nov, 2021 1 commit
  24. 22 Oct, 2021 3 commits
  25. 08 Oct, 2021 1 commit
  26. 28 Sep, 2021 1 commit
  27. 08 Sep, 2021 1 commit
  28. 30 Jul, 2021 2 commits
  29. 26 May, 2021 1 commit
  30. 18 May, 2021 1 commit
    • Alexei Starovoitov's avatar
      bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command. · d510296d
      Alexei Starovoitov authored
      
      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: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210514003623.28033-18-alexei.starovoitov@gmail.com
      d510296d
  31. 11 May, 2021 2 commits