Skip to content

constchecker: check constants between Go/BPF#12436

Closed
kkourt wants to merge 1 commit intocilium:masterfrom
kkourt:valuetester
Closed

constchecker: check constants between Go/BPF#12436
kkourt wants to merge 1 commit intocilium:masterfrom
kkourt:valuetester

Conversation

@kkourt
Copy link
Copy Markdown
Contributor

@kkourt kkourt commented Jul 6, 2020

In the context of #12415, we wanted to add a test to compare values in
Go with ones in BPF. The first approach used cgo, which is not ideal.

This add some initial code to alignchecker that allows to check values
between BPF and go by reading the ELF .rodata section.

If this makes sense, it can be used for to add testing for #12415.

Signed-off-by: Kornilios Kourtis kornilios@isovalent.com

@kkourt kkourt added the release-note/misc This PR makes changes that have no direct user impact. label Jul 6, 2020
@kkourt kkourt requested review from a team as code owners July 6, 2020 15:49
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 6, 2020

Coverage Status

Coverage decreased (-0.06%) to 36.934% when pulling bdad446 on kkourt:valuetester into c4b2c1e on cilium:master.

Copy link
Copy Markdown
Member

@christarazi christarazi left a comment

Choose a reason for hiding this comment

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

Nice! Overall looks good, just have a few comments below.

Comment thread pkg/alignchecker/alignchecker.go Outdated
Comment thread pkg/alignchecker/alignchecker.go Outdated
Comment thread pkg/alignchecker/alignchecker.go Outdated
Comment thread pkg/alignchecker/alignchecker_test.go Outdated
@christarazi
Copy link
Copy Markdown
Member

test-me-please

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 7, 2020

test-me-please

Comment thread pkg/alignchecker/alignchecker_test.go Outdated
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 7, 2020

test-me-please

Copy link
Copy Markdown
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Nice work.

Some small comments inline, nothing major. Probably not worth to respin the PR if these are the only requested changes.

Comment thread pkg/alignchecker/alignchecker.go Outdated
Comment thread pkg/alignchecker/alignchecker.go Outdated
Comment thread pkg/alignchecker/alignchecker.go Outdated
@maintainer-s-little-helper
Copy link
Copy Markdown

Commit 6c8907e8b195748c2a23e3a7b519db9badf95e71 does not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

1 similar comment
@maintainer-s-little-helper
Copy link
Copy Markdown

Commit 6c8907e8b195748c2a23e3a7b519db9badf95e71 does not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@maintainer-s-little-helper maintainer-s-little-helper Bot added the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Jul 7, 2020
@maintainer-s-little-helper
Copy link
Copy Markdown

Commits 6c8907e8b195748c2a23e3a7b519db9badf95e71, ee15973bc54aafe669e332469aae4ee2f8f7265a do not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

1 similar comment
@maintainer-s-little-helper
Copy link
Copy Markdown

Commits 6c8907e8b195748c2a23e3a7b519db9badf95e71, ee15973bc54aafe669e332469aae4ee2f8f7265a do not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@maintainer-s-little-helper maintainer-s-little-helper Bot removed the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Jul 7, 2020
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 7, 2020

test-me-please

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 7, 2020

test-me-please

@kkourt kkourt changed the title alignchecker: add code to also check values alignchecker: add code to also check constants Jul 7, 2020
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 7, 2020

test-me-please

@kkourt kkourt requested a review from a team July 8, 2020 22:11
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 8, 2020

Latest version adds a check for the loadbalancer, a minor checkpatch fix, and removes the object file for the constchecker self-test.

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 9, 2020

@qmonnet I added a small checkpatch change here so that it does not complain about using inline comments for SPDX, since using SPDX seems to be the preferred way (#12436 (comment)).

I later noticed that you had sent a (more complete) patch upstream for this issue (https://lore.kernel.org/patchwork/patch/1265784/#1461076).

Not sure what the proper thing to do here, but it's a bit confusing to get conflicting checkpatch errors, so maybe we should carry the SPDX change locally regardless of whether it's upstreamed?

@qmonnet
Copy link
Copy Markdown
Member

qmonnet commented Jul 9, 2020

Not sure what the proper thing to do here, but it's a bit confusing to get conflicting checkpatch errors, so maybe we should carry the SPDX change locally regardless of whether it's upstreamed?

(Thanks for asking!) I agree this is confusing. I was hoping the patch would be merged upstream, but it didn't get a warm reception and now this seems unlikely to happen. We discussed that during a datapath meeting (last week maybe), and we agreed on the following: There is some follow-up I intend to do on checkpatch, to package it as a Docker image instead of keeping it in the Cilium repo (on Ilya's suggestion). Once we have that, we can apply local patches (patch -p1 < ...) when building the image: this way we keep the mainline version from Linux repo, making it easy to update, but apply the desired local changes before using it.

In the meantime, I would as well keep the current version untouched. Unless you feel this is too much confusing and really prefer to patch, in which case we can start changing checkpatch.pl now and then report the changes later when packaging it as an image.

I opened #12467 about packaging checkpatch.

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 9, 2020

In the meantime, I would as well keep the current version untouched. Unless you feel this is too much confusing and really prefer to patch, in which case we can start changing checkpatch.pl now and then report the changes later when packaging it as an image.

As long as people don't mind the red checkmark in BPF checks, it's fine by me :)
I will remove the patch from this PR.

As a side note, there is also:

+++ b/contrib/checkpatch/checkpatch.sh
@@ -23,6 +23,8 @@ ignore_list=(
     LONG_LINE_COMMENT
     # Ignore tolerance that comes by default
     C99_COMMENT_TOLERANCE
+    # We do not have a MAINTAINERS file, so we can ignore this
+    FILE_PATH_CHANGES
 )

This seems like something that can be applied directly (or maybe not?)

@qmonnet
Copy link
Copy Markdown
Member

qmonnet commented Jul 9, 2020

We could either ignore the FILE_PATH_CHANGES reports as you suggest or patch it in the future to say CODEOWNERS (that we do have) instead of MAINTAINERS. Either is fine by me.

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 9, 2020

test-me-please

Comment thread test/bpf/check-consts.sh Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there are Makefle environment variables set for go and test. I know this is a script but I'm wondering if it would make sense to keep them consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed, they seem to be. My original thought was to add this test in the Makefile (defining the CILIUM_CONSTCHECKER_BPF_OBJ env variable would be enough), but this felt too intrusive/complex, so I decided to put it on a separate script. Since the const are fairly simple and have no other dependencies except for cosntchecker, I would think that running them as they are would be OK.

@maintainer-s-little-helper maintainer-s-little-helper Bot requested a review from aanm July 9, 2020 13:37
@aanm aanm requested a review from joestringer July 9, 2020 13:37
@aanm aanm added the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Jul 9, 2020
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 9, 2020

rebased

@kkourt kkourt removed the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Jul 9, 2020
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 9, 2020

test-me-please

Copy link
Copy Markdown
Member

@nebril nebril left a comment

Choose a reason for hiding this comment

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

Test bits look good to me.

Copy link
Copy Markdown
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

This seems like a reasonable way to perform such checks. At a high level, I wonder whether we would benefit from moving more towards a model where the Golang implementation generates all of these constants from the Golang definition into a header file instead, then the BPF code simply includes those headers. That way, the constants would be ensured to be the same without having to perform additional checks afterwards.

That said, modulo the minor nits below I'm fine with the current approach.

Comment thread pkg/loadbalancer/loadbalancer.go Outdated
Comment thread pkg/loadbalancer/loadbalancer_test.go Outdated
Comment thread test/bpf/check-consts.sh Outdated
The goal is to ensure that common constants between Go and BPF match.

This commit adds:
 - constchecker, which checks values between BPF and Go by reading the
 ELF .rodata section of a BPF object file.
 - two tests, one for constchecker itself with dummy constants and one
 for loadbalancer.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 13, 2020

test-me-please

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 14, 2020

This seems like a reasonable way to perform such checks. At a high level, I wonder whether we would benefit from moving more towards a model where the Golang implementation generates all of these constants from the Golang definition into a header file instead, then the BPF code simply includes those headers. That way, the constants would be ensured to be the same without having to perform additional checks afterwards.

I do think that the approach in this PR is problematic in the sense that it's too much work for a developer to add new checks. They would have to edit two (go test, bpf file with constants) or more (test script) files, and probably would end up just adding a comment instead. And, if people are not going to use it, I'm not sure if it's worth merging.

Generating constants from Go would be better in that sense, but I'm also not sure if it's worth doing it, since it adds some level of complexity, and I do like the fact that the bpf code is self-contained.

Also, I'm not sure if constants checks solve a real problem, i.e., having a chance to catch actual bugs. Maybe a comment in Go and BPF side that these constants should match is the best solution at this point.

@qmonnet
Copy link
Copy Markdown
Member

qmonnet commented Jul 14, 2020

test-me-please

@qmonnet
Copy link
Copy Markdown
Member

qmonnet commented Jul 14, 2020

retest-net-next

@joestringer
Copy link
Copy Markdown
Member

Generating constants from Go would be better in that sense, but I'm also not sure if it's worth doing it, since it adds some level of complexity, and I do like the fact that the bpf code is self-contained.

In practice we're already doing this via the headerfiles for ep_config.h, netdev_config and node_config.h so it's very much in line with our existing templating approaches.

Also, I'm not sure if constants checks solve a real problem, i.e., having a chance to catch actual bugs. Maybe a comment in Go and BPF side that these constants should match is the best solution at this point.

It's always possible, but given that both (Go/C) constants are usually introduced at the same time it's typically fairly easy to catch mistakes. I can't specifically recall hitting an issue like this in the past with Cilium.

Copy link
Copy Markdown
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

I'm fine with the changes. We still have a partially-finished discussion above about the overall approach which could end in either deciding to merge this PR or not, so my approval is subject to that. I appreciate the effort looking into this either way :-)

@kkourt
Copy link
Copy Markdown
Contributor Author

kkourt commented Jul 20, 2020

Unless someone suggests differently, I would opt to drop this one. (I know it's my PR and I'm the one supposed to argue for it, but as I said I think it's too much hassle for people to use it.) We can always resurrect it if we think it makes sense.

@kkourt kkourt closed this Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc This PR makes changes that have no direct user impact.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants