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

Introduce and use vmlinux crate #739

Merged
merged 5 commits into from
Mar 25, 2024
Merged

Introduce and use vmlinux crate #739

merged 5 commits into from
Mar 25, 2024

Conversation

danielocfb
Copy link
Collaborator

Please see individual commits for descriptions.

d-e-s-o added 3 commits March 21, 2024 14:47
This change converts all examples over to using the vmlinux crate for
access to the vmlinux.h header file.

Signed-off-by: Daniel Müller <deso@posteo.net>
Remove the examples/vmlinux/ folder and all the vendored vmlinux.h
header files, now that they are no longer used.

Signed-off-by: Daniel Müller <deso@posteo.net>
This change migrates the integration tests over to using the vmlinux
crate for their vmlinux.h needs. It then also removes the one remaining
vendored vmlinux.h copy from the repository.

Signed-off-by: Daniel Müller <deso@posteo.net>
@danielocfb danielocfb requested a review from anakryiko March 21, 2024 22:17
Copy link
Member

@anakryiko anakryiko left a comment

Choose a reason for hiding this comment

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

LGTM. Do you plan to convert libbpf-bootstrap rust examples to this as well?

use std::path::Path;
use std::path::PathBuf;

// TODO: Ideally we'd deduplicate contents at this level (as well; not just on
Copy link
Member

Choose a reason for hiding this comment

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

those are also huge text files which would compress very nicely, but I assume it's impossible in const context?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Likely not in a const context, yeah. We could probably have a function based interface if need be and load and cache stuff on demand. I mostly got nerd-sniped here and wanted to make it work as I had originally envisioned...

The other avenue would to exclude unnecessary headers based on features. Either way, it's probably not urgent unless/until we use this functionality in anything but example & test code.

@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Mar 22, 2024

LGTM. Do you plan to convert libbpf-bootstrap rust examples to this as well?

Not immediately, but if we decide to publish this crate eventually then yes, happy to adjust the code there.

d-e-s-o added 2 commits March 25, 2024 11:27
Bump the minimum supported Rust version to 1.71. This version will be
required with subsequent changes, as it provides a const version of
ptr::read().

Signed-off-by: Daniel Müller <deso@posteo.net>
Our handling of the vmlinux.h header file is super painful. That has
many reasons, including, but not limited to:
- nothing feels self-contained, as everything is relying on some
  abstruse C header file somewhere
- we kind of sort of wanted to avoid shipping it so far and so every
  component started vendoring their own copy
  - that makes maintenance a nightmare
  - some components do so taking the current target architecture into
    account, others not; limiting possible compilation targets
  - because unit tests are part of the containing library, which *is*
    shipped, we are basically prevented from granting unit tests access
    to vmlinux.h
- just finding the right path to the file is cumbersome and the logic
  for doing so gets replicated all over the place

This change introduces a crate that tries to solve most (all?) of these
problems. It vendors vmlinux.h for various architectures and provides
file system as well as Rust-level access to contents. It also takes care
of honoring the current target architecture in doing so.
Long term we probably should consider publishing it, which would enable
usage from other repositories such as libbpf-bootstrap. We'd likely need
to version it in accordance with the kernel version that the headers
correspond to. For now, it's just a workspace member and will only be
used as dev-dependency.

Signed-off-by: Daniel Müller <deso@posteo.net>
@danielocfb danielocfb merged commit 44292ae into libbpf:master Mar 25, 2024
12 checks passed
@danielocfb danielocfb deleted the topic/vmlinux branch March 25, 2024 18:37
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.

None yet

3 participants