Skip to content

Try harder to get a cgroup2 root mounting point#228

Merged
haesbaert merged 1 commit into
mainfrom
cgroup2
Sep 24, 2025
Merged

Try harder to get a cgroup2 root mounting point#228
haesbaert merged 1 commit into
mainfrom
cgroup2

Conversation

@haesbaert
Copy link
Copy Markdown
Collaborator

@haesbaert haesbaert commented Sep 24, 2025

his looks up the path for cgroup2, in case it's not in /sys/fs/cgroup, but more
importantly, it makes sure /sys/fs/cgroup is a cgroup2, and if not, it attempts
to mount a temporary cgroup2 for loading the DNS probes.

On some systems, cgroup2 is not mounted by default, even though the kernel
supports it.

For DNS and/or every future cgroup probe to function, we need to fetch the
cgroup mounting point pass it to bpf_probes__load(). After that the fd is not
really needed, we can close and also unmount the temporary cgroup2 mount we
might have created.

Idea from Nick.

@haesbaert haesbaert marked this pull request as ready for review September 24, 2025 09:32
@haesbaert haesbaert requested a review from a team as a code owner September 24, 2025 09:32
Comment thread bpf_queue.c Outdated
struct bpf_probes *p;
struct ring_buffer_opts ringbuf_opts;
int cgroup_fd, i, off, ringbuf_fd;
char *cgroup_unmount;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

weird spacing here

Comment thread bpf_queue.c Outdated
}

/*
* No cgroup2 mount found, try mountint it ourselves at
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* No cgroup2 mount found, try mountint it ourselves at
* No cgroup2 mount found, try to mount it ourselves at

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

zefixed

Comment thread bpf_queue.c Outdated
char template[] = "/tmp/quark_cgroup2_mount.XXXXXX";

if ((path = mkdtemp(template)) == NULL) {
qwarn("mktemp %s", template);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
qwarn("mktemp %s", template);
qwarn("mkdtemp %s", template);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ditto

Comment thread bpf_queue.c Outdated
goto fail;
}

*unmount_path = strdup(path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we check for strdup failures on line 585. should make them consistent. if it fails (and all other code miraculously works) we will fail to umount the custom cgroup2 mount.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I thought about it, it would basically just leave it dangling, while in practice that strdup will never fail, so I just ignored. I can add some print at least

Comment thread bpf_queue.c
Copy link
Copy Markdown
Contributor

@nicholasberlin nicholasberlin left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread bpf_queue.c
free(path);
if (fd != -1)
close(fd);
cgroup2_umount_tmp(umount_path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice.

This looks up the path for cgroup2, in case it's not in /sys/fs/cgroup, but more
importantly, it makes sure /sys/fs/cgroup is a cgroup2, and if not, it attempts
to mount a temporary cgroup2 for loading the DNS probes.

On some systems, cgroup2 is not mounted by default, even though the kernel
supports it.

For DNS and/or every future cgroup probe to function, we need to fetch the
cgroup mounting point pass it to bpf_probes__load(). After that the fd is not
really needed, we can close and also unmount the temporary cgroup2 mount we
might have created.

Idea from Nick.
@haesbaert haesbaert merged commit fe06504 into main Sep 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants