-
-
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
Fixup generated BTF for older kernels #2934
Conversation
b55679f
to
eb565b4
Compare
@xiaoqing-wei @the-prachi do you think you'd be able to test this fix on your setup? Unfortunately, we don't build static binaries for PRs but you could build it yourself by running I was able to test this on my local reproducer of #2913 but would like to have a confirmation that it fixes the issue. |
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.
Code looks good but someone with more btf experience should have a look.
Older kernels missing [1] (most importantly the stable 5.4) do not support BTF function entries with global linkage (BTF_FUNC_GLOBAL). This causes them to reject our generated BTF for probes and prevents from running any bpftrace program. In order to fix this, the generated BTF must be patched by replacing the BTF_FUNC_GLOBAL flag by 0. This is normally done by libbpf [2] but only when program loading via bpf_object is used. Since we're still using direct loading using bpf_btf_load and bpf_prog_load, we need to mimic libbpf's behavior and do the patching manually. Note that we cannot fix this directly in codegen b/c LLVM would optimize all our probes away. The BTF fixup itself is pretty simple but required to copy a portion of code from libbpf internals. The reason is that libbpf doesn't export functions for iterating BTF in a non-const way. This also requires to feature-detect support for BTF_FUNC_GLOBAL, so we extend BPFfeature with BTF feature detection. [1] torvalds/linux@51c39bb1d5d1 [2] torvalds/linux@2d3eb67f64ec
eb565b4
to
05bfb81
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.
Looks good to me!
I was able to reproduce the issue on 5.4.266 kernel and confirm that this fix works. So, I'll go ahead and merge this as it's blocking me on other work. |
I saw there's a new tagged build and it's working for me. https://github.com/iovisor/bpftrace/releases/download/v0.20.0/binary_tools_man-bundle.tar.xz |
Older kernels missing torvalds/linux@51c39bb1d5d1 (most importantly the stable 5.4) do not support BTF function entries with global linkage (
BTF_FUNC_GLOBAL
). This causes them to reject our generated BTF for probes and prevents from running any bpftrace program.In order to fix this, the generated BTF must be patched by replacing the
BTF_FUNC_GLOBAL
flag by 0. This is normally done by libbpf (torvalds/linux@2d3eb67f64ec) but only when program loading via bpf_object is used. Since we're still using direct loading usingbpf_btf_load
andbpf_prog_load
, we need to mimic libbpf's behavior and do the patching manually. Note that we cannot fix this directly in codegen b/c LLVM would optimize all our probes away.The BTF fixup itself is pretty simple but required to copy a portion of code from libbpf internals. The reason is that libbpf doesn't export functions for iterating BTF in a non-const way.
This also requires to feature-detect support for
BTF_FUNC_GLOBAL
, so we extendBPFfeature
with BTF feature detection.Fixes #2913.
Checklist
man/adoc/bpftrace.adoc
and if needed indocs/reference_guide.md
CHANGELOG.md