-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
bpf: refactor skeleton generation #20429
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
Conversation
f72f400 to
4613dc0
Compare
791c04f to
d05a190
Compare
| /* libbpf is used via dlopen(), so rename symbols */ | ||
| #define bpf_object__open_skeleton sym_bpf_object__open_skeleton | ||
| #define bpf_object__load_skeleton sym_bpf_object__load_skeleton | ||
| #define bpf_object__destroy_skeleton sym_bpf_object__destroy_skeleton |
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.
Think this approach should work?
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.
not sure I follow, this was not necessary with the previous hook, why is it necessary now?
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.
Previously this was being done manually with a regex in the python script, however I didn't see a clean way to do that with meson directly. This seems to work though.
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.
are these fixed? or can they change dynamically?
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.
Fixed I think, regex would likely break as well if they get changed.
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 meant, the regex catched any of these if new ones were added, while this is hard-coded - will there be new skeleton functions added? Is that possible?
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 think manual changes would typically also end up being required in a few places either way.
|
/cc @keszybz @wat-ze-hex |
e7ebde0 to
c050465
Compare
|
IMO having bloated E.g. there are two other features pending #18145 and #18385. If this PR gets merged, this would mean dull nearly-copy-pasting of The goal of FWIW, @poettering brought up integration with meson in the original PR introduced both libbpf and build script: #17655 (comment) Hence could you please provide a better description of the problem in this PR, similar to a standard template used for filing an issue (target platform, distribution, error message, etc). |
This looks less bloated IMO since it eliminated the python script that is attempting to do the same thing.
Yeah, that would be ideal, but at least this should be cleaner and more reliable.
I assume you are referring to
I did file an issue with meson. If we need something reuseable we can probably use a generator. I try to avoid external scripts as those tend to be difficult when it comes to making cross compilation work correctly.
I mean, it's super broken in any cross compilation scenario, for example: |
The script is reusable for other contributors, that was the point. When #18145 and #18385 are merged further modifying (e.g. changing compilation flags) would mean modifying in three places rather than in one, and this will only get worse when more features are added.
I agree, cross-compilation must be addressed, thanks for raising an issue. I didn't pay a proper attention to it in #17655 since it was huge enough.
SG, will take a close look tomorrow (It's past 11PM atm). |
The script is kinda a maintainability/reliability nightmare IMO, I'll see if I can make this work as a reusable generator. |
I experimented there and it seems the generator feature is too broken to be usable for this. We can at least centralize the clang command params however to reduce code duplication a bit, should at least be more reliable than using external scripts. |
| #include "bpf-dlopen.h" | ||
| #include "bpf-link.h" | ||
| #include "bpf/socket_bind/socket-bind.skel.h" | ||
| #include "bpf/socket_bind/socket-bind-skel.h" |
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.
please stick to .bpf.c and .skel.h conventions, that are used pretty universally across many BPF-based projects
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 bpftool generated socket-bind.skel.h file exists still with the same name as before, it just gets included by socket-bind-skel.h(which redefines the libbpf symbols to avoid linker issues). I can't rename it to socket-bind.skel.h as the file with that name already exists. Should I rename it to something different?
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.
Renamed to socket-bind-skel-wrapper.h.
|
@wat-ze-hex note that with recent enough bpftool (we can lookup exact minimal version) BPF static linking is supported, which is a good feature in itself (allows to break up BPF files into smaller, potentially re-usable .bpf.c files), but it also make llvm-strip unnecessary ( |
Does this work when cross compiling? |
|
Re-based with #18385 build handling as well. |
|
I can't really comment on this. Our resident Python/Meson guru is @keszybz, so I'll defer to him. |
e1c6854 to
e1a4d3d
Compare
This should hopefully fix cross compilation for the bpf programs.
|
Rebased again, @keszybz did you get a chance to look at this? |
bluca
left a comment
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 superficially fine to me, but needs another pair of eyes
To some extent this is true. But it is better for us to have more stuff implemented directly in meson. Then we don't need to care about dependency handling, or debugging ( As I was looking at this PR, I actually noticed a minor issue with the previous implementation. The tool wrote the output files in $SOURCEDIR instead of $BUILDDIR. We never noticed because we still had OTOH, I'm not sure if the patch handles all dependencies correctly. When I do |
|
There seems to be a bug in meson. I'll report it separately. I think it doesn't matter too much, most people don't modify the .bpf.c files, and with a build from scratch this will not matter. |
|
It seems that there is no bug. Seems like I messed something up during testing. $ touch src/core/bpf/restrict_fs/restrict-fs.bpf.c
$ ninja -C build
this rebuilds 4 targets:
src/core/bpf/restrict_fs/restrict-fs.bpf.unstripped.o
src/core/bpf/restrict_fs/restrict-fs.bpf.o
src/core/bpf/restrict_fs/restrict-fs.skel.h
version.hbut this rebuilds 114 targets: $ sed -r -i 's/cgroup_id =/\0 1 +/' src/core/bpf/restrict_fs/restrict-fs.bpf.c
$ ninja -C buildSo it seems meson/ninja are able to correctly shortcircuit the build when there are no changes. Before this PR: $ touch src/core/bpf/restrict_fs/restrict-fs.bpf.c
$ ninja -C build -v
34 targets
$ sed -r -i 's/cgroup_id =/\0 1 +/' src/core/bpf/restrict_fs/restrict-fs.bpf.c
$ ninja -C build
122 targetsThe new scheme seems to handle dependencies better. |
Those made sense when autotoolz were used. With meson, everything should land in the build dir, and this is only likely to obscure issues with custom build rules. C.f. systemd#20429 (comment)
@anakryiko FYI I've implemented this in #22317 with a fallback so that we don't have to bump the bpftool minimum version. |
Those made sense when autotoolz were used. With meson, everything should land in the build dir, and this is only likely to obscure issues with custom build rules. C.f. systemd/systemd#20429 (comment)
This should hopefully fix cross compilation for the bpf programs.