Skip to content

Commit f76895d

Browse files
committed
ebpftracer: report missing BPF tracing program types clearly
On kernels built without CONFIG_BPF_EVENTS (e.g. NVIDIA JetPack 5 / L4T 5.10 with CONFIG_KPROBES=n), BPF_PROG_TYPE_TRACEPOINT and BPF_PROG_TYPE_KPROBE are compiled out and bpf(BPF_PROG_LOAD) fails with a bare EINVAL. The agent then exits with failed to load collection: program sched_process_exit: load program: invalid argument where the program name is whichever program happened to load first, and nothing points at the kernel configuration. Probe TracePoint and Kprobe support with cilium/ebpf/features before loading the collection and fail with an error naming the missing kernel option. Only a conclusive ebpf.ErrNotSupported is reported; any other probe result falls through to the real collection load so existing error paths are unchanged. Document the CONFIG_BPF_EVENTS requirement in the README.
1 parent 0fa2ee7 commit f76895d

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
The agent gathers metrics related to a node and the containers running on it, and it exposes them in the Prometheus format.
77

88
It uses eBPF to track container related events such as TCP connects, so the minimum supported Linux kernel version is 5.1.
9+
The kernel must also be built with `CONFIG_BPF_EVENTS=y` (kprobe and tracepoint BPF programs); some embedded and vendor kernels disable it.
910

1011
<img src="https://coroot.com/static/img/blog/ebpf.svg" width="800" />
1112

‎ebpftracer/tracer.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"time"
1919

2020
"github.com/cilium/ebpf"
21+
"github.com/cilium/ebpf/features"
2122
"github.com/cilium/ebpf/link"
2223
"github.com/cilium/ebpf/perf"
2324
"github.com/coroot/coroot-node-agent/common"
@@ -294,6 +295,11 @@ func (t *Tracer) ebpf(ch chan<- Event) error {
294295
return fmt.Errorf("failed to load collection spec: %w", err)
295296
}
296297
_ = unix.Setrlimit(unix.RLIMIT_MEMLOCK, &unix.Rlimit{Cur: unix.RLIM_INFINITY, Max: unix.RLIM_INFINITY})
298+
for _, pt := range []ebpf.ProgramType{ebpf.TracePoint, ebpf.Kprobe} {
299+
if err := features.HaveProgramType(pt); errors.Is(err, ebpf.ErrNotSupported) {
300+
return fmt.Errorf("kernel does not support BPF %s programs (CONFIG_BPF_EVENTS is not set?): %w", pt, ebpf.ErrNotSupported)
301+
}
302+
}
297303
c, err := ebpf.NewCollectionWithOptions(collectionSpec, ebpf.CollectionOptions{
298304
//Programs: ebpf.ProgramOptions{LogLevel: 2, LogSize: 20 * 1024 * 1024},
299305
})

0 commit comments

Comments
 (0)