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: Use "fallthrough;", compile with -Wimplicit-fallthrough #26211

Merged
merged 2 commits into from
Jun 16, 2023

Conversation

qmonnet
Copy link
Member

@qmonnet qmonnet commented Jun 14, 2023

Warning to backporters:

Only the first commit should be backported.

We can label intentional fall-throughs and tell clang to report unannotated ones, to catch bugs that would be caused by involuntarily falling through between switch labels.

The result is not super aesthetic in builtins.h or jhash.h, but at the same time it's just one keyword so not too much boilerplate either. And it catches bugs. The one fixed in commit 9a64111 ("bpf: test: fix pktgen for IPv6 NEXTHDR_DEST option"), or the first commit in this PR, were found this way.

I wasn't able to pin down the exact version that got support for the relevant attribute, but clang 10 has it for sure and it seems to be much older than that, so we don't have to worry and test for its availability.

Inspired by checkpatch complaining about the /* fall through */ comments.

@qmonnet qmonnet added sig/loader Impacts the loading of BPF programs into the kernel. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/misc This PR makes changes that have no direct user impact. labels Jun 14, 2023
@qmonnet qmonnet requested review from a team as code owners June 14, 2023 08:49
@qmonnet qmonnet requested a review from lmb June 14, 2023 08:49
@qmonnet
Copy link
Member Author

qmonnet commented Jun 14, 2023

/test

@qmonnet
Copy link
Member Author

qmonnet commented Jun 14, 2023

/test

Copy link
Contributor

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

bpf/lib/egress_policies.h Show resolved Hide resolved
@qmonnet qmonnet added the needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch label Jun 14, 2023
@qmonnet
Copy link
Member Author

qmonnet commented Jun 14, 2023

/test

@qmonnet
Copy link
Member Author

qmonnet commented Jun 14, 2023

/test-runtime

@qmonnet
Copy link
Member Author

qmonnet commented Jun 14, 2023

Rebased to have the Conformance Ginkgo test run
/test

Prevent falling through from IPv6 to IPIP when creating SRV6 state
entries based on the encapsulated header protocol.

Caught by compiling with -Wimplicit-fallthrough.

Fixes: bfba740 ("bpf: Handle reply SRv6 traffic")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
We can label intentional fall-throughs and tell clang to report
unannotated ones, to catch bugs that would be caused by involuntarily
falling through between switch labels.

The bug fixed in commit 9a64111 ("bpf: test: fix pktgen for IPv6
NEXTHDR_DEST option") was found this way.

I wasn't able to pin down the exact version that got support for the
relevant attribute, but clang 10 has it for sure and it seems to be much
older than that, so we don't have to worry and test for its
availability.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
@qmonnet
Copy link
Member Author

qmonnet commented Jun 16, 2023

/test

@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 Jun 16, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.13.5 Jun 16, 2023
@qmonnet qmonnet merged commit 48094e7 into cilium:main Jun 16, 2023
61 of 62 checks passed
@qmonnet qmonnet deleted the pr/fallthrough branch June 16, 2023 11:18
@qmonnet
Copy link
Member Author

qmonnet commented Jun 16, 2023

Repeating here the warning for backporters that only the first commit should be backported to 1.13.

@nbusseneau nbusseneau mentioned this pull request Jun 22, 2023
19 tasks
@nbusseneau nbusseneau added backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. and removed needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch labels Jun 22, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.13 in 1.13.5 Jun 22, 2023
@nbusseneau
Copy link
Member

Thanks for the warning @qmonnet!

@tklauser tklauser added backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. and removed backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. labels Jun 29, 2023
@gentoo-root gentoo-root moved this from Backport pending to v1.13 to Backport done to v1.13 in 1.13.5 Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. sig/loader Impacts the loading of BPF programs into the kernel.
Projects
No open projects
1.13.5
Backport done to v1.13
Development

Successfully merging this pull request may close these issues.

None yet

6 participants