cilium/ebpf v0.10.0 - BTF Marshaling
release ·
We’re pleased to announce the first ebpf-go release of 2023! There is one breaking change, so please read through the release notes carefully. All users are encouraged to upgrade.
Breaking Changes
Support for BTF marshaling
So far, the library would only load BTF into the kernel that was originally generated by clang or pahole. As of this release, the library will instead marshal btf.Types directly into BTF blobs. For example, it’s now possible to create an ebpf.Map from Go code by populating the MapSpec.Key and .Value fields with the map’s k/v types to make bpftool map dump nicely pretty-print its contents for you.
As expected, there are a few important side effects and breaking changes to be aware of:
- Setting
MapSpec.BTFandProgramSpec.BTFtonilcan no longer be used to disable BTF during loading, which was the fields’ last remaining purpose. The fields have been removed to make sure this doesn’t slip through library upgrades unnoticed. - If your userspace program replaces individual instructions in
ProgramSpec.Instructionsbefore loading a program, make sure to copy the old Instruction’s Metadata usingInstruction.WithMetadata(old.Metadata). Not doing so may cause you to discard the original instruction’s func_info or line_info, leading to the verifier rejecting your program with e.g.invalid argument: missing bpf_line_info for func#0. (see https://github.com/cilium/cilium/pull/21933 for how this can go wrong) - Disabling BTF for program loads now requires calling
btf.WithFuncMetadata(ins, nil)on the first instruction of each (sub)program, as well asInstruction.WithSource(nil)on each Instruction containing lineinfo. - Disabling BTF for map loads now requires
MapSpec.Keyand.Valuebeing set to nil.
We’re interested in hearing your use cases for explicitly disabling BTF during map/prog loads. We hope the need for disabling BTF altogether should arise less frequently, given the library falls back gracefully when the underlying kernel doesn’t support BTF. In case you do believe this to be necessary, please raise an issue to discuss this further.
Fixes
NewProgram returns an unwrapped VerifierError
Since commit 148c76cf32ddb279 (“internal: make VerifierError more succinct”) the library has defaulted to omitting most of the verifier log when loading a program failed. The intention was that callers would use formatting with the %+v verb to output as much context as necessary. Due to how error wrapping with fmt.Errorf works this meant that the error had to be unwrapped with errors.As, which led to confusion.
NewProgram and friends now return an unwrapped VerifierError so that callers can format the error more easily.
Reliable VerifierError.Truncate field
Prior to this release, the VerifierError.Truncate field would only be set in case ProgramOptions.LogLevel was left to the default value of 0, among a few other quirks. This has now been resolved, making the VerifierError.Truncate field a reliable driver for a retry loop that automatically grows the verifier log buffer and retries loading the program(s). See https://github.com/cilium/cilium/pull/21973/commits/934bccff82f833dcc532f436b4fb419c5d89cb96 for an example implementation.
Additions
Expanded and overhauled feature probes
features.HaveProgramType() can now conclusively probe for the program types ebpf.LSM, ebpf.Tracing and ebpf.Extension without relying on recognizing specific error return values.
Package features has been refactored to use internal.FeatureTest, unifying error wrapping and result caching with the library’s internal machinery. ErrNotSupported returned from features now includes the minimum required kernel version and a feature name.
Kretprobes allow setting maxactive
The kernel’s kretprobe implementation has a limitation where only a fixed number of concurrent calls to a probed function are handled. Usually the kernel chooses a sufficient default value, but for very busy functions this default is too low. This leads to missed kretprobe events.
There is an (unfortunate) workaround for this: the user can specify how many concurrent calls they want to support via a maxactive parameter. This comes with a lot of drawbacks however. maxactive is only supported when using an obsolete interface to kretprobes, and it’s not at all clear how to arrive at the correct maxactive setting. link.KprobeOptions now exposes this setting to the user, since it is the only partial fix.
The authors of the library recommend to not use maxactive unless absolutely necessary. Incorrect use will make your application more brittle and may have system-wide performance impact.
What’s Changed
- map, prog: fix broken links by @boratanrikulu in https://github.com/cilium/ebpf/pull/816
- program: clarify how to use VerifierError by @lmb in https://github.com/cilium/ebpf/pull/819
- link: Allow kprobe multi to be disabled in kernel by @arthurfabre in https://github.com/cilium/ebpf/pull/812
- Add IsPinned() to RawLink by @boratanrikulu in https://github.com/cilium/ebpf/pull/817
- fix bad link to GitHub Discussions by @dmitris in https://github.com/cilium/ebpf/pull/824
- internal: detect if /proc/self/auxv is not readable due to file caps by @lmb in https://github.com/cilium/ebpf/pull/825
- btf: add support for marshaling Type and use it for Program and Map by @lmb in https://github.com/cilium/ebpf/pull/796
- btf: support enum64 by @willfindlay in https://github.com/cilium/ebpf/pull/820
- Add stringer to ebpf-builder by @lmb in https://github.com/cilium/ebpf/pull/827
- asm: add .WithMetadata() for conveniently replacing individual Instructions by @ti-mo in https://github.com/cilium/ebpf/pull/832
- prog: populate VerifierError.Truncate when LogLevel > 0 by @ti-mo in https://github.com/cilium/ebpf/pull/834
- elf_reader: check if ELF is for BPF data by @florianl in https://github.com/cilium/ebpf/pull/830
- map_test: clean up after tests and close maps by @florianl in https://github.com/cilium/ebpf/pull/841
- btf: check for compatibility first when searching for a CO-RE field by @lmb in https://github.com/cilium/ebpf/pull/852
- Set Program.name when constructing from file descriptor by @aibor in https://github.com/cilium/ebpf/pull/849
- btf: do Datasec fixup on inflated types by @lmb in https://github.com/cilium/ebpf/pull/860
- btf: distinguish ‘map’ and ‘program’ BTF by @ti-mo in https://github.com/cilium/ebpf/pull/855
- program: return unwrapped VerifierError by @lmb in https://github.com/cilium/ebpf/pull/851
- map: export MapSpec.Compatible by @olsajiri in https://github.com/cilium/ebpf/pull/858
- btf: Remove deprecated {Map,Program}Spec.BTF field by @ti-mo in https://github.com/cilium/ebpf/pull/864
- btf: fix some split BTF shortcomings by @lmb in https://github.com/cilium/ebpf/pull/861
- Update dependencies for current Go versions by @thaJeztah in https://github.com/cilium/ebpf/pull/866
- map: include generated pin path in newMapWithOptions error by @ti-mo in https://github.com/cilium/ebpf/pull/870
- features: reuse internal.FeatureTest instead of open coding probes by @lmb in https://github.com/cilium/ebpf/pull/776
- feat: support LSM prog type by @daemon1024 in https://github.com/cilium/ebpf/pull/885
- bpf2go: write dependencies to temporary file to support Windows by @junjiexing in https://github.com/cilium/ebpf/pull/865
- program: block SIGPROF during BPF_PROG_RUN by @lmb in https://github.com/cilium/ebpf/pull/887
- btf: fix function doc typo by @rgo3 in https://github.com/cilium/ebpf/pull/889
- link: add QueryPrograms API by @rgo3 in https://github.com/cilium/ebpf/pull/867
- link: add maxactive for kretprobe by @alahaiyo in https://github.com/cilium/ebpf/pull/755
- Add missing program type feature probes by @rgo3 in https://github.com/cilium/ebpf/pull/890
New Contributors
- @boratanrikulu made their first contribution in https://github.com/cilium/ebpf/pull/816
- @willfindlay made their first contribution in https://github.com/cilium/ebpf/pull/820
- @aibor made their first contribution in https://github.com/cilium/ebpf/pull/849
- @daemon1024 made their first contribution in https://github.com/cilium/ebpf/pull/885
- @junjiexing made their first contribution in https://github.com/cilium/ebpf/pull/865
- @alahaiyo made their first contribution in https://github.com/cilium/ebpf/pull/755
Full Changelog: https://github.com/cilium/ebpf/compare/v0.9.3...v0.10.0