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

Use BPF_FS_MAGIC from go sys lib instead of hardcode #8650

Merged
merged 1 commit into from
Mar 10, 2020

Conversation

odinuge
Copy link
Member

@odinuge odinuge commented Feb 28, 2020

This also avoids overflow during conversion. 0xCAFE4A11 is bigger than
the max of int32, so doing int32(uint32(0xCAFE4A11)) (will not compile
directly unless done over two lines) will result in -0x3501b5ef.

Due to some strange errors[0] in the types in "unix.Statfs_t" for 32 bits
systems, we have to explicitly convert to uint to support those (eg.
armv7). If we only need support for 64 bit systems, we can remove the
uint conversion as well.

[0]: For 32bits systems "fsdata.Type" should be uint32 instead of the
current int32, as it is in the linux kernel. This is due to the types in
glibc that the go types are generated from. For 64 bit systems the type
is correctly set to int64.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 28, 2020
@odinuge odinuge changed the title Use BPF_FS_MAGIC from go sys lib instead of hard code Use BPF_FS_MAGIC from go sys lib instead of hardcode Feb 28, 2020
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 28, 2020
@odinuge odinuge force-pushed the bpf-mount-check branch 2 times, most recently from fc8e319 to d03c4a3 Compare February 28, 2020 13:43
@odinuge
Copy link
Member Author

odinuge commented Feb 28, 2020

Ref. #8599

/cc @rifelpet @olemarkus

@k8s-ci-robot
Copy link
Contributor

@odinuge: GitHub didn't allow me to request PR reviews from the following users: olemarkus.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Ref. #8599

/cc @rifelpet @olemarkus

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@hakman
Copy link
Member

hakman commented Feb 28, 2020

I wanted to suggest using BPF_FS_MAGIC instead of the hardcoded value, but bumped into this on mac, same as you see in the failed CI run. The idea itself is good, converting to uint is a better solution:

nodeup/pkg/model/network.go:79:51: undefined: unix.BPF_FS_MAGIC

@odinuge
Copy link
Member Author

odinuge commented Feb 28, 2020

Hmm. So CI runs on darwin as well.. The code is compiled with GOOS=linux GOARCH=amd64, and it should never run on anything else than linux, so I think the tests should run with that too.

Since the code (nodeup) is linux only the best would be to add // +build linux to the files to avoid issues, that will also avoid issues where the binaries are compiled for darwin instead of linux, when the code in reality doesn't support darwin. This is used everywhere in k/k.

@odinuge odinuge force-pushed the bpf-mount-check branch 3 times, most recently from 5cf099c to aaaf2df Compare February 28, 2020 16:20
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 28, 2020
@odinuge odinuge force-pushed the bpf-mount-check branch 3 times, most recently from 2ec231a to c5c3619 Compare February 28, 2020 18:16
@hakman
Copy link
Member

hakman commented Mar 6, 2020

I totally agree that the conversion part should be fixed.
Using unix.BPF_FS_MAGIC instead of the hardcoded value requires a bit too many changes for the gain. It also comes with some downsides, like anyone using macOS will have to change various options in the editor and for new contributors may complicate things.

I would propose to only do the the conversion part and leave the hardcoded value for now.

0xCAFE4A11 is bigger than the max of int32, so doing int32(uint32(0xCAFE4A11))
(will not compile directly unless done over two lines) will result in 0x-3501b5ef.

For linux/amd64 "fsdata.Type" is an int64, while on darwin/amd64 it is
an uint32. This code is however not supposed to be compiled for darwin,
since it is linux spesific.

Due to some strange errors[0] in the types in "unix.Statfs_t" for 32 bits
systems on linux, we have to explicitly convert to uint to support those (eg.
armv7). If we only need support for 64 bit systems, we can remove the
uint conversion.

[0]: For 32bits systems "fsdata.Type" should be uint32 instead of the
current int32, as it is in the linux kernel. This is due to the types in
glibc that the go types are generated from. For 64 bit systems the type
is correctly set to int64.
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 7, 2020
@odinuge
Copy link
Member Author

odinuge commented Mar 7, 2020

I totally agree that the conversion part should be fixed.
Using unix.BPF_FS_MAGIC instead of the hardcoded value requires a bit too many changes for the gain. It also comes with some downsides, like anyone using macOS will have to change various options in the editor and for new contributors may complicate things.

I would propose to only do the the conversion part and leave the hardcoded value for now

I guess that is ok. Updated the PR now 😄

The statfs.Type type on darwin is a uint32, while it is int64 on linux/amd64 and int32 (but in the kernel it is a uint32) in linux/arm/v7, so the types doesn't make that much sense.

Making this "linux-only-code" mac and windows "firendly" may cause some gains, but I also think it can lead to some strange bugs when developers on darwin/windows compile the code for their platform, when it wouldn't properly run there anyways. To avoid regression i do think this deserve some testing, and without fixing the compilation issues, that wouln't be possible (since bpf is linux only).

@hakman
Copy link
Member

hakman commented Mar 7, 2020

Thanks :).
I hope that there isn't anyone trying to run nodeup on mac or windows. BPF would be the least of their problem.
Testing is tricky anyway as it depends on the system that would runt unix.Statfs. It may be a good idea to at least extract the comparison to a separate function and add some tests for it.
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 7, 2020
@rifelpet
Copy link
Member

looks good, thanks!
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: odinuge, rifelpet

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 10, 2020
@k8s-ci-robot k8s-ci-robot merged commit 92ca7bf into kubernetes:master Mar 10, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants