Skip to content

Commit

Permalink
Add feature test for BPF_F_INNER_MAP maps
Browse files Browse the repository at this point in the history
Introduced in
torvalds/linux@4a8f87e.

In Cilium, following the merge of cilium/cilium#15546, we need to add
this feature test as Maglev mode uses inner maps (map-in-map).

Signed-off-by: Chris Tarazi <chris@isovalent.com>
  • Loading branch information
christarazi committed Jun 21, 2021
1 parent 2d8d7b4 commit 6bd777a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/unix/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
BPF_F_WRONLY_PROG = linux.BPF_F_WRONLY_PROG
BPF_F_SLEEPABLE = linux.BPF_F_SLEEPABLE
BPF_F_MMAPABLE = linux.BPF_F_MMAPABLE
BPF_F_INNER_MAP = linux.BPF_F_INNER_MAP
BPF_OBJ_NAME_LEN = linux.BPF_OBJ_NAME_LEN
BPF_TAG_SIZE = linux.BPF_TAG_SIZE
SYS_BPF = linux.SYS_BPF
Expand Down
1 change: 1 addition & 0 deletions internal/unix/types_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
BPF_F_WRONLY_PROG = 0
BPF_F_SLEEPABLE = 0
BPF_F_MMAPABLE = 0
BPF_F_INNER_MAP = 0
BPF_OBJ_NAME_LEN = 0x10
BPF_TAG_SIZE = 0x8
SYS_BPF = 321
Expand Down
5 changes: 5 additions & 0 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ func createMap(spec *MapSpec, inner *internal.FD, opts MapOptions, handles *hand
return nil, fmt.Errorf("map create: %w", err)
}
}
if spec.Flags&unix.BPF_F_INNER_MAP > 0 {
if err := haveInnerMaps(); err != nil {
return nil, fmt.Errorf("map create: %w", err)
}
}

attr := internal.BPFMapCreateAttr{
MapType: uint32(spec.Type),
Expand Down
16 changes: 16 additions & 0 deletions syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ var haveMmapableMaps = internal.FeatureTest("mmapable maps", "5.5", func() error
return nil
})

var haveInnerMaps = internal.FeatureTest("inner maps", "5.10", func() error {
// This checks BPF_F_INNER_MAP, which appeared in 5.10.
m, err := internal.BPFMapCreate(&internal.BPFMapCreateAttr{
MapType: uint32(Array),
KeySize: 4,
ValueSize: 4,
MaxEntries: 1,
Flags: unix.BPF_F_MMAPABLE,
})
if err != nil {
return internal.ErrNotSupported
}
_ = m.Close()
return nil
})

func bpfMapLookupElem(m *internal.FD, key, valueOut internal.Pointer) error {
fd, err := m.Value()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions syscalls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ func TestHaveMapMutabilityModifiers(t *testing.T) {
func TestHaveMmapableMaps(t *testing.T) {
testutils.CheckFeatureTest(t, haveMmapableMaps)
}

func TestHaveInnerMaps(t *testing.T) {
testutils.CheckFeatureTest(t, haveInnerMaps)
}

0 comments on commit 6bd777a

Please sign in to comment.