-
Notifications
You must be signed in to change notification settings - Fork 697
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
features: add HaveProgramHelper API #375
Conversation
Compared to bpftool I just check for EACCES and EINVAL for now instead of checking the verifier log. Not sure if that suffices and if there is an (future) edge case that could break this and result in a false negative/positive. cc @ti-mo @qmonnet |
Did you compare the results with bpftool's (minus the ones for the few program types that aren't working properly on bpftool)? Do you get the same thing? |
Initially I just checked a few helpers for equality randomly, but now did the full comparison and I actually come up short for like 5 helper calls regarding the |
So there's just the |
Yes, just |
A few lines above then, because (again) there's no BTF. Yeah, in that case it's not sure there's a way other than parsing the log. We could start making cases for helpers too, but this will be harder to maintain I'm afraid. |
Oh yeah I selected the wrong line 🙈. |
Tricky question. But then the error codes from the verifier are hardly a stable API either 🤷. |
Drive by observation: at least for error codes developers tend to try to preserve them. The same can't be said for the verifier log, and I think we shouldn't rely on it. |
Hey! 👋 Apologies for letting this PR go stale a bit, but I would like to pick it up again so that I eventually can make use of it in cilium. To sum up the current status: Just relying on error codes can result in false negatives, e.g. To get this PR merged I can think of two possible solutions:
I hope @ti-mo and @lmb can give their opinions on the two solutions I proposed or maybe come up with an even better option. |
If at all possible we should avoid having to maintain "quirks" for individual helpers. Some ideas: Parse kernel BTF and look for the appropriate function signatures.
Parse
Maye a combination of "stupid" BPF program probes and either one of these approaches works? |
@rgo3 Welcome back!
This should indeed be the general approach, but there will be exceptions. :) (as there were with the other probe types)
Requiring an external service/db just to get probes to work doesn't sound very appealing IMO. Some helpers (like
Expensive, but generally effective, have resorted to this before. Good last-resort solution for older kernels.
Naturally, but this is what eventually causes death by a 1000 papercuts, as the fallback detection strategy required will vary depending on the helper. This can only be decided when actually implementing these, so let's discuss on actual code. |
The answer to that is to not provide arbitrary helper feature tests, my preferred solution :P |
Is it an option to move forward with this PR keeping it the way it is currently, basically not trying to create a catch-em-all solution right from the start? We already cover lots of possible progtype-helper combinations the way it is, which would suffice for its first use-case in cilium. If people have future use-cases with combinations we don't probe accurately at the moment, we can defer adding fallback strategies or extra probes until then? As a side node, I played a bit with
bpftool shows this helper to be available to multiple prog types on my kernel while |
I'm okay with the initial implementation not being perfect, as long as we have a way of documenting what the errata are. Preferably in tests, with a GH issue to track the follow-up work. That way, if anyone has the need for a particular broken probe, they can grab the issue and go ahead with the implementation. |
What's going to happen to this? |
I'd still like to get some version of this in, considering this would be the most useful when trying to integrate the features API into cilium (which was the original goal of my GSoC project). I got stuck looking for ways to create tests that nicely show what the errata are because of all the possible combinations between prog types and available helpers on respective kernel versions. I could add tests per prog type, start with the prog types I'd need to use this in cilium and add more over time? Like that I wouldn't have to test the full matrix of possibilities for now but only a smaller subset. If yes I'd try to navigate along this list of versions and available helpers per prog type to incrementally add tests? If that's not a clean enough solution to move forward with this PR, I might need to rethink how we could add helper probes to this API. |
Alright, I think it's finally ready to graduate from its draft status.
Locally this test works for me, as my kernel has this helper type compiled in. Additionally there are two more test-cases I couldn't add because the lib doesn't support those particular builtins yet (just a matter of updating the BuiltinFunc enum I think). I've mentioned those in comments above the test-cases. I've also built a small tool to compare the features API to bpftools feature probes. Currently just living on a branch of my fork of the repo. Running that tool yields following output:
I haven't fully investigated why those false negatives exist, but I'd create an issue to track and investigate if we choose to accept that these differ from bpftool currently. cc @florianl |
Could |
So instead of having |
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 bringing this forward! 👍
The PR as is works fine here.
For possible future work wrt bpftoolcmp
I would also vote for having this in a test case like TestBPFToolCompare
. Rather than calling an external tool that exec.Cmd()
another external tool (bpftool
).
Sorry, had to repush as I found some typos... As for the |
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.
Love it.
Could bpftoolcmp just be part of the testsuite? We could skip tests if the binary doesn't exist.
This can be done in a follow-up. 👍
Bit of a late bike shed: can you call the function HaveProgramHelper? |
I can, sort of diverges from |
We can fix that up by introducing HaveProgramType and depreciating the shortened version. |
`HaveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error` allows to probe the available BPF helpers to a given BPF program type. Probe results are cached and run at most once. Signed-off-by: Robin Gögge <r.goegge@gmail.com>
In order to be in line with other naming schemes throughout the library this commit deprecates HaveProgType() in favor of HaveProgamType(). Signed-off-by: Robin Gögge <r.goegge@gmail.com>
HaveProgHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error
allows to probe the available BPF helpers to a given BPF program
type. Probe results are cached and run at most once.
Signed-off-by: Robin Gögge r.goegge@gmail.com