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

[v1.15] Replaced declare_tailcall_if with logic in the loader #31554

Merged
merged 6 commits into from Mar 25, 2024

Conversation

ti-mo
Copy link
Contributor

@ti-mo ti-mo commented Mar 22, 2024

Once this PR is merged, a GitHub action will update the labels of these PRs:

 30467 31419

[ upstream commit 46db413 ]

Remove `declare_tailcall_if`, so we always emit the tailcall programs
into the ELF. The followup commit will implement pruning logic based
on the actual usage of the tail calls. This means that we will only
need the `invoke_tailcall_if` without the need to keep both the
declaration and invocation in sync.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo added kind/backports This PR provides functionality previously merged into master. backport/1.15 This PR represents a backport for Cilium 1.15.x of a PR that was merged to main. labels Mar 22, 2024
@ti-mo ti-mo changed the title v1.15 Backports 2024-03-22 [v1.15] Replaced declare_tailcall_if with logic in the loader Mar 22, 2024
[ upstream commit c4cbb38 ]

Before this change the tail_call_static function would emit the
following instructions to perform a tailcall:

```
Mov R1, Rctx
Mov R2, Rmap_ptr
Mov R3, <slot>
Call TailCall
```

Since the second instruction is always a Register to Register move, we
would have to backtrack to find the actual map which is being used.

These changes makes it so the following instructions are emitted:

```
Mov R1, Rctx
Mov R2, 0 ll <calls_map>
Mov R3, <slot>
Call TailCall
```

By always using a double word immediate, with a relocation entry on the
Mov R2 instruction it is much easier to find the actual map which is
being used. As a side effect, we usually eliminate an extra instruction
clang was otherwise forced to emit.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
[ upstream commit 16033b9 ]

This commit implements unreachable tail call pruning. When loading a
collection we check if a tail call is reachable. If not, we remove the
tail call from the collection. This saves us from having to load the
tail call program into the kernel.

Previously, we would conditionally not include tail calls in the
collection with pre-processor directives. Now that we do it in the
loader, we can remove the pre-processor directives.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
@ti-mo ti-mo force-pushed the pr/v1.15-backport-2024-03-22-11-23 branch from 6a6a5db to 0db21c7 Compare March 22, 2024 12:37
@ti-mo
Copy link
Contributor Author

ti-mo commented Mar 22, 2024

/test

@ti-mo
Copy link
Contributor Author

ti-mo commented Mar 22, 2024

/test-backport-1.15

@dylandreimerink
Copy link
Member

We might also want to include #31419 where the CI contrib script got fixed which included an issue in my initial PR

@ti-mo
Copy link
Contributor Author

ti-mo commented Mar 22, 2024

/test-backport-1.15

@ti-mo ti-mo marked this pull request as ready for review March 22, 2024 14:01
@ti-mo ti-mo requested a review from a team as a code owner March 22, 2024 14:01
dylandreimerink and others added 3 commits March 22, 2024 15:24
[ upstream commit 217426a ]

[ backporter's notes: regenerated testdata ]

This commit adds a test to verify the behavior of the dead tail call
pruning. It consists of 5 tail calls, of which 2 are unreachable. The
test asserts that only the unreachable tail calls are removed from the
spec.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Signed-off-by: Timo Beckers <timo@isovalent.com>
[ upstream commit e1afa06 ]

The changes to the dead tail call elimination revealed 2 cases of
missing tail calls.

First is to do with NAT46x64 logic where there
still existed a call path from the IPv4 logic which would attempt to
tail call into IPv6 to recirculate the packet, even when the IPv6 tail
call wasn't compiled in.

The second was that when XDP offloaded, the IPv6 logic would tail call
into a ICMP6 tail call which is only compiled in for TC programs.

This commit fixes both possible missing tail calls.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Signed-off-by: Timo Beckers <timo@isovalent.com>
[ upstream commit d6666ed ]

Currently, check-go-testdata.sh doesn't work as expected on CI.

It reports the following error and the GitHub action (Go Precheck)
succeeds without error.

```
contrib/scripts/check-go-testdata.sh
make[1]: Entering directory '/home/runner/work/cilium/cilium/src/github.com/cilium/cilium/pkg/bpf/testdata'
docker run -it --rm -v /home/runner/work/cilium/cilium/src/github.com/cilium/cilium:/cilium quay.io/cilium/cilium-builder:819a4f1e57eaacb6aabfc6a1a39d11d4fd794a88@sha256:24781dc80f2be2d8fd66b0ce1405e1f117a3a0ef388758b1ede7831778e3a4f7 clang -target bpf -Wall -O2 -g -I -I/usr/include -I/cilium/bpf -I/cilium/bpf/include -c /cilium/pkg/bpf/testdata/unreachable-tailcall.c -o /cilium/pkg/bpf/testdata/unreachable-tailcall.o
the input device is not a TTY
make[1]: *** [Makefile:9: build] Error 1
make[1]: Leaving directory '/home/runner/work/cilium/cilium/src/github.com/cilium/cilium/pkg/bpf/testdata'
```

This commit fixes the following issues:

- Don't execute docker interactive
- Use 'set -e' in check script

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
@ti-mo ti-mo force-pushed the pr/v1.15-backport-2024-03-22-11-23 branch from 2a4f3ed to ea001bf Compare March 22, 2024 14:24
@ti-mo
Copy link
Contributor Author

ti-mo commented Mar 22, 2024

/test-backport-1.15

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Mar 25, 2024
@squeed squeed merged commit 9690ac3 into v1.15 Mar 25, 2024
225 of 227 checks passed
@squeed squeed deleted the pr/v1.15-backport-2024-03-22-11-23 branch March 25, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.15 This PR represents a backport for Cilium 1.15.x of a PR that was merged to main. kind/backports This PR provides functionality previously merged into master. ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants