Skip to content

Commit c034c1f

Browse files
authored
Merge pull request #7 from runloopai/adam/add-bpf-kvm
Add eBPF support (tracing/observability)
2 parents 1719159 + 022a315 commit c034c1f

2 files changed

Lines changed: 100 additions & 9 deletions

File tree

‎.github/workflows/build-kernel.yaml‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
kernel_version:
77
description: 'Kernel version to build'
88
required: false
9-
default: '6.18.6'
9+
default: '6.18.32'
1010
push:
1111
branches:
1212
- main
@@ -16,23 +16,32 @@ permissions:
1616
contents: read
1717

1818
env:
19-
KERNEL_VERSION: ${{ inputs.kernel_version || '6.18.6' }}
19+
KERNEL_VERSION: ${{ inputs.kernel_version || '6.18.32' }}
2020

2121
jobs:
2222
build-kernel:
23-
name: Build Kernel (${{ matrix.arch }})
23+
name: Build Kernel (${{ matrix.arch }} / ${{ matrix.flavor }})
2424
runs-on:
2525
group: Default Larger Runners
2626
strategy:
2727
fail-fast: false
2828
matrix:
29+
arch: [x86_64, arm64]
30+
# base = pre-eBPF kernel; ebpf = eBPF tracing stack + BTF (for Tetragon).
31+
flavor: [base, ebpf]
2932
include:
3033
- arch: x86_64
3134
build_arch: x86_64
3235
cross_compile_pkgs: ""
3336
- arch: arm64
3437
build_arch: aarch64
3538
cross_compile_pkgs: gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
39+
- flavor: base
40+
build_type_arg: ""
41+
tarball_suffix: ""
42+
- flavor: ebpf
43+
build_type_arg: "-b ebpf"
44+
tarball_suffix: "-ebpf"
3645

3746
steps:
3847
- name: Checkout
@@ -47,6 +56,7 @@ jobs:
4756
build-essential \
4857
cpio \
4958
curl \
59+
dwarves \
5060
flex \
5161
git \
5262
libelf-dev \
@@ -71,22 +81,45 @@ jobs:
7181
7282
- name: Setup kernel source
7383
working-directory: packaging/kernel
74-
run: ./build-kernel.sh -a ${{ matrix.build_arch }} -v ${{ env.KERNEL_VERSION }} -f -s setup
84+
run: ./build-kernel.sh -a ${{ matrix.build_arch }} -v ${{ env.KERNEL_VERSION }} ${{ matrix.build_type_arg }} -f -s setup
7585

7686
- name: Build kernel
7787
working-directory: packaging/kernel
78-
run: ./build-kernel.sh -a ${{ matrix.build_arch }} -v ${{ env.KERNEL_VERSION }} build
88+
run: ./build-kernel.sh -a ${{ matrix.build_arch }} -v ${{ env.KERNEL_VERSION }} ${{ matrix.build_type_arg }} build
89+
90+
- name: Verify BTF symbols are present
91+
if: matrix.flavor == 'ebpf'
92+
working-directory: packaging/kernel
93+
run: |
94+
# setup runs with -s (skip config checks), so a dropped BTF option
95+
# would not fail the build — it would silently ship a BTF-less kernel
96+
# that crashes Tetragon and other CO-RE agents at startup. Guard both
97+
# the config and the generated .BTF section in vmlinux.
98+
kernel_dir=$(find . -maxdepth 1 -type d -name 'kata-linux-*' | head -n1)
99+
[ -n "${kernel_dir}" ] || { echo "ERROR: kernel build dir not found" >&2; exit 1; }
100+
echo "Checking BTF in ${kernel_dir}"
101+
if ! grep -q '^CONFIG_DEBUG_INFO_BTF=y' "${kernel_dir}/.config"; then
102+
echo "ERROR: CONFIG_DEBUG_INFO_BTF was dropped from .config" >&2
103+
echo "--- DEBUG_KERNEL / DEBUG_INFO / PAHOLE / BTF state ---" >&2
104+
grep -E 'DEBUG_KERNEL|DEBUG_INFO|PAHOLE|BTF' "${kernel_dir}/.config" >&2 || true
105+
exit 1
106+
fi
107+
if ! readelf -S "${kernel_dir}/vmlinux" | grep -q '\.BTF'; then
108+
echo "ERROR: vmlinux has no .BTF section; BTF symbols were not generated" >&2
109+
exit 1
110+
fi
111+
echo "OK: BTF symbols present in vmlinux"
79112
80113
- name: Install kernel artifacts
81114
working-directory: packaging/kernel
82115
run: |
83116
mkdir -p ${{ github.workspace }}/artifacts
84-
DESTDIR=${{ github.workspace }}/artifacts ./build-kernel.sh -a ${{ matrix.build_arch }} -v ${{ env.KERNEL_VERSION }} install
117+
DESTDIR=${{ github.workspace }}/artifacts ./build-kernel.sh -a ${{ matrix.build_arch }} -v ${{ env.KERNEL_VERSION }} ${{ matrix.build_type_arg }} install
85118
86119
- name: Create tarball
87120
id: tarball
88121
run: |
89-
TARBALL_NAME="${{ steps.version.outputs.version_string }}-${{ matrix.arch }}.tar.gz"
122+
TARBALL_NAME="${{ steps.version.outputs.version_string }}-${{ matrix.arch }}${{ matrix.tarball_suffix }}.tar.gz"
90123
echo "tarball_name=${TARBALL_NAME}" >> $GITHUB_OUTPUT
91124
cd ${{ github.workspace }}/artifacts/usr/share/kata-containers
92125
echo "Creating tarball with:"
@@ -111,7 +144,7 @@ jobs:
111144
- name: Upload artifacts to GitHub
112145
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
113146
with:
114-
name: kernel-${{ matrix.arch }}-${{ steps.version.outputs.version_string }}
147+
name: kernel-${{ matrix.arch }}-${{ matrix.flavor }}-${{ steps.version.outputs.version_string }}
115148
path: ${{ github.workspace }}/${{ steps.tarball.outputs.tarball_name }}
116149
retention-days: 7
117150

@@ -129,7 +162,7 @@ jobs:
129162
run: |
130163
DATE=$(date +%Y%m%d)
131164
SHORT_SHA=$(git rev-parse --short=7 HEAD)
132-
KERNEL_VERSION="${{ inputs.kernel_version || '6.18.6' }}"
165+
KERNEL_VERSION="${{ inputs.kernel_version || '6.18.32' }}"
133166
VERSION_STRING="linux-${KERNEL_VERSION}-runloop-${DATE}-${SHORT_SHA}"
134167
echo "version_string=${VERSION_STRING}" >> $GITHUB_OUTPUT
135168
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# eBPF (extended Berkeley Packet Filter) — scoped to observability/tracing
2+
# use cases (bcc, bpftrace, libbpf-based agents). Networking BPF (tc cls/act,
3+
# XDP, sockmap, lwt) is intentionally left off to keep the kernel small.
4+
#
5+
# This is an opt-in build-type fragment: it is merged only when the kernel is
6+
# built with `-b ebpf`. The default build omits it, producing a smaller kernel
7+
# without the eBPF tracing stack or BTF.
8+
#
9+
# CONFIG_BPF_SYSCALL and CONFIG_CGROUP_BPF are already enabled in cgroup.conf.
10+
# CONFIG_HAVE_EBPF_JIT is already enabled in network.conf.
11+
12+
CONFIG_BPF=y
13+
CONFIG_BPF_JIT=y
14+
CONFIG_BPF_JIT_ALWAYS_ON=y
15+
CONFIG_BPF_JIT_DEFAULT_ON=y
16+
CONFIG_BPF_EVENTS=y
17+
18+
# Default kernel.unprivileged_bpf_disabled=2 (require CAP_BPF for bpf()).
19+
CONFIG_BPF_UNPRIV_DEFAULT_OFF=y
20+
21+
# Tracing primitives that BPF programs attach to.
22+
CONFIG_KPROBES=y
23+
CONFIG_UPROBES=y
24+
CONFIG_KPROBE_EVENTS=y
25+
CONFIG_UPROBE_EVENTS=y
26+
CONFIG_TRACING=y
27+
CONFIG_FTRACE=y
28+
CONFIG_FUNCTION_TRACER=y
29+
CONFIG_DYNAMIC_FTRACE=y
30+
CONFIG_FTRACE_SYSCALLS=y
31+
32+
# fprobe enables kprobe_multi (mass-attach kprobes) — big perf win for tools
33+
# that hook many functions (bpftrace, retsnoop, etc.).
34+
CONFIG_FPROBE=y
35+
36+
# bpf_override_return — lets BPF programs override return values of kprobed
37+
# functions (fault injection, debugging). Pulls in FUNCTION_ERROR_INJECTION.
38+
CONFIG_FUNCTION_ERROR_INJECTION=y
39+
CONFIG_BPF_KPROBE_OVERRIDE=y
40+
41+
# BTF (BPF Type Format) — required for kfunc:/fentry/fexit probes, BTF-typed
42+
# args, and CO-RE programs used by libbpf, bpftrace tools/*.bt, Tetragon, and
43+
# most modern eBPF tooling. CO-RE agents read /sys/kernel/btf/vmlinux, which the
44+
# kernel only exposes when CONFIG_DEBUG_INFO_BTF=y; without it Tetragon crashes
45+
# at startup. Requires pahole (dwarves) at kernel build time.
46+
#
47+
# CONFIG_DEBUG_KERNEL gates the whole "Debug information" choice: the DWARF
48+
# options below `depend on DEBUG_KERNEL`. The kata fragment merge starts from
49+
# allnoconfig (DEBUG_KERNEL=n), so without this line the DWARF choice is
50+
# unavailable, DEBUG_INFO never gets selected, and `make oldconfig` silently
51+
# drops DEBUG_INFO_BTF. DEBUG_KERNEL only unlocks debug options — it does not
52+
# enable any on its own — so it adds no image bloat by itself.
53+
CONFIG_DEBUG_KERNEL=y
54+
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
55+
CONFIG_DEBUG_INFO_BTF=y
56+
57+
# CONFIG_DEBUG_INFO_BTF_MODULES is intentionally omitted: CONFIG_MODULES=n
58+
# (base.conf) makes this kernel monolithic, so there is no module BTF to emit.

0 commit comments

Comments
 (0)