Skip to content

Commit 0f2d0b3

Browse files
committed
meta-kernel-block: add bpf capability
Signed-off-by: Alex Gonzalez <alexg@balena.io>
1 parent 0ef51dd commit 0f2d0b3

6 files changed

Lines changed: 81 additions & 81 deletions

File tree

layers/meta-kernel-block/classes/kernel-extension.bbclass

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
#
1010
# Strategy:
1111
# 1. After do_kernel_resin_injectconfig runs (balena defconfig + BALENA_CONFIGS
12-
# are already merged into .config), apply kernel-extension.cfg via
13-
# scripts/kconfig/merge_config.sh.
14-
# 2. Run olddefconfig to resolve dependencies.
12+
# are already merged into .config), discover every *.cfg fragment reachable
13+
# via FILESEXTRAPATHS and merge them all via scripts/kconfig/merge_config.sh
14+
# in sorted order.
15+
# 2. Run olddefconfig once to resolve dependencies.
1516
# 3. Let the normal do_compile / do_install flow proceed.
1617
#
1718
# Usage:
1819
# inherit kernel-extension
19-
# # Place kernel-extension.cfg in a FILESEXTRAPATHS-reachable directory.
20+
# # Place one or more *.cfg fragments in a FILESEXTRAPATHS-reachable dir.
2021

2122
python do_kernel_extend_config() {
23+
import glob
2224
import os
2325
import subprocess
2426

@@ -32,31 +34,40 @@ python do_kernel_extend_config() {
3234
if not arch:
3335
bb.fatal("kernel-extension: ARCH variable not set")
3436

35-
# 1. Locate kernel-extension.cfg via FILESEXTRAPATHS.
36-
extension_cfg = None
37+
# 1. Discover every *.cfg fragment reachable via FILESEXTRAPATHS, in
38+
# sorted order. Deduplicate paths reachable via multiple entries.
39+
fragments = []
40+
seen = set()
3741
filesextrapaths = d.getVar("FILESEXTRAPATHS") or ""
3842
for path in filesextrapaths.split(":"):
39-
candidate = os.path.join(path, "kernel-extension.cfg")
40-
if os.path.exists(candidate):
41-
extension_cfg = candidate
42-
break
43+
if not path:
44+
continue
45+
for cfg in sorted(glob.glob(os.path.join(path, "*.cfg"))):
46+
if cfg not in seen:
47+
seen.add(cfg)
48+
fragments.append(cfg)
4349

44-
if not extension_cfg:
50+
if not fragments:
4551
bb.fatal(
46-
"kernel-extension: kernel-extension.cfg not found.\n"
47-
"Place it in a directory reachable via FILESEXTRAPATHS.\n"
52+
"kernel-extension: no *.cfg fragments found via FILESEXTRAPATHS.\n"
53+
"Place at least one fragment in a FILESEXTRAPATHS-reachable dir.\n"
4854
f"Searched paths: {filesextrapaths}"
4955
)
5056

51-
bb.note(f"Using kernel extension fragment: {extension_cfg}")
57+
bb.note(f"Merging {len(fragments)} kernel extension fragment(s):")
58+
for f in fragments:
59+
bb.note(f" {f}")
5260

53-
# 2. Merge the fragment into .config.
61+
# 2. Merge every fragment in a single merge_config.sh invocation.
62+
# merge_config.sh accepts multiple input fragments; later inputs
63+
# override earlier ones for conflicting symbols and warn on stderr.
5464
merge_script = os.path.join(S, "scripts", "kconfig", "merge_config.sh")
55-
cmd = f'{merge_script} -m -O {B} {base_config} {extension_cfg}'
56-
bb.note("Merging kernel-extension.cfg")
65+
cmd = " ".join([merge_script, "-m", "-O", B, base_config, *fragments])
5766
ret = subprocess.run(cmd, shell=True, capture_output=True, text=True)
5867
if ret.returncode != 0:
5968
bb.fatal(f"merge_config.sh failed:\n{ret.stderr}")
69+
if ret.stderr:
70+
bb.note(ret.stderr)
6071

6172
# 3. Resolve dependencies.
6273
cmd = f'{make_cmd} {make_opts} -C {S} O={B} ARCH={arch} olddefconfig'

layers/meta-kernel-block/recipes-core/images/balena-kernel-block.bb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LICENSE = "MIT"
33

44
inherit balena-hostapp-extension
55

6-
IMAGE_INSTALL = "kernel-modules kernel-image kernel-devicetree"
6+
IMAGE_INSTALL = "kernel-modules kernel-image kernel-devicetree bpftool libbpf"
77

88
IMAGE_LINGUAS = ""
99
VIRTUAL-RUNTIME_init_manager = ""
@@ -14,6 +14,6 @@ remove_unnecessary_files() {
1414
rm -f ${IMAGE_ROOTFS}/bin ${IMAGE_ROOTFS}/sbin
1515
rm -rf ${IMAGE_ROOTFS}/etc
1616
rm -rf ${IMAGE_ROOTFS}/run
17-
rm -rf ${IMAGE_ROOTFS}/usr/bin
17+
rm -rf ${IMAGE_ROOTFS}/var
1818
}
1919
IMAGE_PREPROCESS_COMMAND += "remove_unnecessary_files;"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPATIBLE_HOST = "(x86_64|aarch64).*-linux"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# BPF LSM + BTF + tracing/observability
2+
#
3+
# Enables the in-kernel BPF security module, BTF type information for
4+
# kernel introspection, always-on JIT, and the function/kprobe tracing
5+
# surface bpftrace/Tetragon-class agents need.
6+
#
7+
# These entries require =y kernel-config changes (LSM hook chain,
8+
# DEBUG_INFO). meta-kernel-modules-block could not have produced them.
9+
10+
# Debug info / BTF prerequisites. Full DWARF is required for BTF.
11+
CONFIG_DEBUG_INFO=y
12+
# CONFIG_DEBUG_INFO_NONE is not set
13+
# CONFIG_DEBUG_INFO_REDUCED is not set
14+
CONFIG_DEBUG_INFO_BTF=y
15+
16+
# BPF core. Most of these are typically already =y in modern defconfigs;
17+
# stating them explicitly keeps the fragment robust against base changes.
18+
CONFIG_BPF=y
19+
CONFIG_BPF_SYSCALL=y
20+
CONFIG_BPF_JIT=y
21+
CONFIG_BPF_JIT_ALWAYS_ON=y
22+
23+
# BPF LSM. CONFIG_LSM is a comma-separated string of active LSMs; the
24+
# value below matches the upstream 5.18+ default with bpf included. If
25+
# the balena base defconfig has a custom LSM order, this overrides it.
26+
CONFIG_BPF_LSM=y
27+
CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,bpf,integrity"
28+
29+
# Tracing surface for observability.
30+
CONFIG_FTRACE=y
31+
CONFIG_FUNCTION_TRACER=y
32+
CONFIG_KPROBES=y
33+
CONFIG_KPROBE_EVENTS=y
34+
CONFIG_PERF_EVENTS=y
35+
CONFIG_BPF_EVENTS=y

layers/meta-kernel-block/recipes-kernel/linux/files/kernel-extension.cfg

Lines changed: 0 additions & 59 deletions
This file was deleted.

layers/meta-kernel-block/recipes-kernel/linux/linux-raspberrypi_%.bbappend

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@
55

66
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
77

8-
# Track kernel-extension.cfg in the task hash so changes trigger re-execution.
8+
# Track every *.cfg fragment under files/ in the task hash so any fragment
9+
# edit triggers re-execution. The bbclass discovers fragments by glob; the
10+
# bbappend mirrors that discovery here for hash correctness.
11+
#
912
# NOT in SRC_URI because Yocto would auto-merge .cfg files into the kernel
10-
# config — the bbclass applies it manually.
11-
do_kernel_extend_config[file-checksums] += "${THISDIR}/files/kernel-extension.cfg:True"
13+
# config — the bbclass applies them manually.
14+
python () {
15+
import glob
16+
import os
17+
thisdir = d.getVar("THISDIR")
18+
fragments = sorted(glob.glob(os.path.join(thisdir, "files", "*.cfg")))
19+
d.appendVarFlag(
20+
"do_kernel_extend_config", "file-checksums",
21+
" " + " ".join(f"{p}:True" for p in fragments),
22+
)
23+
}
1224

1325
inherit kernel-extension

0 commit comments

Comments
 (0)