1. 26 Oct, 2021 6 commits
    • Andrii Nakryiko's avatar
      Merge branch 'bpftool: Switch to libbpf's hashmap for referencing BPF objects' · 9327acd0
      Andrii Nakryiko authored
      Quentin Monnet says:
      
      ====================
      
      When listing BPF objects, bpftool can print a number of properties about
      items holding references to these objects. For example, it can show pinned
      paths for BPF programs, maps, and links; or programs and maps using a given
      BTF object; or the names and PIDs of processes referencing BPF objects. To
      collect this information, bpftool uses hash maps (to be clear: the data
      structures, inside bpftool - we are not talking of BPF maps). It uses the
      implementation available from the kernel, and picks it up from
      tools/include/linux/hashtable.h.
      
      This patchset converts bpftool's hash maps to a distinct implementation
      instead, the one coming with libbpf. The main motivation for this change is
      that it should ease the path towards a potential out-of-tree mirror for
      bpftool, like the one libbpf already has. Although it's not perfect to
      depend on libbpf's internal components, bpftool is intimately tied with the
      library anyway, and this looks better than depending too much on (non-UAPI)
      kernel headers.
      
      The first two patches contain preparatory work on the Makefile and on the
      initialisation of the hash maps for collecting pinned paths for objects.
      Then the transition is split into several steps, one for each kind of
      properties for which the collection is backed by hash maps.
      
      v2:
        - Move hashmap cleanup for pinned paths for links from do_detach() to
          do_show().
        - Handle errors on hashmap__append() (in three of the patches).
        - Rename bpftool_hash_fn() and bpftool_equal_fn() as hash_fn_for_key_id()
          and equal_fn_for_key_id(), respectively.
        - Add curly braces for hashmap__for_each_key_entry() { } in
          show_btf_plain() and show_btf_json(), where the flow was difficult to
          read.
      ====================
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      9327acd0
    • Quentin Monnet's avatar
      bpftool: Switch to libbpf's hashmap for PIDs/names references · d6699f8e
      Quentin Monnet authored
      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: default avatarQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-6-quentin@isovalent.com
      d6699f8e
    • Quentin Monnet's avatar
      bpftool: Switch to libbpf's hashmap for programs/maps in BTF listing · 2828d0d7
      Quentin Monnet authored
      In order to show BPF programs and maps using BTF objects when the latter
      are being listed, bpftool creates hash maps to store all relevant items.
      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 commit focuses on the two hash maps used by bpftool when listing
      BTF objects to store references to programs and maps, and convert them
      to the libbpf's implementation.
      Signed-off-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-5-quentin@isovalent.com
      2828d0d7
    • Quentin Monnet's avatar
      bpftool: Switch to libbpf's hashmap for pinned paths of BPF objects · 8f184732
      Quentin Monnet authored
      In order to show pinned paths for BPF programs, maps, or links when
      listing them with the "-f" option, bpftool creates hash maps to store
      all relevant paths under the bpffs. So far, it would rely on the
      kernel implementation (from tools/include/linux/hashtable.h).
      
      We can make bpftool rely on libbpf's implementation instead. 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 commit is the first step of the conversion: the hash maps for
      pinned paths for programs, maps, and links are converted to libbpf's
      hashmap.{c,h}. Other hash maps used for the PIDs of process holding
      references to BPF objects are left unchanged for now. On the build side,
      this requires adding a dependency to a second header internal to libbpf,
      and making it a dependency for the bootstrap bpftool version as well.
      The rest of the changes are a rather straightforward conversion.
      Signed-off-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-4-quentin@isovalent.com
      8f184732
    • Quentin Monnet's avatar
      bpftool: Do not expose and init hash maps for pinned path in main.c · 46241271
      Quentin Monnet authored
      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: default avatarQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-3-quentin@isovalent.com
      46241271
    • Quentin Monnet's avatar
      bpftool: Remove Makefile dep. on $(LIBBPF) for $(LIBBPF_INTERNAL_HDRS) · 8b6c4624
      Quentin Monnet authored
      The dependency is only useful to make sure that the $(LIBBPF_HDRS_DIR)
      directory is created before we try to install locally the required
      libbpf internal header. Let's create this directory properly instead.
      
      This is in preparation of making $(LIBBPF_INTERNAL_HDRS) a dependency to
      the bootstrap bpftool version, in which case we want no dependency on
      $(LIBBPF).
      Signed-off-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-2-quentin@isovalent.com
      8b6c4624
  2. 25 Oct, 2021 5 commits
  3. 23 Oct, 2021 8 commits
  4. 22 Oct, 2021 21 commits