1. 03 12月, 2021 5 次提交
  2. 30 11月, 2021 1 次提交
  3. 29 11月, 2021 1 次提交
    • H
      libbpf: Support static initialization of BPF_MAP_TYPE_PROG_ARRAY · 341ac5ff
      Hengqi Chen 提交于
      Support static initialization of BPF_MAP_TYPE_PROG_ARRAY with a
      syntax similar to map-in-map initialization ([0]):
      
          SEC("socket")
          int tailcall_1(void *ctx)
          {
              return 0;
          }
      
          struct {
              __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
              __uint(max_entries, 2);
              __uint(key_size, sizeof(__u32));
              __array(values, int (void *));
          } prog_array_init SEC(".maps") = {
              .values = {
                  [1] = (void *)&tailcall_1,
              },
          };
      
      Here's the relevant part of libbpf debug log showing what's
      going on with prog-array initialization:
      
      libbpf: sec '.relsocket': collecting relocation for section(3) 'socket'
      libbpf: sec '.relsocket': relo #0: insn #2 against 'prog_array_init'
      libbpf: prog 'entry': found map 0 (prog_array_init, sec 4, off 0) for insn #0
      libbpf: .maps relo #0: for 3 value 0 rel->r_offset 32 name 53 ('tailcall_1')
      libbpf: .maps relo #0: map 'prog_array_init' slot [1] points to prog 'tailcall_1'
      libbpf: map 'prog_array_init': created successfully, fd=5
      libbpf: map 'prog_array_init': slot [1] set to prog 'tailcall_1' fd=6
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/354Signed-off-by: NHengqi Chen <hengqi.chen@gmail.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211128141633.502339-2-hengqi.chen@gmail.com
      341ac5ff
  4. 26 11月, 2021 4 次提交
  5. 20 11月, 2021 1 次提交
  6. 19 11月, 2021 1 次提交
  7. 12 11月, 2021 3 次提交
  8. 08 11月, 2021 4 次提交
  9. 04 11月, 2021 6 次提交
  10. 29 10月, 2021 3 次提交
  11. 28 10月, 2021 1 次提交
  12. 26 10月, 2021 4 次提交
  13. 23 10月, 2021 2 次提交
  14. 22 10月, 2021 4 次提交
    • A
      libbpf: Simplify look up by name of internal maps · 26071635
      Andrii Nakryiko 提交于
      Map name that's assigned to internal maps (.rodata, .data, .bss, etc)
      consist of a small prefix of bpf_object's name and ELF section name as
      a suffix. This makes it hard for users to "guess" the name to use for
      looking up by name with bpf_object__find_map_by_name() API.
      
      One proposal was to drop object name prefix from the map name and just
      use ".rodata", ".data", etc, names. One downside called out was that
      when multiple BPF applications are active on the host, it will be hard
      to distinguish between multiple instances of .rodata and know which BPF
      object (app) they belong to. Having few first characters, while quite
      limiting, still can give a bit of a clue, in general.
      
      Note, though, that btf_value_type_id for such global data maps (ARRAY)
      points to DATASEC type, which encodes full ELF name, so tools like
      bpftool can take advantage of this fact to "recover" full original name
      of the map. This is also the reason why for custom .data.* and .rodata.*
      maps libbpf uses only their ELF names and doesn't prepend object name at
      all.
      
      Another downside of such approach is that it is not backwards compatible
      and, among direct use of bpf_object__find_map_by_name() API, will break
      any BPF skeleton generated using bpftool that was compiled with older
      libbpf version.
      
      Instead of causing all this pain, libbpf will still generate map name
      using a combination of object name and ELF section name, but it will
      allow looking such maps up by their natural names, which correspond to
      their respective ELF section names. This means non-truncated ELF section
      names longer than 15 characters are going to be expected and supported.
      
      With such set up, we get the best of both worlds: leave small bits of
      a clue about BPF application that instantiated such maps, as well as
      making it easy for user apps to lookup such maps at runtime. In this
      sense it closes corresponding libbpf 1.0 issue ([0]).
      
      BPF skeletons will continue using full names for lookups.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/275Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20211021014404.2635234-10-andrii@kernel.org
      26071635
    • A
      libbpf: Support multiple .rodata.* and .data.* BPF maps · aed65917
      Andrii Nakryiko 提交于
      Add support for having multiple .rodata and .data data sections ([0]).
      .rodata/.data are supported like the usual, but now also
      .rodata.<whatever> and .data.<whatever> are also supported. Each such
      section will get its own backing BPF_MAP_TYPE_ARRAY, just like
      .rodata and .data.
      
      Multiple .bss maps are not supported, as the whole '.bss' name is
      confusing and might be deprecated soon, as well as user would need to
      specify custom ELF section with SEC() attribute anyway, so might as well
      stick to just .data.* and .rodata.* convention.
      
      User-visible map name for such new maps is going to be just their ELF
      section names.
      
        [0] https://github.com/libbpf/libbpf/issues/274Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20211021014404.2635234-8-andrii@kernel.org
      aed65917
    • A
      libbpf: Remove assumptions about uniqueness of .rodata/.data/.bss maps · 25bbbd7a
      Andrii Nakryiko 提交于
      Remove internal libbpf assumption that there can be only one .rodata,
      .data, and .bss map per BPF object. To achieve that, extend and
      generalize the scheme that was used for keeping track of relocation ELF
      sections. Now each ELF section has a temporary extra index that keeps
      track of logical type of ELF section (relocations, data, read-only data,
      BSS). Switch relocation to this scheme, as well as .rodata/.data/.bss
      handling.
      
      We don't yet allow multiple .rodata, .data, and .bss sections, but no
      libbpf internal code makes an assumption that there can be only one of
      each and thus they can be explicitly referenced by a single index. Next
      patches will actually allow multiple .rodata and .data sections.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20211021014404.2635234-5-andrii@kernel.org
      25bbbd7a
    • A
      libbpf: Use Elf64-specific types explicitly for dealing with ELF · ad23b723
      Andrii Nakryiko 提交于
      Minimize the usage of class-agnostic gelf_xxx() APIs from libelf. These
      APIs require copying ELF data structures into local GElf_xxx structs and
      have a more cumbersome API. BPF ELF file is defined to be always 64-bit
      ELF object, even when intended to be run on 32-bit host architectures,
      so there is no need to do class-agnostic conversions everywhere. BPF
      static linker implementation within libbpf has been using Elf64-specific
      types since initial implementation.
      
      Add two simple helpers, elf_sym_by_idx() and elf_rel_by_idx(), for more
      succinct direct access to ELF symbol and relocation records within ELF
      data itself and switch all the GElf_xxx usage into Elf64_xxx
      equivalents. The only remaining place within libbpf.c that's still using
      gelf API is gelf_getclass(), as there doesn't seem to be a direct way to
      get underlying ELF bitness.
      
      No functional changes intended.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20211021014404.2635234-4-andrii@kernel.org
      ad23b723