action.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. name: 'Enable BTF'
  2. description: 'Enable CONFIG_DEBUG_INFO_BTF and apply libbpf feature-detection fix for android12-5.10'
  3. inputs:
  4. version:
  5. description: 'Kernel config version (e.g., android12-5.10)'
  6. required: true
  7. kernel_version:
  8. description: 'Kernel version (e.g., 5.10)'
  9. required: true
  10. sublevel:
  11. description: 'Kernel sublevel'
  12. required: true
  13. runs:
  14. using: 'composite'
  15. steps:
  16. - name: Apply libbpf feature-detection fix (android12-5.10)
  17. shell: bash
  18. working-directory: ${{ github.workspace }}/kernel/common
  19. if: ${{ inputs.version == 'android12-5.10' }}
  20. run: |
  21. set -euo pipefail
  22. patch -p1 -N < ${{ github.action_path }}/patches/0001-libbpf-remove-feature-detection-BTF.patch
  23. - name: Apply resolve_btfids linker-flag fix (android12-5.10)
  24. shell: bash
  25. working-directory: ${{ github.workspace }}/kernel/common
  26. if: ${{ inputs.version == 'android12-5.10' }}
  27. run: |
  28. set -euo pipefail
  29. patch -p1 -N < ${{ github.action_path }}/patches/0002-resolve_btfids-inherit-host-linker-flags.patch
  30. - name: Apply xdp_buff BTF-emit fix (android12-5.10)
  31. shell: bash
  32. working-directory: ${{ github.workspace }}/kernel/common
  33. if: ${{ inputs.version == 'android12-5.10' }}
  34. run: |
  35. set -euo pipefail
  36. # bpf_types.h references struct xdp_buff via
  37. # BTF_ID_LIST_SINGLE(bpf_xdp_output_btf_ids) in net/core/filter.c, but
  38. # the oldest sublevels (5.10.43) never emit xdp_buff into vmlinux BTF,
  39. # so resolve_btfids aborts with "unresolved symbol xdp_buff". Force BTF
  40. # emission with BTF_TYPE_EMIT in net/core/xdp.c, which includes
  41. # <net/xdp.h> (the struct must be COMPLETE at the emit point, so it
  42. # cannot live in filter.c where xdp_buff is only forward-declared).
  43. # The patch also adds #include <linux/btf.h> so BTF_TYPE_EMIT is
  44. # declared in xdp.c (filter.c already pulls it in).
  45. # Idempotent/harmless on newer sublevels.
  46. patch -p1 -N < ${{ github.action_path }}/patches/0003-btf-emit-xdp-buff.patch
  47. - name: Apply resolve_btfids ELF_T_WORD endian fix (android12-5.10)
  48. shell: bash
  49. working-directory: ${{ github.workspace }}/kernel/common
  50. if: false
  51. run: |
  52. set -euo pipefail
  53. # Backport of upstream 61e8aeda9398 ("bpf: Fix libelf endian handling
  54. # in resolv_btfids"). The .BTF_ids section content defaults to
  55. # ELF_T_BYTE, so libelf does no per-word translation when
  56. # resolve_btfids patches the section back with elf_update(); without
  57. # ELF_T_WORD the BTF_ID entries (e.g. xdp_buff) are handled as raw
  58. # bytes and resolution fails with "FAILED unresolved symbol xdp_buff".
  59. # Sublevels >= 66 (2021-11+) already carry this fix in-tree, so only
  60. # patch when it is missing (sublevel-43 trees: 2021-10 and lower) to
  61. # stay idempotent under `set -e`.
  62. if ! grep -q 'd_type = ELF_T_WORD' tools/bpf/resolve_btfids/main.c; then
  63. patch -p1 -N < ${{ github.action_path }}/patches/0004-resolve_btfids-elf-word.patch
  64. else
  65. echo "resolve_btfids already has the ELF_T_WORD fix; skipping"
  66. fi
  67. - name: Expose host dd for hermetic BTF generation (android12-5.10)
  68. shell: bash
  69. working-directory: ${{ github.workspace }}/kernel/common
  70. if: ${{ inputs.version == 'android12-5.10' }}
  71. run: |
  72. set -euo pipefail
  73. # The hermetic toolchain PATH (build.config.common -> HERMETIC_TOOLCHAIN=1)
  74. # has no /usr/bin, so coreutils 'dd' is missing. gen_btf in
  75. # scripts/link-vmlinux.sh:253 does `printf ... | dd of=...`; without dd the
  76. # pipeline fails and the build aborts with "Failed to generate BTF".
  77. # ADDITIONAL_HOST_TOOLS is honored by build/_setup_env.sh (symlinked into
  78. # the hermetic host_tools dir, which IS on the PATH). Echo it into the
  79. # build config so both Normal and Bypass build.sh runs pick it up.
  80. grep -q '^ADDITIONAL_HOST_TOOLS=' build.config.gki.aarch64 || \
  81. echo 'ADDITIONAL_HOST_TOOLS="${ADDITIONAL_HOST_TOOLS} dd"' >> build.config.gki.aarch64
  82. - name: Build and use pahole >=1.26 for hermetic BTF generation (android12-5.10)
  83. shell: bash
  84. working-directory: ${{ github.workspace }}/kernel
  85. if: ${{ inputs.version == 'android12-5.10' }}
  86. run: |
  87. set -euo pipefail
  88. # android12-5.10 pins prebuilt pahole v1.19, which fails to recode the
  89. # DWARF types and DROPS symbols (e.g. xdp_buff) from the emitted BTF.
  90. # resolve_btfids then aborts with "FAILED unresolved symbol xdp_buff".
  91. # This is the exact failure Google/kernelci hit (see lore.kernel.org,
  92. # "kernelci failures due to pahole missing", Apr-Sep 2022): pahole emits
  93. # hundreds of MB of "namespace__recode_dwarf_types: couldn't find ..."
  94. # warnings and silently drops types. Even Ubuntu's apt pahole 1.25 still
  95. # cannot fully recode the 5.10.43 sublevel DWARF (5.10.66+ is fine).
  96. # Build the latest pahole from source (1.31, matching a working host)
  97. # and wrap the hermetic-path pahole to exec it.
  98. #
  99. # The wrapper also always injects --skip_encoding_btf_enum64 /
  100. # decl_tag / type_tag. Sublevels <=149 have no scripts/pahole-flags.sh
  101. # at all, so their link-vmlinux.sh calls pahole with no skip flags; the
  102. # old in-tree libbpf there only handles BTF kinds 1-15 and EINVALs on
  103. # enum64/decl_tag/type_tag. Newer sublevels pass --skip_encoding_btf_enum64
  104. # via pahole-flags.sh already; duplicate skip flags are harmless.
  105. sudo apt-get install -y -qq cmake gcc libdw-dev libelf-dev zlib1g-dev dwarves
  106. # Build pahole 1.31 from source (acmel/dwarves). Deterministic, self-hosted.
  107. # Release build type is required: the default Debug sets -Wall -Werror, and
  108. # the bundled libbpf/btf_encoder fail under newer GCC as -Werror.
  109. PAHOLE_SRC="$HOME/dwarves"
  110. rm -rf "$PAHOLE_SRC"
  111. git clone --depth 1 --branch v1.31 https://github.com/acmel/dwarves.git "$PAHOLE_SRC"
  112. mkdir -p "$PAHOLE_SRC/build"
  113. cd "$PAHOLE_SRC/build"
  114. cmake -D__LIB=lib -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release .. >/dev/null
  115. make -j"$(nproc)" pahole
  116. sudo make install pahole
  117. command -v pahole
  118. pahole --version
  119. HERMETIC_PAHOLE="${{ github.workspace }}/kernel/build/build-tools/path/linux-x86/pahole"
  120. REAL_PAHOLE="$(command -v pahole)"
  121. if [ -L "$HERMETIC_PAHOLE" ] || [ -f "$HERMETIC_PAHOLE" ]; then
  122. cat > "$HERMETIC_PAHOLE" <<EOF
  123. #!/bin/sh
  124. exec "$REAL_PAHOLE" --skip_encoding_btf_enum64 --skip_encoding_btf_decl_tag --skip_encoding_btf_type_tag "\$@"
  125. EOF
  126. chmod +x "$HERMETIC_PAHOLE"
  127. echo "Wrote wrapper $HERMETIC_PAHOLE -> $REAL_PAHOLE (skip enum64/decl_tag/type_tag)"
  128. "$HERMETIC_PAHOLE" --version
  129. else
  130. echo "WARNING: $HERMETIC_PAHOLE not found; leaving prebuilt pahole in place"
  131. fi
  132. - name: Enable BTF Config
  133. uses: ./.github/actions/set-kernel-config
  134. with:
  135. config_list: |
  136. CONFIG_DEBUG_INFO_BTF=y