Skip to content

Commit

Permalink
PinType: change from int to uint32
Browse files Browse the repository at this point in the history
For supporting custom pinning behaviours in Cilium, we're looking to extend
the MapSpec.Pinning flag and treat it as a bitfield internally. libbpf and
ebpf-go currently only support LIBBPF_PIN_BY_NAME and ebpf.PinByName
respectively, which has a value of 1, so it's still up in the air whether or
not this could officially evolve into a bitfield in the future, since doing
so can be done while maintaining backwards compatibility.

In Cilium's case, we reserve the lower 4 bits for the upstream enum values and
mask out the remaining bits before calling NewCollection. The upper bits are
used for specifying flags to request specific behaviours, e.g. to ignore a
pinned map during loading, and explicitly overwriting its pin at a later stage,
when the entrypoint program(s) were successfully attached. Useful for working
with prog arrays that need to remain pinned.

We want to keep using the existing ebpf.PinType type for this, but defining
masks using a signed type needs to be done with care, so ideally PinType would
be unsigned.

A few more data points on why this change is warranted:

- bpf_elf_map always had 'unsigned int' fields only, including 'pinning'
- libbpf reads the BTF map def 'pinning' field into a __u32
- Realistically, `enum libbpf_pin_type` will not acquire any negative values

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo authored and lmb committed Oct 20, 2023
1 parent 64567f8 commit 0d47e51
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const (
type AttachFlags uint32

// PinType determines whether a map is pinned into a BPFFS.
type PinType int
type PinType uint32

// Valid pin types.
//
Expand Down
2 changes: 1 addition & 1 deletion types_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d47e51

Please sign in to comment.