Skip to content
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

Add kprobepin example showing how to re-use a pinned map in a BPF prog #364

Merged
merged 2 commits into from
Aug 11, 2021

Conversation

ungureanuvladvictor
Copy link
Member

@ungureanuvladvictor ungureanuvladvictor commented Aug 4, 2021

Chatted with @ti-mo on Slack about adding an example on how to re-use a pinned map given this is something supported by the library. I figured out the current kprobe example is pretty good given it keeps a counter of how many time sys_execve got called.

@ungureanuvladvictor ungureanuvladvictor marked this pull request as ready for review August 5, 2021 16:12
@ungureanuvladvictor ungureanuvladvictor force-pushed the vladu/kprobepin branch 2 times, most recently from 33f3b5d to ef848b1 Compare August 10, 2021 14:21
Signed-off-by: Vlad Ungureanu <vladu@palantir.com>
examples/kprobepin/main.go Outdated Show resolved Hide resolved
var kProbeObj KProbePinExampleObjects
if err := LoadKProbePinExampleObjects(&kProbeObj, &ebpf.CollectionOptions{
Maps: ebpf.MapOptions{
PinPath: bpfFSPath,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment that explains what this does? Plus, please use a subdirectory of /sys/fs/bpf: filepath.Join(bpfFSPath, "execve_probe").

Copy link
Member Author

@ungureanuvladvictor ungureanuvladvictor Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up calling os.MkdirAll which is a no-op if the path exists, let me know if this is good.

examples/kprobepin/main.go Outdated Show resolved Hide resolved
examples/kprobepin/main.go Show resolved Hide resolved
Signed-off-by: Vlad Ungureanu <vladu@palantir.com>
@lmb lmb merged commit 5bce951 into cilium:master Aug 11, 2021
@lmb
Copy link
Collaborator

lmb commented Aug 11, 2021

Thanks!

@ti-mo
Copy link
Collaborator

ti-mo commented Aug 11, 2021

Very clean, thanks!

@zhangzhiqiangcs
Copy link

zhangzhiqiangcs commented Mar 3, 2023

Hello, all, I run into this kprobepin demo with the problem that

failed to create bpf fs subpath: mkdir /sys/fs/bpf/sys_execve: no such file or directory

but I have /sys/fs/bpf/ directory and filesystem is sysfs.

Any ideas or documents can help with this situation?

Thanks for any help.

@zhangzhiqiangcs
Copy link

found a issue: #926

@ti-mo
Copy link
Collaborator

ti-mo commented Mar 3, 2023

@zhangzhiqiangcs /sys/fs/bpf needs to be of type bpffs, not sysfs. Your distribution's init system (I assume you're also on wsl2?) usually takes care of setting this up.

Otherwise: mount -t bpf bpf /sys/fs/bpf.

@zhangzhiqiangcs
Copy link

@ti-mo Sorry to forget paste my os-release. My machine is Ubuntu 18.04 .

I am not sure why /sys/fs/bpf is exists and is sysfs type.

Execute command mount -t bpf bpf /sys/fs/bpf really solved my problem. Now the example runs as expect! Thank you very much !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants