-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
BEGIN/END: Add more reliable implementation #2264
Conversation
72eb896
to
f86d940
Compare
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.
I really like this, handling of BEGIN/END has been a bit of pain so far.
Just one thing: there are some places where BEGIN and END are treated as special cases of uprobes. Those could be cleaned as a part of this PR.
Which parts are you referring to? I left the old codepath in b/c BPF_PROG_RUN for raw_tp was only added in late 2020: https://lore.kernel.org/bpf/[email protected]/ . So I'm concerned we'll leave some of our users hanging if we only use this new approach. |
I found 2 occurrences that could be removed: |
Ah yeah good finds. I'll fix that up and debug the test failures some time this week. |
Done |
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.
Thanks for doing this, looks much better!
Better to remove as many default cases as possible cuz when someone adds a new enum type they'll get a compiler warning instead of a runtime failure some time later.
Create a separate probe type for BEGIN/END probes. Currently a noop in this commit. We will use this new probe type in the next commit to implement a more reliable special probe.
We will be using BPF_PROG_RUN on this prog type to implement BEGIN/END probes next.
Before, we implemented BEGIN/END probes as uprobes, attached the probes to trigger functions in /proc/self/exe, and triggered the prog by calling the trigger functions. This works well most of the time except for when distros decide to strip symbols from bpftrace. This commit makes BEGIN/END probes more reliable by implementing special probes as BPF_PROG_TYPE_RAW_TRACEPOINT and calling BPF_PROG_RUN on them. This is ok b/c we don't allow users to access any associated `ctx` in speical probes anyways. And we choose raw_tp prog type b/c it has BPF_PROG_RUN implemented. I did try to implement BPF_PROG_RUN on BPF_PROG_TYPE_KPROBE in the kernel but upstream didn't like it too much: https://lore.kernel.org/bpf/[email protected]/ . So we have raw_tp instead.
Even though this change should be somewhat transparent to the user, most distros have stopped stripping bpftrace symbols to work around bpftrace limitations. So add entry in changelog in case anyone is checking.
Tests: 1701 1722 1723 Issue: nm: /usr/bin/bpftrace: no symbols fixed: bpftrace/bpftrace#2264 but yet arrive upstream (or is that downstream?)
Before, we implemented BEGIN/END probes as uprobes, attached the probes
to trigger functions in /proc/self/exe, and triggered the prog by calling
the trigger functions. This works well most of the time except for when
distros decide to strip symbols from bpftrace.
This commit makes BEGIN/END probes more reliable by implementing special
probes as BPF_PROG_TYPE_RAW_TRACEPOINT and calling BPF_PROG_RUN on them.
This is ok b/c we don't allow users to access any associated
ctx
inspeical probes anyways. And we choose raw_tp prog type b/c it has
BPF_PROG_RUN implemented.
I did try to implement BPF_PROG_RUN on BPF_PROG_TYPE_KPROBE in the
kernel but upstream didn't like it too much:
https://lore.kernel.org/bpf/[email protected]/ .
So we have raw_tp instead.
Checklist
man/adoc/bpftrace.adoc
and if needed indocs/reference_guide.md
CHANGELOG.md