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

Share bpf maps internally and remove pinning / bpffs requirement #1251

Merged
merged 8 commits into from
Oct 15, 2024

Conversation

rafaelroquetto
Copy link
Contributor

@rafaelroquetto rafaelroquetto commented Oct 11, 2024

Leverage the fact that pinning/PinType is an uint and introduce a new PinType called PinInternal, which shares the corresponding maps inside the same userspace process (i.e. all of the maps sharing the same name refer to the same ebpf map object, but no actual bpffs pinning is given).

All bpf filesystem mounting code has been removed.

Resolves #1249

@rafaelroquetto rafaelroquetto added the do-not-merge WIP or something that musn't be merged label Oct 11, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 63.88889% with 13 lines in your changes missing coverage. Please review.

Project coverage is 81.82%. Comparing base (ac3b137) to head (df95555).

Files with missing lines Patch % Lines
pkg/internal/ebpf/tracer_linux.go 61.76% 8 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1251      +/-   ##
==========================================
+ Coverage   81.78%   81.82%   +0.03%     
==========================================
  Files         135      135              
  Lines       11416    11384      -32     
==========================================
- Hits         9337     9315      -22     
+ Misses       1544     1543       -1     
+ Partials      535      526       -9     
Flag Coverage Δ
integration-test 60.54% <63.88%> (-0.15%) ⬇️
k8s-integration-test 59.21% <63.88%> (+0.07%) ⬆️
oats-test 36.46% <63.88%> (-0.15%) ⬇️
unittests 53.60% <0.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rafaelroquetto rafaelroquetto force-pushed the no_more_pinning branch 5 times, most recently from 745afd8 to 4cf890f Compare October 11, 2024 21:57
@@ -137,6 +137,9 @@ enum libbpf_pin_type {
LIBBPF_PIN_NONE,
/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */
LIBBPF_PIN_BY_NAME,

// XXX custom
LIBBPF_PIN_INTERNAL = 100
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have decided to do this mainly so that we don't introduce a header that will need to be included everywhere, containing a single constant define.

I reckon this should be refactored if or when we decide to resplit the tracers.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if i understand what are you saying here. What do you mean resplit the tracers?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add this explanation to a comment on LIBBPF_PIN_INTERNAL so we don't forget the context it in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to move this into a header of our own, since we might copy - paste a new version of libbpf headers here and cause an compile error. To the person that does this it may not be obvious what caused the build break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marctc I was under the impression everything was grouped together so that we could share the maps, but perhaps I am missing a part of the history. I intend to split the tc programs off generic_tracer to allow them to be loaded separately - it will be possible to do the same now for other programs if we conclude it's desirable.

@grcevski @mariomac I will move this constant elsewhere to avoid confusion.

@rafaelroquetto rafaelroquetto changed the title WIP: No more pinning WIP: Share bpf maps internally and remove pinning / bpffs requirement Oct 11, 2024
@rafaelroquetto rafaelroquetto added the documentation Improvements or additions to documentation label Oct 11, 2024
internalMaps[k] = internalMap
}

collOpts.MapReplacements[k] = internalMap
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cilium/ebpf will clone internalMap when processing MapReplacements, meaning both clones can be safely closed irrespective of each other (clones still share the underlying map object though, it's just the underlying file descriptor that is dup'd)

@@ -45,31 +42,6 @@ spec:
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
{{- if not (.Values.privileged) }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be prudent to get a second pair of eyes on these changes

Copy link
Contributor

Choose a reason for hiding this comment

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

We probably could do it in a separate PR IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marctc ok, I will revert this part

@rafaelroquetto rafaelroquetto changed the title WIP: Share bpf maps internally and remove pinning / bpffs requirement Share bpf maps internally and remove pinning / bpffs requirement Oct 12, 2024
@rafaelroquetto rafaelroquetto removed the do-not-merge WIP or something that musn't be merged label Oct 12, 2024
@rafaelroquetto rafaelroquetto marked this pull request as ready for review October 12, 2024 02:13
Copy link
Contributor

@marctc marctc left a comment

Choose a reason for hiding this comment

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

LGTM amazing find @rafaelroquetto. Did you notice if this impacted the peformance? Personally i'd had removed the unprivileged stuff in a different PR (also to document how to run Beyla without privileges), but overall looks good!

Copy link
Contributor

@mariomac mariomac left a comment

Choose a reason for hiding this comment

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

Amazing! I love removing code :)

As Marc says, I would let the changes in the helm chart for another PR, so we can focus on merging this feature and later test the unconfinement requirements.

@@ -137,6 +137,9 @@ enum libbpf_pin_type {
LIBBPF_PIN_NONE,
/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */
LIBBPF_PIN_BY_NAME,

// XXX custom
LIBBPF_PIN_INTERNAL = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add this explanation to a comment on LIBBPF_PIN_INTERNAL so we don't forget the context it in the future

@@ -25,9 +25,6 @@ spec:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if not (.Values.privileged) }}
container.apparmor.security.beta.kubernetes.io/beyla: "unconfined"
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we set this when the container is NOT privileged, so we can add the required capabilities. I don't remember if this was required only for SYS_ADMIN capability, or setting the rest of capabilities require it too.

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I remember we had to use this "unconfined" because App Armour prevents us from mounting file systems or writing to /sys/fs. So if we don't have to mount anymore we don't need to remove this restriction.

However we shouldn't remove this in this PR. It should be a follow-up and we should probably confirm this is works now with real k8s install, since we have no tests for this.

Copy link
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

LGTM! Great work, minor comments :).

@@ -137,6 +137,9 @@ enum libbpf_pin_type {
LIBBPF_PIN_NONE,
/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */
LIBBPF_PIN_BY_NAME,

// XXX custom
LIBBPF_PIN_INTERNAL = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to move this into a header of our own, since we might copy - paste a new version of libbpf headers here and cause an compile error. To the person that does this it may not be obvious what caused the build break.

@@ -25,9 +25,6 @@ spec:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if not (.Values.privileged) }}
container.apparmor.security.beta.kubernetes.io/beyla: "unconfined"
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I remember we had to use this "unconfined" because App Armour prevents us from mounting file systems or writing to /sys/fs. So if we don't have to mount anymore we don't need to remove this restriction.

However we shouldn't remove this in this PR. It should be a follow-up and we should probably confirm this is works now with real k8s install, since we have no tests for this.

@rafaelroquetto
Copy link
Contributor Author

@marctc Thanks. I will remove the changes to the helm chart, but I intend to keep the documentation changes (i.e. removing the mentions to the ebpf filesystem since they are no longer relevant). I will take care of a "how to run beyla unprivileged" in a separate PR, as this will mostly boil down to capabilities and these changes are "backwards compatible".

@rafaelroquetto
Copy link
Contributor Author

@grcevski @marctc @mariomac I have removed the helm charts changed, but kept the documentation ones. Let me know if you'd like me to revert the doc changes as well.

@rafaelroquetto rafaelroquetto merged commit c9d2647 into main Oct 15, 2024
14 checks passed
@rafaelroquetto rafaelroquetto deleted the no_more_pinning branch October 15, 2024 16:51
mattdurham pushed a commit to mattdurham/beyla that referenced this pull request Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove pinning in ebpf
5 participants