1. 22 Jan, 2020 3 commits
  2. 21 Jan, 2020 14 commits
  3. 20 Jan, 2020 3 commits
  4. 17 Jan, 2020 10 commits
  5. 16 Jan, 2020 3 commits
  6. 15 Jan, 2020 7 commits
    • Alexei Starovoitov's avatar
      Merge branch 'bpftool-improvements' · 7bcfea96
      Alexei Starovoitov authored
      Martin Lau says:
      
      ====================
      When a map is storing a kernel's struct, its
      map_info->btf_vmlinux_value_type_id is set.  The first map type
      supporting it is BPF_MAP_TYPE_STRUCT_OPS.
      
      This series adds support to dump this kind of map with BTF.
      The first two patches are bug fixes which are only applicable to
      bpf-next.
      
      Please see individual patches for details.
      
      v3:
      - Remove unnecessary #include "libbpf_internal.h" from patch 5
      
      v2:
      - Expose bpf_find_kernel_btf() as a LIBBPF_API in patch 3 (Andrii)
      - Cache btf_vmlinux in bpftool/map.c (Andrii)
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      7bcfea96
    • Martin KaFai Lau's avatar
      bpftool: Support dumping a map with btf_vmlinux_value_type_id · 4e1ea332
      Martin KaFai Lau authored
      This patch makes bpftool support dumping a map's value properly
      when the map's value type is a type of the running kernel's btf.
      (i.e. map_info.btf_vmlinux_value_type_id is set instead of
      map_info.btf_value_type_id).  The first usecase is for the
      BPF_MAP_TYPE_STRUCT_OPS.
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200115230044.1103008-1-kafai@fb.com
      4e1ea332
    • Martin KaFai Lau's avatar
      bpftool: Add struct_ops map name · 84c72cee
      Martin KaFai Lau authored
      This patch adds BPF_MAP_TYPE_STRUCT_OPS to "struct_ops" name mapping
      so that "bpftool map show" can print the "struct_ops" map type
      properly.
      
      [root@arch-fb-vm1 bpf]# ~/devshare/fb-kernel/linux/tools/bpf/bpftool/bpftool map show id 8
      8: struct_ops  name dctcp  flags 0x0
      	key 4B  value 256B  max_entries 1  memlock 4096B
      	btf_id 7
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200115230037.1102674-1-kafai@fb.com
      84c72cee
    • Martin KaFai Lau's avatar
      libbpf: Expose bpf_find_kernel_btf as a LIBBPF_API · fb2426ad
      Martin KaFai Lau authored
      This patch exposes bpf_find_kernel_btf() as a LIBBPF_API.
      It will be used in 'bpftool map dump' in a following patch
      to dump a map with btf_vmlinux_value_type_id set.
      
      bpf_find_kernel_btf() is renamed to libbpf_find_kernel_btf()
      and moved to btf.c.  As <linux/kernel.h> is included,
      some of the max/min type casting needs to be fixed.
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200115230031.1102305-1-kafai@fb.com
      fb2426ad
    • Martin KaFai Lau's avatar
      bpftool: Fix missing BTF output for json during map dump · 188a4866
      Martin KaFai Lau authored
      The btf availability check is only done for plain text output.
      It causes the whole BTF output went missing when json_output
      is used.
      
      This patch simplifies the logic a little by avoiding passing "int btf" to
      map_dump().
      
      For plain text output, the btf_wtr is only created when the map has
      BTF (i.e. info->btf_id != 0).  The nullness of "json_writer_t *wtr"
      in map_dump() alone can decide if dumping BTF output is needed.
      As long as wtr is not NULL, map_dump() will print out the BTF-described
      data whenever a map has BTF available (i.e. info->btf_id != 0)
      regardless of json or plain-text output.
      
      In do_dump(), the "int btf" is also renamed to "int do_plain_btf".
      
      Fixes: 99f9863a ("bpftool: Match maps by name")
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Cc: Paul Chaignon <paul.chaignon@orange.com>
      Link: https://lore.kernel.org/bpf/20200115230025.1101828-1-kafai@fb.com
      188a4866
    • Martin KaFai Lau's avatar
      bpftool: Fix a leak of btf object · d7de7267
      Martin KaFai Lau authored
      When testing a map has btf or not, maps_have_btf() tests it by actually
      getting a btf_fd from sys_bpf(BPF_BTF_GET_FD_BY_ID). However, it
      forgot to btf__free() it.
      
      In maps_have_btf() stage, there is no need to test it by really
      calling sys_bpf(BPF_BTF_GET_FD_BY_ID). Testing non zero
      info.btf_id is good enough.
      
      Also, the err_close case is unnecessary, and also causes double
      close() because the calling func do_dump() will close() all fds again.
      
      Fixes: 99f9863a ("bpftool: Match maps by name")
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Cc: Paul Chaignon <paul.chaignon@orange.com>
      Link: https://lore.kernel.org/bpf/20200115230019.1101352-1-kafai@fb.com
      d7de7267
    • Alexei Starovoitov's avatar
      Merge branch 'bpf-batch-ops' · 990bca1f
      Alexei Starovoitov authored
      Brian Vazquez says:
      
      ====================
      This patch series introduce batch ops that can be added to bpf maps to
      lookup/lookup_and_delete/update/delete more than 1 element at the time,
      this is specially useful when syscall overhead is a problem and in case
      of hmap it will provide a reliable way of traversing them.
      
      The implementation inclues a generic approach that could potentially be
      used by any bpf map and adds it to arraymap, it also includes the specific
      implementation of hashmaps which are traversed using buckets instead
      of keys.
      
      The bpf syscall subcommands introduced are:
      
        BPF_MAP_LOOKUP_BATCH
        BPF_MAP_LOOKUP_AND_DELETE_BATCH
        BPF_MAP_UPDATE_BATCH
        BPF_MAP_DELETE_BATCH
      
      The UAPI attribute is:
      
        struct { /* struct used by BPF_MAP_*_BATCH commands */
               __aligned_u64   in_batch;       /* start batch,
                                                * NULL to start from beginning
                                                */
               __aligned_u64   out_batch;      /* output: next start batch */
               __aligned_u64   keys;
               __aligned_u64   values;
               __u32           count;          /* input/output:
                                                * input: # of key/value
                                                * elements
                                                * output: # of filled elements
                                                */
               __u32           map_fd;
               __u64           elem_flags;
               __u64           flags;
        } batch;
      
      in_batch and out_batch are only used for lookup and lookup_and_delete since
      those are the only two operations that attempt to traverse the map.
      
      update/delete batch ops should provide the keys/values that user wants
      to modify.
      
      Here are the previous discussions on the batch processing:
       - https://lore.kernel.org/bpf/20190724165803.87470-1-brianvv@google.com/
       - https://lore.kernel.org/bpf/20190829064502.2750303-1-yhs@fb.com/
       - https://lore.kernel.org/bpf/20190906225434.3635421-1-yhs@fb.com/
      
      Changelog sinve v4:
       - Remove unnecessary checks from libbpf API (Andrii Nakryiko)
       - Move DECLARE_LIBBPF_OPTS with all var declarations (Andrii Nakryiko)
       - Change bucket internal buffer size to 5 entries (Yonghong Song)
       - Fix some minor bugs in hashtab batch ops implementation (Yonghong Song)
      
      Changelog sinve v3:
       - Do not use copy_to_user inside atomic region (Yonghong Song)
       - Use _opts approach on libbpf APIs (Andrii Nakryiko)
       - Drop generic_map_lookup_and_delete_batch support
       - Free malloc-ed memory in tests (Yonghong Song)
       - Reverse christmas tree (Yonghong Song)
       - Add acked labels
      
      Changelog sinve v2:
       - Add generic batch support for lpm_trie and test it (Yonghong Song)
       - Use define MAP_LOOKUP_RETRIES for retries (John Fastabend)
       - Return errors directly and remove labels (Yonghong Song)
       - Insert new API functions into libbpf alphabetically (Yonghong Song)
       - Change hlist_nulls_for_each_entry_rcu to
         hlist_nulls_for_each_entry_safe in htab batch ops (Yonghong Song)
      
      Changelog since v1:
       - Fix SOB ordering and remove Co-authored-by tag (Alexei Starovoitov)
      
      Changelog since RFC:
       - Change batch to in_batch and out_batch to support more flexible opaque
         values to iterate the bpf maps.
       - Remove update/delete specific batch ops for htab and use the generic
         implementations instead.
      ====================
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      990bca1f