1. 31 8月, 2020 1 次提交
  2. 20 8月, 2020 1 次提交
  3. 14 8月, 2020 3 次提交
  4. 07 8月, 2020 1 次提交
  5. 02 8月, 2020 1 次提交
  6. 31 7月, 2020 1 次提交
  7. 26 7月, 2020 3 次提交
  8. 18 7月, 2020 1 次提交
  9. 16 7月, 2020 1 次提交
  10. 10 7月, 2020 1 次提交
  11. 09 7月, 2020 3 次提交
  12. 08 7月, 2020 1 次提交
  13. 29 6月, 2020 1 次提交
    • A
      libbpf: Support disabling auto-loading BPF programs · d9297581
      Andrii Nakryiko 提交于
      Currently, bpf_object__load() (and by induction skeleton's load), will always
      attempt to prepare, relocate, and load into kernel every single BPF program
      found inside the BPF object file. This is often convenient and the right thing
      to do and what users expect.
      
      But there are plenty of cases (especially with BPF development constantly
      picking up the pace), where BPF application is intended to work with old
      kernels, with potentially reduced set of features. But on kernels supporting
      extra features, it would like to take a full advantage of them, by employing
      extra BPF program. This could be a choice of using fentry/fexit over
      kprobe/kretprobe, if kernel is recent enough and is built with BTF. Or BPF
      program might be providing optimized bpf_iter-based solution that user-space
      might want to use, whenever available. And so on.
      
      With libbpf and BPF CO-RE in particular, it's advantageous to not have to
      maintain two separate BPF object files to achieve this. So to enable such use
      cases, this patch adds ability to request not auto-loading chosen BPF
      programs. In such case, libbpf won't attempt to perform relocations (which
      might fail due to old kernel), won't try to resolve BTF types for
      BTF-aware (tp_btf/fentry/fexit/etc) program types, because BTF might not be
      present, and so on. Skeleton will also automatically skip auto-attachment step
      for such not loaded BPF programs.
      
      Overall, this feature allows to simplify development and deployment of
      real-world BPF applications with complicated compatibility requirements.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200625232629.3444003-2-andriin@fb.com
      d9297581
  14. 26 6月, 2020 1 次提交
  15. 24 6月, 2020 3 次提交
  16. 23 6月, 2020 3 次提交
    • A
      libbpf: Add support for extracting kernel symbol addresses · 1c0c7074
      Andrii Nakryiko 提交于
      Add support for another (in addition to existing Kconfig) special kind of
      externs in BPF code, kernel symbol externs. Such externs allow BPF code to
      "know" kernel symbol address and either use it for comparisons with kernel
      data structures (e.g., struct file's f_op pointer, to distinguish different
      kinds of file), or, with the help of bpf_probe_user_kernel(), to follow
      pointers and read data from global variables. Kernel symbol addresses are
      found through /proc/kallsyms, which should be present in the system.
      
      Currently, such kernel symbol variables are typeless: they have to be defined
      as `extern const void <symbol>` and the only operation you can do (in C code)
      with them is to take its address. Such extern should reside in a special
      section '.ksyms'. bpf_helpers.h header provides __ksym macro for this. Strong
      vs weak semantics stays the same as with Kconfig externs. If symbol is not
      found in /proc/kallsyms, this will be a failure for strong (non-weak) extern,
      but will be defaulted to 0 for weak externs.
      
      If the same symbol is defined multiple times in /proc/kallsyms, then it will
      be error if any of the associated addresses differs. In that case, address is
      ambiguous, so libbpf falls on the side of caution, rather than confusing user
      with randomly chosen address.
      
      In the future, once kernel is extended with variables BTF information, such
      ksym externs will be supported in a typed version, which will allow BPF
      program to read variable's contents directly, similarly to how it's done for
      fentry/fexit input arguments.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NHao Luo <haoluo@google.com>
      Link: https://lore.kernel.org/bpf/20200619231703.738941-3-andriin@fb.com
      1c0c7074
    • A
      libbpf: Generalize libbpf externs support · 2e33efe3
      Andrii Nakryiko 提交于
      Switch existing Kconfig externs to be just one of few possible kinds of more
      generic externs. This refactoring is in preparation for ksymbol extern
      support, added in the follow up patch. There are no functional changes
      intended.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NHao Luo <haoluo@google.com>
      Link: https://lore.kernel.org/bpf/20200619231703.738941-2-andriin@fb.com
      2e33efe3
    • A
      libbpf: Add a bunch of attribute getters/setters for map definitions · 1bdb6c9a
      Andrii Nakryiko 提交于
      Add a bunch of getter for various aspects of BPF map. Some of these attribute
      (e.g., key_size, value_size, type, etc) are available right now in struct
      bpf_map_def, but this patch adds getter allowing to fetch them individually.
      bpf_map_def approach isn't very scalable, when ABI stability requirements are
      taken into account. It's much easier to extend libbpf and add support for new
      features, when each aspect of BPF map has separate getter/setter.
      
      Getters follow the common naming convention of not explicitly having "get" in
      its name: bpf_map__type() returns map type, bpf_map__key_size() returns
      key_size. Setters, though, explicitly have set in their name:
      bpf_map__set_type(), bpf_map__set_key_size().
      
      This patch ensures we now have a getter and a setter for the following
      map attributes:
        - type;
        - max_entries;
        - map_flags;
        - numa_node;
        - key_size;
        - value_size;
        - ifindex.
      
      bpf_map__resize() enforces unnecessary restriction of max_entries > 0. It is
      unnecessary, because libbpf actually supports zero max_entries for some cases
      (e.g., for PERF_EVENT_ARRAY map) and treats it specially during map creation
      time. To allow setting max_entries=0, new bpf_map__set_max_entries() setter is
      added. bpf_map__resize()'s behavior is preserved for backwards compatibility
      reasons.
      
      Map ifindex getter is added as well. There is a setter already, but no
      corresponding getter. Fix this assymetry as well. bpf_map__set_ifindex()
      itself is converted from void function into error-returning one, similar to
      other setters. The only error returned right now is -EBUSY, if BPF map is
      already loaded and has corresponding FD.
      
      One lacking attribute with no ability to get/set or even specify it
      declaratively is numa_node. This patch fixes this gap and both adds
      programmatic getter/setter, as well as adds support for numa_node field in
      BTF-defined map.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20200621062112.3006313-1-andriin@fb.com
      1bdb6c9a
  17. 13 6月, 2020 1 次提交
  18. 02 6月, 2020 4 次提交
  19. 20 5月, 2020 1 次提交
  20. 14 5月, 2020 1 次提交
  21. 13 5月, 2020 1 次提交
  22. 11 5月, 2020 1 次提交
    • G
      bpf, libbpf: Replace zero-length array with flexible-array · 385bbf7b
      Gustavo A. R. Silva 提交于
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20200507185057.GA13981@embeddedor
      385bbf7b
  23. 10 5月, 2020 1 次提交
  24. 30 4月, 2020 1 次提交
  25. 29 4月, 2020 3 次提交
    • A
      libbpf: Fix huge memory leak in libbpf_find_vmlinux_btf_id() · 3521ffa2
      Andrii Nakryiko 提交于
      BTF object wasn't freed.
      
      Fixes: a6ed02ca ("libbpf: Load btf_vmlinux only once per object.")
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Cc: KP Singh <kpsingh@google.com>
      Link: https://lore.kernel.org/bpf/20200429012111.277390-9-andriin@fb.com
      3521ffa2
    • A
      libbpf: Add BTF-defined map-in-map support · 646f02ff
      Andrii Nakryiko 提交于
      As discussed at LPC 2019 ([0]), this patch brings (a quite belated) support
      for declarative BTF-defined map-in-map support in libbpf. It allows to define
      ARRAY_OF_MAPS and HASH_OF_MAPS BPF maps without any user-space initialization
      code involved.
      
      Additionally, it allows to initialize outer map's slots with references to
      respective inner maps at load time, also completely declaratively.
      
      Despite a weak type system of C, the way BTF-defined map-in-map definition
      works, it's actually quite hard to accidentally initialize outer map with
      incompatible inner maps. This being C, of course, it's still possible, but
      even that would be caught at load time and error returned with helpful debug
      log pointing exactly to the slot that failed to be initialized.
      
      As an example, here's a rather advanced HASH_OF_MAPS declaration and
      initialization example, filling slots #0 and #4 with two inner maps:
      
        #include <bpf/bpf_helpers.h>
      
        struct inner_map {
                __uint(type, BPF_MAP_TYPE_ARRAY);
                __uint(max_entries, 1);
                __type(key, int);
                __type(value, int);
        } inner_map1 SEC(".maps"),
          inner_map2 SEC(".maps");
      
        struct outer_hash {
                __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
                __uint(max_entries, 5);
                __uint(key_size, sizeof(int));
                __array(values, struct inner_map);
        } outer_hash SEC(".maps") = {
                .values = {
                        [0] = &inner_map2,
                        [4] = &inner_map1,
                },
        };
      
      Here's the relevant part of libbpf debug log showing pretty clearly of what's
      going on with map-in-map initialization:
      
        libbpf: .maps relo #0: for 6 value 0 rel.r_offset 96 name 260 ('inner_map1')
        libbpf: .maps relo #0: map 'outer_arr' slot [0] points to map 'inner_map1'
        libbpf: .maps relo #1: for 7 value 32 rel.r_offset 112 name 249 ('inner_map2')
        libbpf: .maps relo #1: map 'outer_arr' slot [2] points to map 'inner_map2'
        libbpf: .maps relo #2: for 7 value 32 rel.r_offset 144 name 249 ('inner_map2')
        libbpf: .maps relo #2: map 'outer_hash' slot [0] points to map 'inner_map2'
        libbpf: .maps relo #3: for 6 value 0 rel.r_offset 176 name 260 ('inner_map1')
        libbpf: .maps relo #3: map 'outer_hash' slot [4] points to map 'inner_map1'
        libbpf: map 'inner_map1': created successfully, fd=4
        libbpf: map 'inner_map2': created successfully, fd=5
        libbpf: map 'outer_hash': created successfully, fd=7
        libbpf: map 'outer_hash': slot [0] set to map 'inner_map2' fd=5
        libbpf: map 'outer_hash': slot [4] set to map 'inner_map1' fd=4
      
      Notice from the log above that fd=6 (not logged explicitly) is used for inner
      "prototype" map, necessary for creation of outer map. It is destroyed
      immediately after outer map is created.
      
      See also included selftest with some extra comments explaining extra details
      of usage. Additionally, similar initialization syntax and libbpf functionality
      can be used to do initialization of BPF_PROG_ARRAY with references to BPF
      sub-programs. This can be done in follow up patches, if there will be a demand
      for this.
      
        [0] https://linuxplumbersconf.org/event/4/contributions/448/Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20200429002739.48006-4-andriin@fb.com
      646f02ff
    • A
      libbpf: Refactor map creation logic and fix cleanup leak · 2d39d7c5
      Andrii Nakryiko 提交于
      Factor out map creation and destruction logic to simplify code and especially
      error handling. Also fix map FD leak in case of partially successful map
      creation during bpf_object load operation.
      
      Fixes: 57a00f41 ("libbpf: Add auto-pinning of maps when loading BPF objects")
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20200429002739.48006-3-andriin@fb.com
      2d39d7c5