1. 21 8月, 2019 1 次提交
  2. 18 8月, 2019 1 次提交
  3. 16 8月, 2019 1 次提交
    • A
      libbpf: make libbpf.map source of truth for libbpf version · dadb81d0
      Andrii Nakryiko 提交于
      Currently libbpf version is specified in 2 places: libbpf.map and
      Makefile. They easily get out of sync and it's very easy to update one,
      but forget to update another one. In addition, Github projection of
      libbpf has to maintain its own version which has to be remembered to be
      kept in sync manually, which is very error-prone approach.
      
      This patch makes libbpf.map a source of truth for libbpf version and
      uses shell invocation to parse out correct full and major libbpf version
      to use during build. Now we need to make sure that once new release
      cycle starts, we need to add (initially) empty section to libbpf.map
      with correct latest version.
      
      This also will make it possible to keep Github projection consistent
      with kernel sources version of libbpf by adopting similar parsing of
      version from libbpf.map.
      
      v2->v3:
      - grep -o + sort -rV (Andrey);
      
      v1->v2:
      - eager version vars evaluation (Jakub);
      - simplified version regex (Andrey);
      
      Cc: Andrey Ignatov <rdna@fb.com>
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      dadb81d0
  4. 14 8月, 2019 1 次提交
  5. 08 8月, 2019 4 次提交
  6. 30 7月, 2019 1 次提交
  7. 29 7月, 2019 1 次提交
  8. 28 7月, 2019 1 次提交
  9. 26 7月, 2019 1 次提交
  10. 24 7月, 2019 2 次提交
    • A
      libbpf: provide more helpful message on uninitialized global var · f2a3e4e9
      Andrii Nakryiko 提交于
      When BPF program defines uninitialized global variable, it's put into
      a special COMMON section. Libbpf will reject such programs, but will
      provide very unhelpful message with garbage-looking section index.
      
      This patch detects special section cases and gives more explicit error
      message.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      f2a3e4e9
    • I
      libbpf: fix using uninitialized ioctl results · decb705e
      Ilya Maximets 提交于
      'channels.max_combined' initialized only on ioctl success and
      errno is only valid on ioctl failure.
      
      The code doesn't produce any runtime issues, but makes memory
      sanitizers angry:
      
       Conditional jump or move depends on uninitialised value(s)
          at 0x55C056F: xsk_get_max_queues (xsk.c:336)
          by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354)
          by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447)
          by 0x55C0E57: xsk_socket__create (xsk.c:601)
        Uninitialised value was created by a stack allocation
          at 0x55C04CD: xsk_get_max_queues (xsk.c:318)
      
      Additionally fixed warning on uninitialized bytes in ioctl arguments:
      
       Syscall param ioctl(SIOCETHTOOL) points to uninitialised byte(s)
          at 0x648D45B: ioctl (in /usr/lib64/libc-2.28.so)
          by 0x55C0546: xsk_get_max_queues (xsk.c:330)
          by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354)
          by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447)
          by 0x55C0E57: xsk_socket__create (xsk.c:601)
        Address 0x1ffefff378 is on thread 1's stack
        in frame #1, created by xsk_get_max_queues (xsk.c:318)
        Uninitialised value was created by a stack allocation
          at 0x55C04CD: xsk_get_max_queues (xsk.c:318)
      
      CC: Magnus Karlsson <magnus.karlsson@intel.com>
      Fixes: 1cad0788 ("libbpf: add support for using AF_XDP sockets")
      Signed-off-by: NIlya Maximets <i.maximets@samsung.com>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      decb705e
  11. 22 7月, 2019 2 次提交
  12. 20 7月, 2019 2 次提交
  13. 17 7月, 2019 1 次提交
  14. 12 7月, 2019 1 次提交
  15. 08 7月, 2019 3 次提交
    • A
      libbpf: add perf_buffer_ prefix to README · cd07a95f
      Andrii Nakryiko 提交于
      perf_buffer "object" is part of libbpf API now, add it to the list of
      libbpf function prefixes.
      Suggested-by: NDaniel Borkman <daniel@iogearbox.net>
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      cd07a95f
    • A
      libbpf: auto-set PERF_EVENT_ARRAY size to number of CPUs · d7ff34d5
      Andrii Nakryiko 提交于
      For BPF_MAP_TYPE_PERF_EVENT_ARRAY typically correct size is number of
      possible CPUs. This is impossible to specify at compilation time. This
      change adds automatic setting of PERF_EVENT_ARRAY size to number of
      system CPUs, unless non-zero size is specified explicitly. This allows
      to adjust size for advanced specific cases, while providing convenient
      and logical defaults.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      d7ff34d5
    • A
      libbpf: add perf buffer API · fb84b822
      Andrii Nakryiko 提交于
      BPF_MAP_TYPE_PERF_EVENT_ARRAY map is often used to send data from BPF program
      to user space for additional processing. libbpf already has very low-level API
      to read single CPU perf buffer, bpf_perf_event_read_simple(), but it's hard to
      use and requires a lot of code to set everything up. This patch adds
      perf_buffer abstraction on top of it, abstracting setting up and polling
      per-CPU logic into simple and convenient API, similar to what BCC provides.
      
      perf_buffer__new() sets up per-CPU ring buffers and updates corresponding BPF
      map entries. It accepts two user-provided callbacks: one for handling raw
      samples and one for get notifications of lost samples due to buffer overflow.
      
      perf_buffer__new_raw() is similar, but provides more control over how
      perf events are set up (by accepting user-provided perf_event_attr), how
      they are handled (perf_event_header pointer is passed directly to
      user-provided callback), and on which CPUs ring buffers are created
      (it's possible to provide a list of CPUs and corresponding map keys to
      update). This API allows advanced users fuller control.
      
      perf_buffer__poll() is used to fetch ring buffer data across all CPUs,
      utilizing epoll instance.
      
      perf_buffer__free() does corresponding clean up and unsets FDs from BPF map.
      
      All APIs are not thread-safe. User should ensure proper locking/coordination if
      used in multi-threaded set up.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      fb84b822
  16. 06 7月, 2019 7 次提交
  17. 03 7月, 2019 2 次提交
  18. 28 6月, 2019 3 次提交
  19. 26 6月, 2019 1 次提交
  20. 25 6月, 2019 1 次提交
  21. 19 6月, 2019 1 次提交
  22. 18 6月, 2019 2 次提交
    • A
      libbpf: allow specifying map definitions using BTF · abd29c93
      Andrii Nakryiko 提交于
      This patch adds support for a new way to define BPF maps. It relies on
      BTF to describe mandatory and optional attributes of a map, as well as
      captures type information of key and value naturally. This eliminates
      the need for BPF_ANNOTATE_KV_PAIR hack and ensures key/value sizes are
      always in sync with the key/value type.
      
      Relying on BTF, this approach allows for both forward and backward
      compatibility w.r.t. extending supported map definition features. By
      default, any unrecognized attributes are treated as an error, but it's
      possible relax this using MAPS_RELAX_COMPAT flag. New attributes, added
      in the future will need to be optional.
      
      The outline of the new map definition (short, BTF-defined maps) is as follows:
      1. All the maps should be defined in .maps ELF section. It's possible to
         have both "legacy" map definitions in `maps` sections and BTF-defined
         maps in .maps sections. Everything will still work transparently.
      2. The map declaration and initialization is done through
         a global/static variable of a struct type with few mandatory and
         extra optional fields:
         - type field is mandatory and specified type of BPF map;
         - key/value fields are mandatory and capture key/value type/size information;
         - max_entries attribute is optional; if max_entries is not specified or
           initialized, it has to be provided in runtime through libbpf API
           before loading bpf_object;
         - map_flags is optional and if not defined, will be assumed to be 0.
      3. Key/value fields should be **a pointer** to a type describing
         key/value. The pointee type is assumed (and will be recorded as such
         and used for size determination) to be a type describing key/value of
         the map. This is done to save excessive amounts of space allocated in
         corresponding ELF sections for key/value of big size.
      4. As some maps disallow having BTF type ID associated with key/value,
         it's possible to specify key/value size explicitly without
         associating BTF type ID with it. Use key_size and value_size fields
         to do that (see example below).
      
      Here's an example of simple ARRAY map defintion:
      
      struct my_value { int x, y, z; };
      
      struct {
      	int type;
      	int max_entries;
      	int *key;
      	struct my_value *value;
      } btf_map SEC(".maps") = {
      	.type = BPF_MAP_TYPE_ARRAY,
      	.max_entries = 16,
      };
      
      This will define BPF ARRAY map 'btf_map' with 16 elements. The key will
      be of type int and thus key size will be 4 bytes. The value is struct
      my_value of size 12 bytes. This map can be used from C code exactly the
      same as with existing maps defined through struct bpf_map_def.
      
      Here's an example of STACKMAP definition (which currently disallows BTF type
      IDs for key/value):
      
      struct {
      	__u32 type;
      	__u32 max_entries;
      	__u32 map_flags;
      	__u32 key_size;
      	__u32 value_size;
      } stackmap SEC(".maps") = {
      	.type = BPF_MAP_TYPE_STACK_TRACE,
      	.max_entries = 128,
      	.map_flags = BPF_F_STACK_BUILD_ID,
      	.key_size = sizeof(__u32),
      	.value_size = PERF_MAX_STACK_DEPTH * sizeof(struct bpf_stack_build_id),
      };
      
      This approach is naturally extended to support map-in-map, by making a value
      field to be another struct that describes inner map. This feature is not
      implemented yet. It's also possible to incrementally add features like pinning
      with full backwards and forward compatibility. Support for static
      initialization of BPF_MAP_TYPE_PROG_ARRAY using pointers to BPF programs
      is also on the roadmap.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      abd29c93
    • A
      libbpf: split initialization and loading of BTF · 063183bf
      Andrii Nakryiko 提交于
      Libbpf does sanitization of BTF before loading it into kernel, if kernel
      doesn't support some of newer BTF features. This removes some of the
      important information from BTF (e.g., DATASEC and VAR description),
      which will be used for map construction. This patch splits BTF
      processing into initialization step, in which BTF is initialized from
      ELF and all the original data is still preserved; and
      sanitization/loading step, which ensures that BTF is safe to load into
      kernel. This allows to use full BTF information to construct maps, while
      still loading valid BTF into older kernels.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      063183bf