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

Execute and test CO-RE relocations of bpf2bpf subprogs #590

Merged
merged 2 commits into from Mar 7, 2022

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Mar 4, 2022

btf: include CO-RE relocations of bpf2bpf subprograms

ProgramSpecs read from an ELF contain the full instruction streams from the
bpf2bpf subprograms they call. When marshaling a program to be inserted into
the kernel, FuncInfos and LineInfos are collected from all called subprogs,
but CO-RE relocations were notably skipped after the linker rework in 9d739bd.

This commit gathers CO-RE relos for all subprogs included in the final
instruction stream and modifies their offsets to point to their new locations.

btf: add CO-RE read test that fails unless relocations were correctly applied

The linker rework in 9d739bd caused a piece of code that appended CORERelos
to the entrypoint instruction stream to be forgotten. The existing CO-RE tests
were all written in a way where the BPF programs would return 0 (success) if
no CO-RE relocations were applied at all.

This caused CO-RE relocations against functions (subprogs) that were only
included by a bpf2bpf call to be skipped.

This patch adds a broken test program that returns non-zero if left unaltered,
and requires CO-RE relocation against another BTF blob to return 0.
Additionally, the checks are performed from a non-inlined subprogram to ensure
CO-RE relocations against subprogs work.


@eiffel-fl could you verify if this solves your problem?

Fixes #586

@ti-mo ti-mo requested a review from lmb March 4, 2022 17:12
@eiffel-fl
Copy link
Contributor

Hi.

I tested it with the initial tool I was testing and specifying __attribute((noinline)) and it worked fine!
I also take a quick look to your code and it is cool!
Thank you for this :D :D :D

If you need test or review or anything, feel free to ping!

Best regards.

ProgramSpecs read from an ELF contain the full instruction streams from the
bpf2bpf subprograms they call. When marshaling a program to be inserted into
the kernel, FuncInfos and LineInfos are collected from all called subprogs,
but CO-RE relocations were notably skipped after the linker rework in 9d739bd.

This commit gathers CO-RE relos for all subprogs included in the final
instruction stream and modifies their offsets to point to their new locations.

Signed-off-by: Timo Beckers <timo@isovalent.com>
… applied

The linker rework in 9d739bd caused a piece of code that appended CORERelos
to the entrypoint instruction stream to be forgotten. The existing CO-RE tests
were all written in a way where the BPF programs would return 0 (success) if
no CO-RE relocations were applied at all.

This caused CO-RE relocations against functions (subprogs) that were only
included by a bpf2bpf call to be skipped.

This patch adds a broken test program that returns non-zero if left unaltered,
and requires CO-RE relocation against another BTF blob to return 0.
Additionally, the checks are performed from a non-inlined subprogram to ensure
CO-RE relocations against subprogs work.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo merged commit b45a91a into cilium:master Mar 7, 2022
@ti-mo ti-mo deleted the tb/multiprog-core-relos branch March 7, 2022 21:10
linker.go Show resolved Hide resolved
linker.go Show resolved Hide resolved
linker.go Show resolved Hide resolved
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.

Relocation is not called for some BPF_CORE_READ
3 participants