Skip to content

Commit

Permalink
[btf] Flush kernel spec (BTF) after loading a sensor
Browse files Browse the repository at this point in the history
[ upstream commit 6f70926 ("[btf] Flush kernel spec (BTF) after
loading a sensor") ]

This patch flushes the BTF when we complete the loading of a sensor.

Signed-off-by: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
  • Loading branch information
tpapagian authored and mtardy committed Oct 23, 2024
1 parent d798657 commit 9f7b0f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/bpf/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ func HasMissedStatsKprobeMulti() bool {
}

func LogFeatures() string {
// once we have detected all features, flush the BTF spec
// we cache all values so calling again a Has* function will
// not load the BTF again
defer ebtf.FlushKernelSpec()
return fmt.Sprintf("override_return: %t, buildid: %t, kprobe_multi: %t, uprobe_multi %t, fmodret: %t, fmodret_syscall: %t, signal: %t, large: %t, link_pin: %t, lsm: %t, missed_stats_kprobe_multi: %t, missed_stats_kprobe: %t",
HasOverrideHelper(), HasBuildId(), HasKprobeMulti(), HasUprobeMulti(),
HasModifyReturn(), HasModifyReturnSyscall(), HasSignalHelper(), HasProgramLargeSize(),
Expand Down
4 changes: 4 additions & 0 deletions pkg/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/btf"
cachedbtf "github.com/cilium/tetragon/pkg/btf"
"github.com/cilium/tetragon/pkg/kernels"
"github.com/cilium/tetragon/pkg/logger"
Expand Down Expand Up @@ -115,6 +116,9 @@ func (s *Sensor) Load(bpfDir string) error {
progsAdd(s.Progs)
AllMaps = append(AllMaps, s.Maps...)

// cleanup the BTF once we have loaded all sensor's program
btf.FlushKernelSpec()

l.WithField("sensor", s.Name).Infof("Loaded BPF maps and events for sensor successfully")
s.Loaded = true
return nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/sensors/program/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ func doLoadProgram(

load.Prog = prog

// in KernelTypes, we use a non-standard BTF which is possibly annotated with symbols
// from kernel modules. At this point we don't need that anymore, so we can release
// the memory from it.
load.KernelTypes = nil

// Copy the loaded collection before it's destroyed
if KeepCollection {
return copyLoadedCollection(coll)
Expand Down

0 comments on commit 9f7b0f0

Please sign in to comment.