1. 03 12月, 2021 11 次提交
  2. 01 12月, 2021 2 次提交
  3. 30 11月, 2021 2 次提交
  4. 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
  5. 27 11月, 2021 1 次提交
    • T
      bpf, mips: Fix build errors about __NR_bpf undeclared · e32cb12f
      Tiezhu Yang 提交于
      Add the __NR_bpf definitions to fix the following build errors for mips:
      
        $ cd tools/bpf/bpftool
        $ make
        [...]
        bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
         #  error __NR_bpf not defined. libbpf does not support your arch.
            ^~~~~
        bpf.c: In function ‘sys_bpf’:
        bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
          return syscall(__NR_bpf, cmd, attr, size);
                         ^~~~~~~~
                         __NR_brk
        [...]
        In file included from gen_loader.c:15:0:
        skel_internal.h: In function ‘skel_sys_bpf’:
        skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
          return syscall(__NR_bpf, cmd, attr, size);
                         ^~~~~~~~
                         __NR_brk
      
      We can see the following generated definitions:
      
        $ grep -r "#define __NR_bpf" arch/mips
        arch/mips/include/generated/uapi/asm/unistd_o32.h:#define __NR_bpf (__NR_Linux + 355)
        arch/mips/include/generated/uapi/asm/unistd_n64.h:#define __NR_bpf (__NR_Linux + 315)
        arch/mips/include/generated/uapi/asm/unistd_n32.h:#define __NR_bpf (__NR_Linux + 319)
      
      The __NR_Linux is defined in arch/mips/include/uapi/asm/unistd.h:
      
        $ grep -r "#define __NR_Linux" arch/mips
        arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	4000
        arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	5000
        arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	6000
      
      That is to say, __NR_bpf is:
      
        4000 + 355 = 4355 for mips o32,
        6000 + 319 = 6319 for mips n32,
        5000 + 315 = 5315 for mips n64.
      
      So use the GCC pre-defined macro _ABIO32, _ABIN32 and _ABI64 [1] to define
      the corresponding __NR_bpf.
      
      This patch is similar with commit bad1926d ("bpf, s390: fix build for
      libbpf and selftest suite").
      
        [1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/mips/mips.h#l549Signed-off-by: NTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/1637804167-8323-1-git-send-email-yangtiezhu@loongson.cn
      e32cb12f
  6. 26 11月, 2021 8 次提交
  7. 20 11月, 2021 1 次提交
  8. 19 11月, 2021 2 次提交
  9. 16 11月, 2021 1 次提交
    • Y
      libbpf: Fix a couple of missed btf_type_tag handling in btf.c · 69a055d5
      Yonghong Song 提交于
      Commit 2dc1e488 ("libbpf: Support BTF_KIND_TYPE_TAG") added the
      BTF_KIND_TYPE_TAG support. But to test vmlinux build with ...
      
        #define __user __attribute__((btf_type_tag("user")))
      
      ... I needed to sync libbpf repo and manually copy libbpf sources to
      pahole. To simplify process, I used BTF_KIND_RESTRICT to simulate the
      BTF_KIND_TYPE_TAG with vmlinux build as "restrict" modifier is barely
      used in kernel.
      
      But this approach missed one case in dedup with structures where
      BTF_KIND_RESTRICT is handled and BTF_KIND_TYPE_TAG is not handled in
      btf_dedup_is_equiv(), and this will result in a pahole dedup failure.
      This patch fixed this issue and a selftest is added in the subsequent
      patch to test this scenario.
      
      The other missed handling is in btf__resolve_size(). Currently the compiler
      always emit like PTR->TYPE_TAG->... so in practice we don't hit the missing
      BTF_KIND_TYPE_TAG handling issue with compiler generated code. But lets
      add case BTF_KIND_TYPE_TAG in the switch statement to be future proof.
      
      Fixes: 2dc1e488 ("libbpf: Support BTF_KIND_TYPE_TAG")
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20211115163937.3922235-1-yhs@fb.com
      69a055d5
  10. 12 11月, 2021 5 次提交
    • Y
      libbpf: Support BTF_KIND_TYPE_TAG · 2dc1e488
      Yonghong Song 提交于
      Add libbpf support for BTF_KIND_TYPE_TAG.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211112012614.1505315-1-yhs@fb.com
      2dc1e488
    • A
      libbpf: Make perf_buffer__new() use OPTS-based interface · 41788934
      Andrii Nakryiko 提交于
      Add new variants of perf_buffer__new() and perf_buffer__new_raw() that
      use OPTS-based options for future extensibility ([0]). Given all the
      currently used API names are best fits, re-use them and use
      ___libbpf_override() approach and symbol versioning to preserve ABI and
      source code compatibility. struct perf_buffer_opts and struct
      perf_buffer_raw_opts are kept as well, but they are restructured such
      that they are OPTS-based when used with new APIs. For struct
      perf_buffer_raw_opts we keep few fields intact, so we have to also
      preserve the memory location of them both when used as OPTS and for
      legacy API variants. This is achieved with anonymous padding for OPTS
      "incarnation" of the struct.  These pads can be eventually used for new
      options.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/311Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211111053624.190580-6-andrii@kernel.org
      41788934
    • A
      libbpf: Ensure btf_dump__new() and btf_dump_opts are future-proof · 6084f5dc
      Andrii Nakryiko 提交于
      Change btf_dump__new() and corresponding struct btf_dump_ops structure
      to be extensible by using OPTS "framework" ([0]). Given we don't change
      the names, we use a similar approach as with bpf_prog_load(), but this
      time we ended up with two APIs with the same name and same number of
      arguments, so overloading based on number of arguments with
      ___libbpf_override() doesn't work.
      
      Instead, use "overloading" based on types. In this particular case,
      print callback has to be specified, so we detect which argument is
      a callback. If it's 4th (last) argument, old implementation of API is
      used by user code. If not, it must be 2nd, and thus new implementation
      is selected. The rest is handled by the same symbol versioning approach.
      
      btf_ext argument is dropped as it was never used and isn't necessary
      either. If in the future we'll need btf_ext, that will be added into
      OPTS-based struct btf_dump_opts.
      
      struct btf_dump_opts is reused for both old API and new APIs. ctx field
      is marked deprecated in v0.7+ and it's put at the same memory location
      as OPTS's sz field. Any user of new-style btf_dump__new() will have to
      set sz field and doesn't/shouldn't use ctx, as ctx is now passed along
      the callback as mandatory input argument, following the other APIs in
      libbpf that accept callbacks consistently.
      
      Again, this is quite ugly in implementation, but is done in the name of
      backwards compatibility and uniform and extensible future APIs (at the
      same time, sigh). And it will be gone in libbpf 1.0.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/283Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211111053624.190580-5-andrii@kernel.org
      6084f5dc
    • A
      libbpf: Turn btf_dedup_opts into OPTS-based struct · 957d350a
      Andrii Nakryiko 提交于
      btf__dedup() and struct btf_dedup_opts were added before we figured out
      OPTS mechanism. As such, btf_dedup_opts is non-extensible without
      breaking an ABI and potentially crashing user application.
      
      Unfortunately, btf__dedup() and btf_dedup_opts are short and succinct
      names that would be great to preserve and use going forward. So we use
      ___libbpf_override() macro approach, used previously for bpf_prog_load()
      API, to define a new btf__dedup() variant that accepts only struct btf *
      and struct btf_dedup_opts * arguments, and rename the old btf__dedup()
      implementation into btf__dedup_deprecated(). This keeps both source and
      binary compatibility with old and new applications.
      
      The biggest problem was struct btf_dedup_opts, which wasn't OPTS-based,
      and as such doesn't have `size_t sz;` as a first field. But btf__dedup()
      is a pretty rarely used API and I believe that the only currently known
      users (besides selftests) are libbpf's own bpf_linker and pahole.
      Neither use case actually uses options and just passes NULL. So instead
      of doing extra hacks, just rewrite struct btf_dedup_opts into OPTS-based
      one, move btf_ext argument into those opts (only bpf_linker needs to
      dedup btf_ext, so it's not a typical thing to specify), and drop never
      used `dont_resolve_fwds` option (it was never used anywhere, AFAIK, it
      makes BTF dedup much less useful and efficient).
      
      Just in case, for old implementation, btf__dedup_deprecated(), detect
      non-NULL options and error out with helpful message, to help users
      migrate, if there are any user playing with btf__dedup().
      
      The last remaining piece is dedup_table_size, which is another
      anachronism from very early days of BTF dedup. Since then it has been
      reduced to the only valid value, 1, to request forced hash collisions.
      This is only used during testing. So instead introduce a bool flag to
      force collisions explicitly.
      
      This patch also adapts selftests to new btf__dedup() and btf_dedup_opts
      use to avoid selftests breakage.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/281Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211111053624.190580-4-andrii@kernel.org
      957d350a
    • A
      libbpf: Add ability to get/set per-program load flags · a6ca7158
      Andrii Nakryiko 提交于
      Add bpf_program__flags() API to retrieve prog_flags that will be (or
      were) supplied to BPF_PROG_LOAD command.
      
      Also add bpf_program__set_extra_flags() API to allow to set *extra*
      flags, in addition to those determined by program's SEC() definition.
      Such flags are logically OR'ed with libbpf-derived flags.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211111051758.92283-2-andrii@kernel.org
      a6ca7158
  11. 10 11月, 2021 1 次提交
  12. 08 11月, 2021 5 次提交