1. 29 9月, 2020 1 次提交
  2. 19 8月, 2020 3 次提交
  3. 14 8月, 2020 1 次提交
    • A
      libbpf: Handle BTF pointer sizes more carefully · 44ad23df
      Andrii Nakryiko 提交于
      With libbpf and BTF it is pretty common to have libbpf built for one
      architecture, while BTF information was generated for a different architecture
      (typically, but not always, BPF). In such case, the size of a pointer might
      differ betweem architectures. libbpf previously was always making an
      assumption that pointer size for BTF is the same as native architecture
      pointer size, but that breaks for cases where libbpf is built as 32-bit
      library, while BTF is for 64-bit architecture.
      
      To solve this, add heuristic to determine pointer size by searching for `long`
      or `unsigned long` integer type and using its size as a pointer size. Also,
      allow to override the pointer size with a new API btf__set_pointer_size(), for
      cases where application knows which pointer size should be used. User
      application can check what libbpf "guessed" by looking at the result of
      btf__pointer_size(). If it's not 0, then libbpf successfully determined a
      pointer size, otherwise native arch pointer size will be used.
      
      For cases where BTF is parsed from ELF file, use ELF's class (32-bit or
      64-bit) to determine pointer size.
      
      Fixes: 8a138aed ("bpf: btf: Add BTF support to libbpf")
      Fixes: 351131b5 ("libbpf: add btf_dump API for BTF-to-C conversion")
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200813204945.1020225-5-andriin@fb.com
      44ad23df
  4. 07 8月, 2020 1 次提交
  5. 03 8月, 2020 1 次提交
  6. 31 7月, 2020 1 次提交
  7. 10 7月, 2020 1 次提交
  8. 09 7月, 2020 1 次提交
  9. 26 3月, 2020 1 次提交
  10. 16 1月, 2020 1 次提交
  11. 11 1月, 2020 1 次提交
  12. 16 12月, 2019 3 次提交
    • P
      libbpf: Fix build by renaming variables · a79ac2d1
      Prashant Bhole 提交于
      In btf__align_of() variable name 't' is shadowed by inner block
      declaration of another variable with same name. Patch renames
      variables in order to fix it.
      
        CC       sharedobjs/btf.o
      btf.c: In function ‘btf__align_of’:
      btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
        303 |   int i, align = 1, t;
            |                     ^
      btf.c:283:25: note: shadowed declaration is here
        283 |  const struct btf_type *t = btf__type_by_id(btf, id);
            |
      
      Fixes: 3d208f4c ("libbpf: Expose btf__align_of() API")
      Signed-off-by: NPrashant Bhole <prashantbhole.linux@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: NToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/bpf/20191216082738.28421-1-prashantbhole.linux@gmail.com
      a79ac2d1
    • A
      libbpf: Support libbpf-provided extern variables · 166750bc
      Andrii Nakryiko 提交于
      Add support for extern variables, provided to BPF program by libbpf. Currently
      the following extern variables are supported:
        - LINUX_KERNEL_VERSION; version of a kernel in which BPF program is
          executing, follows KERNEL_VERSION() macro convention, can be 4- and 8-byte
          long;
        - CONFIG_xxx values; a set of values of actual kernel config. Tristate,
          boolean, strings, and integer values are supported.
      
      Set of possible values is determined by declared type of extern variable.
      Supported types of variables are:
      - Tristate values. Are represented as `enum libbpf_tristate`. Accepted values
        are **strictly** 'y', 'n', or 'm', which are represented as TRI_YES, TRI_NO,
        or TRI_MODULE, respectively.
      - Boolean values. Are represented as bool (_Bool) types. Accepted values are
        'y' and 'n' only, turning into true/false values, respectively.
      - Single-character values. Can be used both as a substritute for
        bool/tristate, or as a small-range integer:
        - 'y'/'n'/'m' are represented as is, as characters 'y', 'n', or 'm';
        - integers in a range [-128, 127] or [0, 255] (depending on signedness of
          char in target architecture) are recognized and represented with
          respective values of char type.
      - Strings. String values are declared as fixed-length char arrays. String of
        up to that length will be accepted and put in first N bytes of char array,
        with the rest of bytes zeroed out. If config string value is longer than
        space alloted, it will be truncated and warning message emitted. Char array
        is always zero terminated. String literals in config have to be enclosed in
        double quotes, just like C-style string literals.
      - Integers. 8-, 16-, 32-, and 64-bit integers are supported, both signed and
        unsigned variants. Libbpf enforces parsed config value to be in the
        supported range of corresponding integer type. Integers values in config can
        be:
        - decimal integers, with optional + and - signs;
        - hexadecimal integers, prefixed with 0x or 0X;
        - octal integers, starting with 0.
      
      Config file itself is searched in /boot/config-$(uname -r) location with
      fallback to /proc/config.gz, unless config path is specified explicitly
      through bpf_object_open_opts' kernel_config_path option. Both gzipped and
      plain text formats are supported. Libbpf adds explicit dependency on zlib
      because of this, but this shouldn't be a problem, given libelf already depends
      on zlib.
      
      All detected extern variables, are put into a separate .extern internal map.
      It, similarly to .rodata map, is marked as read-only from BPF program side, as
      well as is frozen on load. This allows BPF verifier to track extern values as
      constants and perform enhanced branch prediction and dead code elimination.
      This can be relied upon for doing kernel version/feature detection and using
      potentially unsupported field relocations or BPF helpers in a CO-RE-based BPF
      program, while still having a single version of BPF program running on old and
      new kernels. Selftests are validating this explicitly for unexisting BPF
      helper.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191214014710.3449601-3-andriin@fb.com
      166750bc
    • A
      libbpf: Expose btf__align_of() API · 3d208f4c
      Andrii Nakryiko 提交于
      Expose BTF API that calculates type alignment requirements.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191214014341.3442258-7-andriin@fb.com
      3d208f4c
  13. 16 11月, 2019 1 次提交
  14. 07 11月, 2019 1 次提交
  15. 21 10月, 2019 1 次提交
  16. 16 10月, 2019 1 次提交
  17. 08 8月, 2019 2 次提交
  18. 22 7月, 2019 1 次提交
  19. 18 6月, 2019 1 次提交
  20. 25 5月, 2019 2 次提交
  21. 17 5月, 2019 1 次提交
  22. 16 4月, 2019 1 次提交
  23. 10 4月, 2019 1 次提交
  24. 27 3月, 2019 1 次提交
    • A
      libbpf: fix btf_dedup equivalence check handling of different kinds · 9ec71c1c
      Andrii Nakryiko 提交于
      btf_dedup_is_equiv() used to compare btf_type->info fields, before doing
      kind-specific equivalence check. This comparsion implicitly verified
      that candidate and canonical types are of the same kind. With enum fwd
      resolution logic this check couldn't be done generically anymore, as for
      enums info contains vlen, which differs between enum fwd and
      fully-defined enum, so this check was subsumed by kind-specific
      equivalence checks.
      
      This change caused btf_dedup_is_equiv() to let through VOID vs other
      types check to reach switch, which was never meant to be handing VOID
      kind, as VOID kind is always pre-resolved to itself and is only
      equivalent to itself, which is checked early in btf_dedup_is_equiv().
      
      This change adds back BTF kind equality check in place of more generic
      btf_type->info check, still defering further kind-specific checks to
      a per-kind switch.
      
      Fixes: 9768095b ("btf: resolve enum fwds in btf_dedup")
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      9ec71c1c
  25. 15 3月, 2019 1 次提交
    • A
      btf: resolve enum fwds in btf_dedup · 9768095b
      Andrii Nakryiko 提交于
      GCC and clang support enum forward declarations as an extension. Such
      forward-declared enums will be represented as normal BTF_KIND_ENUM types with
      vlen=0. This patch adds ability to resolve such enums to their corresponding
      fully defined enums. This helps to avoid duplicated BTF type graphs which only
      differ by some types referencing forward-declared enum vs full enum.
      
      One such example in kernel is enum irqchip_irq_state, defined in
      include/linux/interrupt.h and forward-declared in include/linux/irq.h. This
      causes entire struct task_struct and all referenced types to be duplicated in
      btf_dedup output. This patch eliminates such duplication cases.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      9768095b
  26. 01 3月, 2019 3 次提交
  27. 17 2月, 2019 1 次提交
    • A
      tools/libbpf: support bigger BTF data sizes · 5aab392c
      Andrii Nakryiko 提交于
      While it's understandable why kernel limits number of BTF types to 65535
      and size of string section to 64KB, in libbpf as user-space library it's
      too restrictive. E.g., pahole converting DWARF to BTF type information
      for Linux kernel generates more than 3 million BTF types and more than
      3MB of strings, before deduplication. So to allow btf__dedup() to do its
      work, we need to be able to load bigger BTF sections using btf__new().
      Singed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      5aab392c
  28. 15 2月, 2019 1 次提交
  29. 09 2月, 2019 4 次提交