Repository navigation
btf, linker: resolve kfuncs by essential name when exact match fails - #2098
Draft
Ananttyagi07 wants to merge 1 commit into
Draft
Ananttyagi07 wants to merge 1 commit into
Ananttyagi07 wants to merge 1 commit into
Conversation
Adds btf.EssentialName, an exported wrapper around the existing CO-RE "ignored suffix rule" logic, and uses it in fixupKfuncs as a fallback: if a kfunc's exact name isn't found in the kernel, retry with the ___ flavour suffix stripped. This lets a BPF program declare multiple ___-suffixed variants of a kfunc that has changed signature across kernel versions (e.g. "foo___old" and "foo") and have the correct one resolve automatically against whatever kernel it runs on, per cilium#2057. The existing btf.CheckTypeCompatibility call in fixupKfuncs already runs unconditionally after resolution, so it continues to guard against silently binding to an unrelated kfunc that happens to share the essential name. Scoped the fallback to fixupKfuncs specifically rather than changing findTargetInKernel itself, since that helper is also used for program attach-target and struct_ops lookups, where fuzzy suffix matching would be an unwanted, silent change in behavior. Testing: - go build ./..., go vet ./..., gofmt -l all clean. - Added TestEssentialNameExported for the new exported wrapper; the underlying suffix-stripping logic already has thorough coverage in TestEssentialName. - Could not exercise the fixupKfuncs retry path itself end-to-end: it requires loading a program against real kernel BTF, and this dev environment has neither CAP_BPF nor a way to fabricate a kfunc with multiple kernel-version signatures to test against. Generative AI disclosure: per the Cilium Generative AI policy, I used Claude (Anthropic) while preparing this change. It helped trace where kfunc name resolution actually happens (fixupKfuncs in linker.go, distinct from the typed-ksym-var path in the same file), confirmed that the signature-compatibility half of this issue was already implemented via btf.CheckTypeCompatibility, and helped scope the fix to the kfunc call site rather than the shared findTargetInKernel helper. I reviewed and understood the resulting design and code before submitting. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Anant Tyagi <tyagianant65@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2057. When a kfunc call can't be resolved by its exact name in
the kernel's BTF, retry using the name with its
___flavour suffixstripped (its "essential name"), matching the same "ignored suffix
rule" already used for CO-RE relocations.
This lets a BPF program declare multiple
___-suffixed variants of akfunc whose signature has changed across kernel versions (e.g.
foo___old,foo) and have the variant matching the running kernelresolve automatically, instead of only ever resolving kfuncs with an
exact name match.
What was already there vs. what this adds
While tracing this, I found the signature-compatibility half of the
issue ("ensure its function signature is the same") is already
implemented:
fixupKfuncsinlinker.gocallsbtf.CheckTypeCompatibilityon whatever target is resolved, beforeusing it. So the only missing piece was the name resolution itself,
which was doing an exact match only (
findTargetInKernel→Spec.TypeByName, no suffix handling).This adds
btf.EssentialName, an exported wrapper around theexisting internal
newEssentialName/essentialNameLenCO-RE logic(so the suffix-stripping rule itself isn't duplicated), and uses it
as a fallback in
fixupKfuncsspecifically — not infindTargetInKernelitself, since that helper is shared with programattach-target and struct_ops lookups, where fuzzy suffix matching
would be an unwanted, silent behavior change.
Testing
go build ./...,go vet ./...,gofmt -lall clean.TestEssentialNameExportedfor the new exported wrapper. Thesuffix-stripping logic itself already has thorough edge-case
coverage via the existing
TestEssentialName.fixupKfuncsretry path end-to-end: thatrequires loading a program against real kernel BTF containing a
kfunc with multiple versioned signatures, and this dev environment
has neither CAP_BPF nor such a kfunc available to test against.
Marking as draft for that reason — happy to add an integration test
if a maintainer can point me at a suitable existing kfunc/kernel
fixture, or if there's a preferred way to fake this in the test
suite.
Generative AI disclosure
Per the Cilium Generative AI policy: I used Claude (Anthropic) while
preparing this submission. It helped trace where kfunc resolution
actually happens in the codebase, confirmed the signature-compatibility
check already existed, and helped scope the fix to avoid changing
shared lookup behavior used by other callers. I reviewed and
understood the resulting design and code before submitting, and I'm
happy to discuss any part of it further during review.
🤖 Generated with Claude Code