-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tetragon: Replace cgo loader with cilium/ebpf library #141
Conversation
c6eaf8c
to
8d6cf66
Compare
864455e
to
2649ddb
Compare
pkg/bpf/detect.go
Outdated
return fd >= 0 ? true : false; | ||
} | ||
|
||
*/ | ||
import "C" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import "C" |
Looks like cgo is not required here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, I'll squash that in, thanks
sry I should have assigned #143 sooner :-\ |
No problem, thanks for great contributions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great cleanup! Thanks!
small nit:
There is a "fix" the the end of commit: 'tetragon: Load kprobes with ebpf/cilium interface'
@@ -185,6 +189,13 @@ func (s *Sensor) LoadMaps(stopCtx context.Context, mapDir string) error { | |||
|
|||
pinPath := filepath.Join(mapDir, m.PinName) | |||
|
|||
if dir := filepath.Dir(m.PinName); isValidSubdir(dir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to not return an error if isValidSubdir
fails, because the loading will fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the condition there is to check if PinName has directory portion and create it,
dir will be '.' for PinName without subdirectory, so that's filtered out in isValidSubdir,
plus I added check for '..' which we don't want.. I'll add some comment
git rebase squash leftover ;-) thanks |
Adding the pin path to the log, that gives exit output, like: (check the new pin='...' values) time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=tracepoint/sys_exit pin=event_exit time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=kprobe/wake_up_new_task pin=kprobe_pid_clear time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=tracepoint/sys_execve pin=event_execve time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=kprobe/generic_kprobe pin=kprobe_fd_install time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=kprobe/generic_kprobe pin=kprobe___x64_sys_close time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=kprobe/generic_kprobe pin=kprobe___x64_sys_read time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=kprobe/generic_retkprobe pin=kretprobe___x64_sys_read time="2022-06-21T01:43:38+02:00" level=info msg="BPF prog was unloaded" label=kprobe/generic_kprobe pin=kprobe___x64_sys_write Signed-off-by: Jiri Olsa <[email protected]>
Adding fdinstall_map as map sensor so it's created and pinned by cilium/ebpf library code. Removing the loader code that was repining the map for each program, which is now done by Sensor::LoadMaps. Signed-off-by: Jiri Olsa <[email protected]>
Making the program init more readable, so we can add more fields easily. Signed-off-by: Jiri Olsa <[email protected]>
Current libbpf loader is using program specific names for maps. Adding PinName field to Map struct to allow that for Map objects. The PinName field is initialized with MapBuilderPin function, the standard MapBuilder initializes PinName to Name, so it's always defined. Adding map of maps to Program, that returns pin name for each map name assigned to the program. It's used when loading the program to get pin name of its map. Each program can have specific pin name of the map assigned. Signed-off-by: Jiri Olsa <[email protected]>
Adding support to have directory part in the map's pin name. It will be used for retprobe_map which is pinned under special directory. Signed-off-by: Jiri Olsa <[email protected]>
Adding MapLoad field to Program object to pass map name and data to the loader code. The loader code will update each map with the data from the MapLoad array. It will be used in following code to load filter and config data for generic kprobes and tracepoints. Signed-off-by: Jiri Olsa <[email protected]>
Adding support to specify custom map and prefix for tail calls installation. It will be used in following changes. Signed-off-by: Jiri Olsa <[email protected]>
Currently loadProgram function check and install maps only for 'main' program, but we need to do it for all programs. Signed-off-by: Jiri Olsa <[email protected]>
Adding program.LoadTracepointProgram function that creates tracepoint from sensor program. Signed-off-by: Jiri Olsa <[email protected]>
Replacing current libbpf tracepoint loader code with program.LoadTracepointProgram call, that uses cilium/ebpf library. Changing 'kprobe' tail call program names to 'tracepoint' and using tracepoint specific tail call map. Signed-off-by: Jiri Olsa <[email protected]>
Removing tracepoint loader gco code, because it's no longer needed. Signed-off-by: Jiri Olsa <[email protected]>
Removing TraceFD and all its return values. It was used to keep track and close opened tracepoints, which is no longer needed, because tracepoints are loaded via cilium ebpf library and are unloaded with chained unloader defined in TracepointAttach function. Signed-off-by: Jiri Olsa <[email protected]>
Adding program.LoadKprobeProgram function that creates kprobe from sensor program. Signed-off-by: Jiri Olsa <[email protected]>
Replacing current libbpf kprobe loader code with program.KprobeAttach call, that uses cilium/ebpf library. Adding kprobe specific tail call map. There's one difference to sysfs bpf layout - we no longer pin all the tail call programs, just the main, so for example for sys_close syscall, the we pin just following files: kprobe___x64_sys_close kprobe___x64_sys_close-kp-calls instead of current: kprobe___x64_sys_close kprobe___x64_sys_close_0 kprobe___x64_sys_close_1 kprobe___x64_sys_close_10 kprobe___x64_sys_close_2 kprobe___x64_sys_close_3 kprobe___x64_sys_close_4 kprobe___x64_sys_close_5 kprobe___x64_sys_close_6 kprobe___x64_sys_close_7 kprobe___x64_sys_close_8 kprobe___x64_sys_close_9 kprobe___x64_sys_close-kp-calls Signed-off-by: Jiri Olsa <[email protected]>
Adding support to load override program if it's defined for kprobe. It's attached 'prior' the kprobe itself so it's ensured it's called 'after' the kprobe. Signed-off-by: Jiri Olsa <[email protected]>
Removing kprobe loader gco code, because it's no longer needed. Signed-off-by: Jiri Olsa <[email protected]>
Using ebpf/cilium interface to detect features. Signed-off-by: Jiri Olsa <[email protected]>
We need following fix for ebpf: d17ebbefb05d ("map: Do not chec maxEntries for PerfEventArray map") It's not released yet, so updating go.mod to point to branch check-out-ed from v0.9.0 with cherry-pick-ed above fix. And plus changes from running 'go mod vendor'. Signed-off-by: Jiri Olsa <[email protected]>
Thank you @olsajiri Does this support the Example verbose:
The verbose flag is intended to set verbosity level which I think it is only used when loading bpf programs, so maybe improve its description while you are it: Also would be cool to have a bogus bpf program test that we try to load set verbose flag and make sure that we have the failed output... |
hum, so the verifier log will show even without verbose option, like:
the original behavior is to display that only with --verbose option, another change to using libbpf is the verbose output of libbpf loading programs, |
Passing 'verbose' setup to loadProgram function and using it to display verifier error output only when verbose != 0, which was default behaviour for libbpf loader. Signed-off-by: Jiri Olsa <[email protected]>
great! |
Adding tracepoints and kprobe loading support so far.
There's still btf package that needs to be migrated,
will be done in following PR.
Signed-off-by: Jiri Olsa [email protected]