Skip to content
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

BPF_CALL for eBPF functions incorrectly refers to offset instead of imm #11

Open
Alan-Jowett opened this issue Nov 29, 2022 · 3 comments

Comments

@Alan-Jowett
Copy link
Collaborator

https://github.com/dthaler/ebpf-docs/blob/update/isa/kernel.org/instruction-set.rst#jump-instructions
https://github.com/dthaler/ebpf-docs/blob/update/isa/kernel.org/instruction-set.rst#ebpf-functions

BPF call instruction with src == 1 should pass the offset to the BPF function via the immediate field and not the offset field.

@Alan-Jowett
Copy link
Collaborator Author

Found while fixing Alan-Jowett/bpf_conformance#60

@yesh0
Copy link

yesh0 commented Dec 1, 2022

By the way, one may verify the statement against the Linux implementation in its verifier, which uses insn->imm as the offset:

https://github.com/torvalds/linux/blob/ef4d3ea40565a781c25847e9cb96c1bd9f462bc6/kernel/bpf/verifier.c#L2198-L2199

if (bpf_pseudo_func(insn) || bpf_pseudo_call(insn))
    ret = add_subprog(env, i + insn->imm + 1);

@Alan-Jowett
Copy link
Collaborator Author

Thanks @yesh0 I appreciate the feedback. Unfortunately, due to license conflicts, I can't look at the Linux eBPF code (I work on a MIT licensed BPF runtime). The approach I have been taking is to use a set of tests in bpf_conformance to measure the behavior of Linux (and verify that other BPF implementations match the Linux behavior).

While implementing the corresponding BPF assembler (using Intel style assembly) for this test, I noticed that setting the offset in the offset field didn't work, hence filing this issue to get the doc updated.

We are also using the same test suites to verify that the behavior of other BPF implementations is correct, including uBPF, rbpf, prevail verifier, and bpf2c.

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

No branches or pull requests

2 participants