Skip to content

Ksyms module btf fallback#1594

Open
altugbozkurt07 wants to merge 3 commits into
aya-rs:mainfrom
altugbozkurt07:ksyms-module-btf-fallback
Open

Ksyms module btf fallback#1594
altugbozkurt07 wants to merge 3 commits into
aya-rs:mainfrom
altugbozkurt07:ksyms-module-btf-fallback

Conversation

@altugbozkurt07

@altugbozkurt07 altugbozkurt07 commented Jun 6, 2026

Copy link
Copy Markdown

Build on the typed ksym support in #1372 and the split-BTF view support in #1593 to resolve extern ksyms defined by kernel modules.

The ksyms PR resolves typed extern variables and kfuncs against vmlinux BTF. That is not enough for module-defined symbols, because module BTF is split BTF: it defines module-local symbols while referencing base vmlinux types. This PR discovers loaded module BTF objects lazily when vmlinux cannot resolve all typed externs, resolves those externs through SplitBtf, and keeps the module BTF FDs alive until program load.

Module-BTF relocations also need different kernel ABI encoding than vmlinux relocations. This PR tracks whether an extern resolved to vmlinux, module BTF, kallsyms, or weak-missing, then patches module kfunc calls with the module BTF fd-array index and module variable references with the module BTF object FD.

This also adds opt-in xtask support for building and injecting integration-test kernel modules, so module-BTF behavior can be tested in the VM integration flow.

Added tests for:

  • typed extern variable and function resolution from module BTF
  • lazy module-BTF discovery only when vmlinux resolution is insufficient
  • module kfunc and module variable relocation encoding
  • invalid module-BTF relocation cases
  • module BTF fd-array indexing
  • integration coverage with a test kernel module exporting a typed ksym used by an eBPF program

This change is Reviewable

Collect extern symbols from object BTF and fix up the .ksyms datasec
so the resulting BTF is acceptable to the kernel.

Resolve typed extern vars and kfuncs through kernel BTF. Fall back to
/proc/kallsyms for typeless vars, then apply the corresponding extern
relocations before program load.

Expose the object-level ksym APIs in aya-obj via
Object::resolve_externs(), Object::relocate_externs(), and KsymsError.

Weak extern handling follows libbpf-style behavior. Unresolved weak var
references are null-patched, unresolved weak kfunc calls are poisoned,
and unresolved strong extern relocations are rejected.

Add integration coverage for typed ksyms, typed kfuncs,
kallsyms-backed ksyms, and missing strong-symbol failures.
Model split BTF as a borrowed view over base and split BTF objects instead of storing base BTF state inside Btf itself. This keeps Btf as a standalone parsed metadata blob while allowing lookup code to resolve type IDs and string offsets through the combined split-BTF namespace.

Move shared type walking helpers behind BtfView and make type/field compatibility generic over that view. Existing callers still use Btf directly, while module-BTF resolution can pass SplitBtf in a follow-up.
@altugbozkurt07 altugbozkurt07 requested a review from a team as a code owner June 6, 2026 19:26
@netlify

netlify Bot commented Jun 6, 2026

Copy link
Copy Markdown

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7baeca3
🔍 Latest deploy log https://app.netlify.com/projects/aya-rs-docs/deploys/6a248b27e46f780008e24b33
😎 Deploy Preview https://deploy-preview-1594--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@altugbozkurt07 altugbozkurt07 force-pushed the ksyms-module-btf-fallback branch 3 times, most recently from 7020ff2 to 405593e Compare June 6, 2026 20:47
Discover module BTFs lazily when typed ksym externs cannot be resolved from vmlinux, keep module BTF FDs alive until program load, and encode module variable/kfunc relocations with the kernel ABI expected FD form.

Add opt-in xtask support for building and injecting integration-test kernel modules, plus a first module-BTF typed ksym integration fixture and local custom-kernel validation helper.
@altugbozkurt07 altugbozkurt07 force-pushed the ksyms-module-btf-fallback branch from 405593e to 7baeca3 Compare June 6, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant