Skip to content
Snippets Groups Projects
  1. Sep 13, 2024
  2. Sep 11, 2024
    • Sam James's avatar
      tools: Drop nonsensical -O6 · eb9b9a6f
      Sam James authored
      
      -O6 is very much not-a-thing. Really, this should've been dropped
      entirely in 49b3cd30 ("tools: Set the maximum optimization level
      according to the compiler being used") instead of just passing it for
      not-Clang.
      
      Just collapse it down to -O3, instead of "-O6 unless Clang, in which case
      -O3".
      
      GCC interprets > -O3 as -O3. It doesn't even interpret > -O3 as -Ofast,
      which is a good thing, given -Ofast has specific (non-)requirements for
      code built using it. So, this does nothing except look a bit daft.
      
      Remove the silliness and also save a few lines in the Makefiles accordingly.
      
      Reviewed-by: default avatarIan Rogers <irogers@google.com>
      Reviewed-by: default avatarJesper Juhl <jesperjuhl76@gmail.com>
      Signed-off-by: default avatarSam James <sam@gentoo.org>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Bill Wendling <morbo@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Justin Stitt <justinstitt@google.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: llvm@lists.linux.dev
      Link: https://lore.kernel.org/r/4f01524fa4ea91c7146a41e26ceaf9dae4c127e4.1725821201.git.sam@gentoo.org
      
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      eb9b9a6f
  3. Sep 10, 2024
  4. Sep 09, 2024
  5. Sep 06, 2024
  6. Sep 05, 2024
  7. Sep 04, 2024
  8. Aug 30, 2024
  9. Aug 29, 2024
  10. Aug 15, 2024
    • Sam James's avatar
      libbpf: Workaround -Wmaybe-uninitialized false positive · fab45b96
      Sam James authored
      
      In `elf_close`, we get this with GCC 15 -O3 (at least):
      ```
      In function ‘elf_close’,
          inlined from ‘elf_close’ at elf.c:53:6,
          inlined from ‘elf_find_func_offset_from_file’ at elf.c:384:2:
      elf.c:57:9: warning: ‘elf_fd.elf’ may be used uninitialized [-Wmaybe-uninitialized]
         57 |         elf_end(elf_fd->elf);
            |         ^~~~~~~~~~~~~~~~~~~~
      elf.c: In function ‘elf_find_func_offset_from_file’:
      elf.c:377:23: note: ‘elf_fd.elf’ was declared here
        377 |         struct elf_fd elf_fd;
            |                       ^~~~~~
      In function ‘elf_close’,
          inlined from ‘elf_close’ at elf.c:53:6,
          inlined from ‘elf_find_func_offset_from_file’ at elf.c:384:2:
      elf.c:58:9: warning: ‘elf_fd.fd’ may be used uninitialized [-Wmaybe-uninitialized]
         58 |         close(elf_fd->fd);
            |         ^~~~~~~~~~~~~~~~~
      elf.c: In function ‘elf_find_func_offset_from_file’:
      elf.c:377:23: note: ‘elf_fd.fd’ was declared here
        377 |         struct elf_fd elf_fd;
            |                       ^~~~~~
      ```
      
      In reality, our use is fine, it's just that GCC doesn't model errno
      here (see linked GCC bug). Suppress -Wmaybe-uninitialized accordingly
      by initializing elf_fd.fd to -1 and elf_fd.elf to NULL.
      
      I've done this in two other functions as well given it could easily
      occur there too (same access/use pattern).
      
      Signed-off-by: default avatarSam James <sam@gentoo.org>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://gcc.gnu.org/PR114952
      Link: https://lore.kernel.org/bpf/14ec488a1cac02794c2fa2b83ae0cef1bce2cb36.1723578546.git.sam@gentoo.org
      fab45b96
  11. Aug 12, 2024
  12. Aug 06, 2024
  13. Aug 05, 2024
    • Brian Norris's avatar
      tools build: Correct bpf fixdep dependencies · dbb2a7a9
      Brian Norris authored
      The dependencies in tools/lib/bpf/Makefile are incorrect. Before we
      recurse to build $(BPF_IN_STATIC), we need to build its 'fixdep'
      executable.
      
      I can't use the usual shortcut from Makefile.include:
      
        <target>: <sources> fixdep
      
      because its 'fixdep' target relies on $(OUTPUT), and $(OUTPUT) differs
      in the parent 'make' versus the child 'make' -- so I imitate it via
      open-coding.
      
      I tweak a few $(MAKE) invocations while I'm at it, because
      1. I'm adding a new recursive make; and
      2. these recursive 'make's print spurious lines about files that are "up
         to date" (which isn't normally a feature in Kbuild subtargets) or
         "jobserver not available" (see [1])
      
      I also need to tweak the assignment of the OUTPUT variable, so that
      relative path builds work. For example, for 'make tools/lib/bpf', OUTPUT
      is unset, and is usually treated as "cwd" -- but recursive make will
      change cwd and so OUTPUT has a new meaning. For consistency, I ensure
      OUTPUT is always an absolute path.
      
      And $(Q) gets a backup definition in tools/build/Makefile.include,
      because Makefile.include is sometimes included without
      tools/build/Makefile, so the "quiet command" stuff doesn't actually work
      consistently without it.
      
      After this change, top-level builds result in an empty grep result from:
      
        $ grep 'cannot find fixdep' $(find tools/ -name '*.cmd')
      
      [1] https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html
      
      
      If we're not using $(MAKE) directly, then we need to use more '+'.
      
      Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Josh Poimboeuf <jpoimboe@kernel.org>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Link: https://lore.kernel.org/r/20240715203325.3832977-4-briannorris@chromium.org
      
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      dbb2a7a9
    • Brian Norris's avatar
      tools build: Correct libsubcmd fixdep dependencies · 96f30c8f
      Brian Norris authored
      
      All built targets need fixdep to be built first, before handling object
      dependencies [1]. We're missing one such dependency before the libsubcmd
      target.
      
      This resolves .cmd file generation issues such that the following
      sequence produces many fewer results:
      
        $ git clean -xfd tools/
        $ make tools/objtool
        $ grep "cannot find fixdep" $(find tools/objtool -name '*.cmd')
      
      In particular, only a buggy tools/objtool/libsubcmd/.fixdep.o.cmd
      remains, due to circular dependencies of fixdep on itself.
      
      Such incomplete .cmd files don't usually cause a direct problem, since
      they're designed to fail "open", but they can cause some subtle problems
      that would otherwise be handled by proper fixdep'd dependency files. [2]
      
      [1] This problem is better described in commit abb26210 ("perf
      tools: Force fixdep compilation at the start of the build"). I don't
      apply its solution here, because additional recursive make can be a bit
      of overkill.
      
      [2] Example failure case:
      
        cp -arl linux-src linux-src2
        cd linux-src2
        make O=/path/to/out
        cd ../linux-src
        rm -rf ../linux-src2
        make O=/path/to/out
      
      Previously, we'd see errors like:
      
        make[6]: *** No rule to make target
        '/path/to/linux-src2/tools/include/linux/compiler.h', needed by
        '/path/to/out/tools/bpf/resolve_btfids/libsubcmd/exec-cmd.o'.  Stop.
      
      Now, the properly-fixdep'd .cmd files will ignore a missing
      /path/to/linux-src2/...
      
      Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Josh Poimboeuf <jpoimboe@kernel.org>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Link: https://lore.kernel.org/all/ZGVi9HbI43R5trN8@bhelgaas/
      Link: https://lore.kernel.org/all/Zk-C5Eg84yt6_nml@google.com/
      Link: https://lore.kernel.org/r/20240715203325.3832977-2-briannorris@chromium.org
      
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      96f30c8f
  14. Aug 01, 2024
    • Tiezhu Yang's avatar
      perf list: Give clues if failed to open tracing events directory · b48543c4
      Tiezhu Yang authored
      
      When executing the command "perf list", I met "Error: failed to open
      tracing events directory" twice, the first reason is that there is no
      "/sys/kernel/tracing/events" directory due to it does not enable the
      kernel tracing infrastructure with CONFIG_FTRACE, the second reason
      is that there is no root privileges.
      
      Add the error string to tell the users what happened and what should
      to do, and also call put_tracing_file() to free events_path a little
      later to avoid messy code in the error message.
      
      At the same time, just remove the redundant "/" of the file path in
      the function get_tracing_file(), otherwise it shows something like
      "/sys/kernel/tracing//events".
      
      Before:
      
        $ ./perf list
        Error: failed to open tracing events directory
      
      After:
      
      (1) Without CONFIG_FTRACE
      
        $ ./perf list
        Error: failed to open tracing events directory
        /sys/kernel/tracing/events: No such file or directory
      
      (2) With CONFIG_FTRACE but no root privileges
      
        $ ./perf list
        Error: failed to open tracing events directory
        /sys/kernel/tracing/events: Permission denied
      
      Committer testing:
      
      Redirect stdout to null to quickly test the patch:
      
      Before:
      
        $ perf list > /dev/null
        Error: failed to open tracing events directory
        $
      
      After:
      
        $ perf list > /dev/null
        Error: failed to open tracing events directory
        /sys/kernel/tracing/events: Permission denied
        $
      
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/lkml/20240730062301.23244-3-yangtiezhu@loongson.cn
      
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b48543c4
    • Charlie Jenkins's avatar
      libperf: Add gitignore · d261f9eb
      Charlie Jenkins authored
      
      Ignore files that are generated by libperf and libperf tests.
      
      Signed-off-by: default avatarCharlie Jenkins <charlie@rivosinc.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/lkml/20240729-libperf_gitignore-v1-1-1c70dd98edf9@rivosinc.com
      
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d261f9eb
  15. Jul 31, 2024
    • Athira Rajeev's avatar
      perf annotate: Add disasm_line__parse() to parse raw instruction for powerpc · 06dd4c5a
      Athira Rajeev authored
      
      Currently, the perf tool infrastructure uses the disasm_line__parse
      function to parse disassembled line.
      
      Example snippet from objdump:
      
        objdump  --start-address=<address> --stop-address=<address>  -d --no-show-raw-insn -C <vmlinux>
      
        c0000000010224b4:	lwz     r10,0(r9)
      
      This line "lwz r10,0(r9)" is parsed to extract instruction name,
      registers names and offset.
      
      In powerpc, the approach for data type profiling uses raw instruction
      instead of result from objdump to identify the instruction category and
      extract the source/target registers.
      
      Example: 38 01 81 e8     ld      r4,312(r1)
      
      Here "38 01 81 e8" is the raw instruction representation. Add function
      "disasm_line__parse_powerpc" to handle parsing of raw instruction.
      Also update "struct disasm_line" to save the binary code/
      With the change, function captures:
      
      line -> "38 01 81 e8     ld      r4,312(r1)"
      raw instruction "38 01 81 e8"
      
      Raw instruction is used later to extract the reg/offset fields. Macros
      are added to extract opcode and register fields. "struct disasm_line"
      is updated to carry union of "bytes" and "raw_insn" of 32 bit to carry raw
      code (raw).
      
      Function "disasm_line__parse_powerpc fills the raw instruction hex value
      and can use macros to get opcode. There is no changes in existing code
      paths, which parses the disassembled code.  The size of raw instruction
      depends on architecture.
      
      In case of powerpc, the parsing the disasm line needs to handle cases
      for reading binary code directly from DSO as well as parsing the objdump
      result. Hence adding the logic into separate function instead of
      updating "disasm_line__parse".  The architecture using the instruction
      name and present approach is not altered. Since this approach targets
      powerpc, the macro implementation is added for powerpc as of now.
      
      Since the disasm_line__parse is used in other cases (perf annotate) and
      not only data tye profiling, the powerpc callback includes changes to
      work with binary code as well as mnemonic representation.
      
      Also in case if the DSO read fails and libcapstone is not supported, the
      approach fallback to use objdump as option. Hence as option, patch has
      changes to ensure objdump option also works well.
      
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-5-atrajeev@linux.vnet.ibm.com
      
      
      [ Add check for strndup() result ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      06dd4c5a
  16. Jul 29, 2024
    • David Vernet's avatar
      libbpf: Don't take direct pointers into BTF data from st_ops · 04a94133
      David Vernet authored
      
      In struct bpf_struct_ops, we have take a pointer to a BTF type name, and
      a struct btf_type. This was presumably done for convenience, but can
      actually result in subtle and confusing bugs given that BTF data can be
      invalidated before a program is loaded. For example, in sched_ext, we
      may sometimes resize a data section after a skeleton has been opened,
      but before the struct_ops scheduler map has been loaded. This may cause
      the BTF data to be realloc'd, which can then cause a UAF when loading
      the program because the struct_ops map has pointers directly into the
      BTF data.
      
      We're already storing the BTF type_id in struct bpf_struct_ops. Because
      type_id is stable, we can therefore just update the places where we were
      looking at those pointers to instead do the lookups we need from the
      type_id.
      
      Fixes: 590a0088 ("bpf: libbpf: Add STRUCT_OPS support")
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20240724171459.281234-1-void@manifault.com
      04a94133
  17. Jul 17, 2024
  18. Jul 10, 2024
  19. Jul 08, 2024
  20. Jul 01, 2024
  21. Jun 26, 2024
    • Alan Maguire's avatar
      libbpf: Fix clang compilation error in btf_relocate.c · 0f31c2c6
      Alan Maguire authored
      
      When building with clang for ARCH=i386, the following errors are
      observed:
      
        CC      kernel/bpf/btf_relocate.o
      ./tools/lib/bpf/btf_relocate.c:206:23: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
        206 |                 info[id].needs_size = true;
            |                                     ^ ~
      ./tools/lib/bpf/btf_relocate.c:256:25: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
        256 |                         base_info.needs_size = true;
            |                                              ^ ~
      2 errors generated.
      
      The problem is we use 1-bit, 31-bit bitfields in a signed int.
      Changing to
      
      	bool needs_size: 1;
      	unsigned int size:31;
      
      ...resolves the error and pahole reports that 4 bytes are used
      for the underlying representation:
      
      $ pahole btf_name_info tools/lib/bpf/btf_relocate.o
      struct btf_name_info {
      	const char  *              name;                 /*     0     8 */
      	unsigned int               needs_size:1;         /*     8: 0  4 */
      	unsigned int               size:31;              /*     8: 1  4 */
      	__u32                      id;                   /*    12     4 */
      
      	/* size: 16, cachelines: 1, members: 4 */
      	/* last cacheline: 16 bytes */
      };
      
      Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20240624192903.854261-1-alan.maguire@oracle.com
      0f31c2c6
  22. Jun 25, 2024
    • Kuan-Wei Chiu's avatar
      tools/lib/list_sort: remove redundant code for cond_resched handling · 6d74e1e3
      Kuan-Wei Chiu authored
      Since cond_resched() is not called in userspace, remove the redundant code
      in userspace's list_sort() implementation.  This change eliminates the
      unused 'count' variable and the associated logic for invoking cmp()
      periodically, which was intended to trigger cond_resched() in kernel
      space.
      
      The removed code includes:
      - Declaration and increment of the 'count' variable.
      - Conditional invocation of cmp() based on 'count'.
      
      This cleanup simplifies merge_final(), avoids unnecessary overhead, and
      has no impact on the functionality of list_sort() in userspace.
      
      Link: https://lkml.kernel.org/r/20240525230206.1077536-1-visitorckw@gmail.com
      
      
      Signed-off-by: default avatarKuan-Wei Chiu <visitorckw@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      6d74e1e3
  23. Jun 24, 2024
  24. Jun 21, 2024
  25. Jun 17, 2024
    • Eduard Zingerman's avatar
      libbpf: Make btf_parse_elf process .BTF.base transparently · c86f180f
      Eduard Zingerman authored
      
      Update btf_parse_elf() to check if .BTF.base section is present.
      The logic is as follows:
      
        if .BTF.base section exists:
           distilled_base := btf_new(.BTF.base)
        if distilled_base:
           btf := btf_new(.BTF, .base_btf=distilled_base)
           if base_btf:
              btf_relocate(btf, base_btf)
        else:
           btf := btf_new(.BTF)
        return btf
      
      In other words:
      - if .BTF.base section exists, load BTF from it and use it as a base
        for .BTF load;
      - if base_btf is specified and .BTF.base section exist, relocate newly
        loaded .BTF against base_btf.
      
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20240613095014.357981-6-alan.maguire@oracle.com
      c86f180f
    • Alan Maguire's avatar
      libbpf: Split BTF relocation · 19e00c89
      Alan Maguire authored
      
      Map distilled base BTF type ids referenced in split BTF and their
      references to the base BTF passed in, and if the mapping succeeds,
      reparent the split BTF to the base BTF.
      
      Relocation is done by first verifying that distilled base BTF
      only consists of named INT, FLOAT, ENUM, FWD, STRUCT and
      UNION kinds; then we sort these to speed lookups.  Once sorted,
      the base BTF is iterated, and for each relevant kind we check
      for an equivalent in distilled base BTF.  When found, the
      mapping from distilled -> base BTF id and string offset is recorded.
      In establishing mappings, we need to ensure we check STRUCT/UNION
      size when the STRUCT/UNION is embedded in a split BTF STRUCT/UNION,
      and when duplicate names exist for the same STRUCT/UNION.  Otherwise
      size is ignored in matching STRUCT/UNIONs.
      
      Once all mappings are established, we can update type ids
      and string offsets in split BTF and reparent it to the new base.
      
      Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Link: https://lore.kernel.org/bpf/20240613095014.357981-4-alan.maguire@oracle.com
      19e00c89
    • Alan Maguire's avatar
      libbpf: Add btf__distill_base() creating split BTF with distilled base BTF · 58e185a0
      Alan Maguire authored
      
      To support more robust split BTF, adding supplemental context for the
      base BTF type ids that split BTF refers to is required.  Without such
      references, a simple shuffling of base BTF type ids (without any other
      significant change) invalidates the split BTF.  Here the attempt is made
      to store additional context to make split BTF more robust.
      
      This context comes in the form of distilled base BTF providing minimal
      information (name and - in some cases - size) for base INTs, FLOATs,
      STRUCTs, UNIONs, ENUMs and ENUM64s along with modified split BTF that
      points at that base and contains any additional types needed (such as
      TYPEDEF, PTR and anonymous STRUCT/UNION declarations).  This
      information constitutes the minimal BTF representation needed to
      disambiguate or remove split BTF references to base BTF.  The rules
      are as follows:
      
      - INT, FLOAT, FWD are recorded in full.
      - if a named base BTF STRUCT or UNION is referred to from split BTF, it
        will be encoded as a zero-member sized STRUCT/UNION (preserving
        size for later relocation checks).  Only base BTF STRUCT/UNIONs
        that are either embedded in split BTF STRUCT/UNIONs or that have
        multiple STRUCT/UNION instances of the same name will _need_ size
        checks at relocation time, but as it is possible a different set of
        types will be duplicates in the later to-be-resolved base BTF,
        we preserve size information for all named STRUCT/UNIONs.
      - if an ENUM[64] is named, a ENUM forward representation (an ENUM
        with no values) of the same size is used.
      - in all other cases, the type is added to the new split BTF.
      
      Avoiding struct/union/enum/enum64 expansion is important to keep the
      distilled base BTF representation to a minimum size.
      
      When successful, new representations of the distilled base BTF and new
      split BTF that refers to it are returned.  Both need to be freed by the
      caller.
      
      So to take a simple example, with split BTF with a type referring
      to "struct sk_buff", we will generate distilled base BTF with a
      0-member STRUCT sk_buff of the appropriate size, and the split BTF
      will refer to it instead.
      
      Tools like pahole can utilize such split BTF to populate the .BTF
      section (split BTF) and an additional .BTF.base section.  Then
      when the split BTF is loaded, the distilled base BTF can be used
      to relocate split BTF to reference the current (and possibly changed)
      base BTF.
      
      So for example if "struct sk_buff" was id 502 when the split BTF was
      originally generated,  we can use the distilled base BTF to see that
      id 502 refers to a "struct sk_buff" and replace instances of id 502
      with the current (relocated) base BTF sk_buff type id.
      
      Distilled base BTF is small; when building a kernel with all modules
      using distilled base BTF as a test, overall module size grew by only
      5.3Mb total across ~2700 modules.
      
      Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Link: https://lore.kernel.org/bpf/20240613095014.357981-2-alan.maguire@oracle.com
      58e185a0
  26. Jun 14, 2024
  27. Jun 06, 2024
Loading