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

bugtool: get bpffs mountpoint from /proc/mounts #13342

Merged
merged 1 commit into from
Oct 1, 2020
Merged

bugtool: get bpffs mountpoint from /proc/mounts #13342

merged 1 commit into from
Oct 1, 2020

Conversation

jibi
Copy link
Member

@jibi jibi commented Sep 30, 2020

Rather then hardcoding the /sys/fs/bpf value in bugtool, parse
/proc/mounts to determine the correct mountpoint for the BPF filesystem.

Fixes: #13218

Signed-off-by: Gilberto Bertin gilberto@isovalent.com

@jibi jibi requested a review from a team as a code owner September 30, 2020 08:49
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Sep 30, 2020
@qmonnet qmonnet self-requested a review September 30, 2020 08:51
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.

Looks great, thank you!

This won't be “tested” by the CI, I suppose you validated the change locally to make sure we still dump the maps as intended?

bugtool/cmd/configuration.go Outdated Show resolved Hide resolved
@qmonnet qmonnet added area/bugtool Impacts gathering of data for debugging purposes. area/CI Continuous Integration testing issue or flake ci/flake This is a known failure that occurs in the tree. Please investigate me! release-note/ci This PR makes changes to the CI. labels Sep 30, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Sep 30, 2020
@qmonnet
Copy link
Member

qmonnet commented Sep 30, 2020

I'm just thinking: Although unlikely, we could have several bpffs mounted at different points. Would it be worth to try and list the maps under each of them in that case?

@qmonnet qmonnet added the sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. label Sep 30, 2020
@qmonnet qmonnet requested a review from a team September 30, 2020 09:06
@jibi
Copy link
Member Author

jibi commented Sep 30, 2020

Looks great, thank you!

This won't be “tested” by the CI, I suppose you validated the change locally to make sure we still dump the maps as intended?

Yes, I tested it both manually in the dev VMs as well as by crashing some e2e tests and looking at its dump in /tmp

@jibi
Copy link
Member Author

jibi commented Sep 30, 2020

I'm just thinking: Although unlikely, we could have several bpffs mounted at different points. Would it be worth to try and list the maps under each of them in that case?

I wasn't aware of this possibility but yes, I agree that we should try list maps under each of the mounted bpffs 👍

@qmonnet
Copy link
Member

qmonnet commented Sep 30, 2020

I wasn't aware of this possibility but yes, I agree that we should try list maps under each of the mounted bpffs +1

You can mount multiple ones, but I don't think this is something Cilium would ever do. Just thinking that if for any reason users have mounted another bpffs, we would risk missing the correct one when dumping the maps.

@jibi jibi marked this pull request as draft September 30, 2020 09:58
Copy link
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

We already have a separate package for listing mounts (pkg/mountinfo), I think it would be better to use it here.

@@ -39,6 +41,27 @@ func setupDefaultConfig(path string, k8sPods []string, confDir, cmdDir string) (
return &c, save(&c, path)
}

func bpffsMountpoint() []string {
Copy link
Member

Choose a reason for hiding this comment

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

We already have a separate module for listing mounts from /proc/self/mountinfo (which contains more details than /proc/mounts):

https://github.com/cilium/cilium/blob/master/pkg/mountinfo/mountinfo.go#L125-L135

The example of using it, also for checking BPFFS mount, is here:

https://github.com/cilium/cilium/blob/master/pkg/bpf/bpffs_linux.go#L69-L81

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @mrostecki, I'll take a look at that package now

@vadorovsky
Copy link
Member

@qmonnet @jibi

You can mount multiple ones, but I don't think this is something Cilium would ever do. Just thinking that if for any reason users have mounted another bpffs, we would risk missing the correct one when dumping the maps.

In cilium-agent we even return an explicit error if there are multiple BPFFS mounts:

https://github.com/cilium/cilium/blob/master/pkg/bpf/bpffs_linux.go#L278-L284

@jibi
Copy link
Member Author

jibi commented Sep 30, 2020

@qmonnet @jibi

You can mount multiple ones, but I don't think this is something Cilium would ever do. Just thinking that if for any reason users have mounted another bpffs, we would risk missing the correct one when dumping the maps.

In cilium-agent we even return an explicit error if there are multiple BPFFS mounts:

https://github.com/cilium/cilium/blob/master/pkg/bpf/bpffs_linux.go#L278-L284

It looks like we have a case of multiple bpf fs even in the dev VM:

vagrant@k8s1:/sys/fs/bpf$ cat /proc/mounts | grep bpf
bpffs /sys/fs/bpf bpf rw,relatime 0 0
bpffs /sys/fs/bpf/xdp bpf rw,relatime 0 0
bpffs /sys/fs/bpf/ip bpf rw,relatime 0 0
bpffs /sys/fs/bpf/sk bpf rw,relatime 0 0
bpffs /sys/fs/bpf/sa bpf rw,relatime 0 0

and I'm slightly confused as tc (which is the only one we are interested in) is just a subdirectory of the main mountpoint (/sys/fs/bpf) while xdp, ip, sk and sa are all additional bpf filesystems 🤔

edit:
I'm getting multiple mountpoints also with the mountinfo module:

vagrant@k8s1:~/go/src/github.com/cilium/cilium/bugtool$ sudo ./cilium-bugtool
mountpoints: [/sys/fs/bpf /sys/fs/bpf/xdp /sys/fs/bpf/ip /sys/fs/bpf/sk /sys/fs/bpf/sa]
[..]

@qmonnet
Copy link
Member

qmonnet commented Sep 30, 2020

iproute2 considers tc as a reference subdirectory and attempts to do symlinks for the other ones (see related code), but seems to fall back on bind mounts when it fails with something different than EEXIST or EPERM. Not sure what's happening in the dev VMs.

Hmm I wonder why this does not seem to be picked up by the check in bpffs_linux.go 🤔

@vadorovsky
Copy link
Member

vadorovsky commented Sep 30, 2020

@jibi /sys/fs/bpf/xdp, /sys/fs/bpf/ip, /sys/fs/bpf/sk and /sys/fs/bpf/sa are sub mounts of /sys/fs/bpf (it means /sys/fs/bpf is their parent mount). So it's fine.

We want to avoid multiple BPFFS mounts which have / as their root. As we do it here: https://github.com/cilium/cilium/blob/master/pkg/bpf/bpffs_linux.go#L162

@vadorovsky
Copy link
Member

@qmonnet The last link I pasted is the reason why cilium-agent doesn't fail because of `/sys/fs/bpf´ subdirectories. ;)

@jibi
Copy link
Member Author

jibi commented Sep 30, 2020

Thank you both @qmonnet and @mrostecki, I just learnt a bunch of new things :)

In this case I think i will:

  • assume there's only a single bpffs mounted
  • consider it to be the first one returned by mountinfo.GetMountInfo() which has both the bpf type and and the / root

@jibi jibi marked this pull request as ready for review September 30, 2020 12:17
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.

Looks good to me, please just add a comment so we can remember the logics here.

bugtool/cmd/configuration.go Show resolved Hide resolved
Rather then hardcoding the /sys/fs/bpf value in bugtool, use the
`mountinfo` package (which exposes the information in /proc/self/mounts)
to determine the correct mountpoint for the BPF filesystem.

Fixes: #13218

Signed-off-by: Gilberto Bertin <gilberto@isovalent.com>
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.

Looks good to me, thanks!

@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.8.4 Sep 30, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.7.10 Sep 30, 2020
Copy link
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

@pchaigno pchaigno added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Sep 30, 2020
@joestringer joestringer removed this from Needs backport from master in 1.8.4 Sep 30, 2020
@joestringer joestringer removed this from Needs backport from master in 1.7.10 Sep 30, 2020
@joestringer joestringer added this to Needs backport from master in 1.7.11 Sep 30, 2020
@joestringer joestringer added this to Needs backport from master in 1.8.5 Sep 30, 2020
@borkmann borkmann merged commit 57d3473 into cilium:master Oct 1, 2020
@jibi jibi deleted the pr/bugtool-get-bpffs-mountpoint-from-proc-mounts branch October 1, 2020 11:21
@tklauser tklauser moved this from Needs backport from master to Backport done to v1.8 in 1.8.5 Oct 13, 2020
@tklauser tklauser moved this from Needs backport from master to Backport done to v1.7 in 1.7.11 Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bugtool Impacts gathering of data for debugging purposes. area/CI Continuous Integration testing issue or flake ci/flake This is a known failure that occurs in the tree. Please investigate me! ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
No open projects
1.7.11
Backport done to v1.7
1.8.5
Backport done to v1.8
Development

Successfully merging this pull request may close these issues.

bugtool: Incorrect BPF filesystem path
7 participants