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

btf: provide work around for missing BTF_KIND_ENUM64 support #1116

Closed
lmb opened this issue Aug 11, 2023 · 1 comment · Fixed by #1132
Closed

btf: provide work around for missing BTF_KIND_ENUM64 support #1116

lmb opened this issue Aug 11, 2023 · 1 comment · Fixed by #1132
Assignees
Labels
enhancement New feature or request

Comments

@lmb
Copy link
Collaborator

lmb commented Aug 11, 2023

pahole from v1.24 generates a new BTF_KIND_ENUM64. The library has support for this as well, and only encodes an enum64 if necessary to represent a type. This still causes a problem when compiling an old kernel with a new pahole, since TestRoundtripVmlinux then tries to load the enum64 into the kernel.

This shows that it would be nice^H^H^H it's necessary to have a general workaround for this. libbpf does the following when enum64 is not supported:

  • It clears the kind flag on BTF_KIND_ENUM and BTF_KIND_ENUM64. This is used to specify signedness and only cosmetic from what I can tell.
  • It replaces BTF_KIND_ENUM64 with a union.

Details are here: https://lwn.net/ml/bpf/20220603015937.1190992-1-yhs@fb.com/

@lmb lmb added the enhancement New feature or request label Aug 11, 2023
@lmb
Copy link
Collaborator Author

lmb commented Aug 14, 2023

I'm a bit fuzzy why libbpf replaces the enum with a union? It doesn't seem like it can preserve values, etc. that way?

Implementing this also requires at least v6.0 in CI, which is when BTF_KIND_ENUM64 appeared.

lmb added a commit to lmb/ebpf that referenced this issue Sep 13, 2023
Replace an ENUM64 with a 64-bit integer on kernels which don't
support the former. This behaviour is similar to libbpf, which replaces
the ENUM64 with a union instead.

Remove the old heuristic which encoded a 64-bit enum as a 32-bit enum
if none of the values exceeded math.MaxUint32. The heuristic has no
tests and doesn't take the signedness of the enum into account.

Fixes cilium#1116

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb self-assigned this Sep 13, 2023
@lmb lmb closed this as completed in #1132 Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant