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.13] cocci: fix warnings related to const qualifiers and DROP_MISSED_TAIL_CALL #28279

Merged
merged 3 commits into from Sep 27, 2023

Conversation

giorio94
Copy link
Member

The coccicheck has been silently failing for a while [1], and the CI was recently fixed for the v1.13 branch bumping the related docker image in 100b580. Yet, the given check was not run in that PR (fixed by #28122, currently being backported), hence the warnings are only popping up in newer PRs. Hence, let's fix them.

[1]: 0dad157 ("cocci: Fix Python path for coccilib")

cocci: fix warnings related to const qualifiers and DROP_MISSED_TAIL_CALL 

@maintainer-s-little-helper maintainer-s-little-helper bot added backport/1.13 This PR represents a backport for Cilium 1.13.x of a PR that was merged to main. kind/backports This PR provides functionality previously merged into master. labels Sep 26, 2023
@giorio94 giorio94 mentioned this pull request Sep 26, 2023
10 tasks
@giorio94 giorio94 force-pushed the pr/giorio94/v1.13/coccicheck-fixes branch from d787723 to 65ecc5b Compare September 26, 2023 09:59
qmonnet and others added 3 commits September 26, 2023 15:18
[ upstream commit 89dd226 ]

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>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
The coccicheck has been silently failing for a while [1], and the CI was
recently fixed for the v1.13 branch bumping the related docker image in
100b580.

Hence, let's fix the const qualifier errors reported by coccinelle,
leveraging the spatch tool. In one case, the automatic fix failed with:

  EXN: Failure("bpf/lib/proxy.h: 155: try to delete an expanded token: struct") in bpf/lib/proxy.h

but after manually adding the const qualifier to CT_TUPLE_TYPE the error
was resolved.

[1]: 0dad157 ("cocci: Fix Python path for coccilib")

Related: 72fece4 ("bpf: Add some missing const qualifiers")
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
The coccicheck has been silently failing for a while [1], and the CI was
recently fixed for the v1.13 branch bumping the related docker image in
100b580.

The check currently complains about two missing DROP_MISSED_TAIL_CALL
occurrences in bpf/lib/nodeport.h, although we do actually return it
(but indirectly). Let's make it more explicit, so that the check no
longer emits a warning.

[1]: 0dad157 ("cocci: Fix Python path for coccilib")

Related: 279bbdc ("bpf: Return DROP_MISSED_TAIL_CALL when missing some tail calls")
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the pr/giorio94/v1.13/coccicheck-fixes branch from 65ecc5b to c26dda1 Compare September 26, 2023 13:19
@giorio94
Copy link
Member Author

/test-backport-1.13

@giorio94 giorio94 marked this pull request as ready for review September 26, 2023 14:12
@giorio94 giorio94 requested review from a team as code owners September 26, 2023 14:12
@giorio94
Copy link
Member Author

giorio94 commented Sep 26, 2023

/test-1.26-net-next

Failed due to Server returned HTTP response code: 401 for URL: https://api.github.com/repos/cilium/cilium/issues/28279

@giorio94 giorio94 changed the title cocci: fix warnings related to const qualifiers and DROP_MISSED_TAIL_CALL [v1.13] cocci: fix warnings related to const qualifiers and DROP_MISSED_TAIL_CALL Sep 26, 2023
Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

OK looks good, thank you!

@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 Sep 27, 2023
@lmb lmb merged commit b5b1a52 into v1.13 Sep 27, 2023
120 checks passed
@lmb lmb deleted the pr/giorio94/v1.13/coccicheck-fixes branch September 27, 2023 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.13 This PR represents a backport for Cilium 1.13.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

5 participants