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
More coccinelle fixes #24606
More coccinelle fixes #24606
Conversation
CI failing because some of those |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Good new,/Good news,/
in the first commit message, s/"__attribute__((unused))/"__attribute__((unused))"/
in the second commit message, other than that and the comment about the make
variable that LGTM.
GCC and clang support label attributes, such as __attribute__((unused)) to indicate that under certain configurations, (goto) labels will not be used at compilation time. We've been using this to silence warnings about unused labels. However, GCC's "Attribute Syntax" documentation [0] states that: GNU C++ only permits attributes on labels if the attribute specifier is immediately followed by a semicolon (i.e., the label applies to an empty statement). If the semicolon is missing, C++ label attributes are ambiguous, as it is permissible for a declaration, which could begin with an attribute list, to be labelled in C++. We're using clang to compile the BPF programs and I couldn't find an equivalent statement, but it should likely be the same. Let's add the semi-colons. The real motivation for this clean-up is to coccinelle parse the files properly and to better apply checks. We've seen it struggle when the semi-colons are missing. [0] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Label-Attributes-2 Signed-off-by: Quentin Monnet <quentin@isovalent.com>
dbbbff7
to
92b0bb6
Compare
So I added a new commit at the beginning, to fix a parsing issue for coccinelle that was messing up with the reports for the I also switched to |
All missing qualifiers detected by coccinelle. The missing "const" on the "mac" argument in icmp6.h was found by running the latest coccinelle (not 1.1.1 as in CI and Docker image) on the bpf code base. The missing qualifier in proxy.h was not detected so far because coccinelle stumbles on parsing macro CTX_REDIRECT_FN in proxy.h, in particular because of the CT_TUPLE_TYPE argument where we pass a two-word long type (struct ipv(4|)_ct_tuple). The spatch tool would fail with: EXN: Failure("bpf/lib/proxy.h: 164: try to delete an expanded token: struct") in bpf/lib/proxy.h and then would fail to detect the missing "const". By commenting out temporarily the calls to CTX_REDIRECT_FN we make it work again. Good news, by adding the missing "const" to "CT_TUPLE_TYPE", we're also fixing the parsing for coccinelle, so future mistakes in the file should be reported as expected. Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Trying to create a new coccinelle check, we realised that some patterns that we expected to match in the bpf/ were in fact never caught. Here is a minimal reproducer. foo.cocci: @@ @@ ( - foo = bar; + foo = baz; ) foo.c (not working): int main (void) { int foo, bar, baz = 0, coccibreaker __maybe_unused; foo = bar; return foo; } Invocation: $ docker run --rm --user 1000 \ --workdir /workspace -v `pwd`:/workspace -it docker.io/cilium/coccicheck:2.4@sha256:24abe3fbb8e829fa41a68a3b76cb4df84fd5a87a7d1d6254c1c1fe5effb5bd1b \ spatch --include-headers --very-quiet --in-place \ --sp-file contrib/coccinelle/foo.cocci bpf/foo.c This does not catch the "foo = bar;" statement in the C file. However, the pattern is caught in the following file instead: foo.c (working): int main (void) { int foo, bar, baz = 0; int coccifine __maybe_unused; foo = bar; return foo; } The __maybe_unused attribute seems to prevent spatch to parse correctly the function. This happens independently of whether __maybe_unused is defined in the C code. The behaviour remains the same if we replace __maybe_unused with some other random word (although replacing it with "__attribute__((unused))" works as expected). Running from coccinelle's "master" branch works fine, and when running spatch locally (no Docker image) we can also observe the following warnings: warning: Can't find macro file: /usr/local/bin/lib/coccinelle/standard.h warning: Can't find default iso file: /usr/local/bin/lib/coccinelle/standard.iso This error was fixed with commit coccinelle/coccinelle@540888ff426e ("Fix 263: wrong default path for COCCINELLE_HOME") [0], which is not part of a release yet. Until it is, we still want to have our code covered by coccinelle. As a workaround to the issue, we could pass manually the paths to the files containing the definitions for the isomorphisms and built-in macros for coccinelle, with spatch options "--macro-file-builtin" and "--iso-file". Even simpler, we can set $(COCCINELLE_HOME) to the correct path so that both files are found. No camels were harmed during this investigation. [0] https://gitlab.inria.fr/coccinelle/coccinelle/-/commit/540888ff426e Signed-off-by: Quentin Monnet <quentin@isovalent.com>
92b0bb6
to
a050bb2
Compare
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the very clear commit messages!
In terms of tests, I don't think we need anything other than coccicheck and build datapath to pass. The first should cover the coccicheck changes and the second should be enough to cover the small changes to the C code. Marking ready to merge. |
There's an outstanding change request by @kaworu. Please either dismiss it, or give him the time to resolve it. Please also triage the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @qmonnet! TIL about semi-colons after __maybe_unused
for goto labels, but that make sense.
/test-runtime |
Review is in and I filed #24633 for the failed test, which looks like a new flake. |
Build finished. |
runtime test succeeded, but instead of GitHub picking up the result, we have ciliumbot commenting 🤔 Anyway, this time we should be good to go. |
Please look at commit descriptions for details.