Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions features/misc.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package features

import (
"errors"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/asm"
"github.com/cilium/ebpf/internal"
"github.com/cilium/ebpf/internal/sys"
)

// HaveLargeInstructions probes the running kernel if more than 4096 instructions
Expand Down Expand Up @@ -62,7 +65,7 @@ func HaveV2ISA() error {
}

var haveV2ISA = internal.NewFeatureTest("v2 ISA", func() error {
return probeProgram(&ebpf.ProgramSpec{
err := probeProgram(&ebpf.ProgramSpec{
Type: ebpf.SocketFilter,
Instructions: asm.Instructions{
asm.Mov.Imm(asm.R0, 0),
Expand All @@ -71,6 +74,11 @@ var haveV2ISA = internal.NewFeatureTest("v2 ISA", func() error {
asm.Return().WithSymbol("exit"),
},
})
// This sometimes bubbles up from the JIT on aarch64.
if errors.Is(err, sys.ENOTSUPP) {
return ebpf.ErrNotSupported
}
return err
}, "4.14")

// HaveV3ISA probes the running kernel if instructions of the v3 ISA are supported.
Expand All @@ -83,7 +91,7 @@ func HaveV3ISA() error {
}

var haveV3ISA = internal.NewFeatureTest("v3 ISA", func() error {
return probeProgram(&ebpf.ProgramSpec{
err := probeProgram(&ebpf.ProgramSpec{
Type: ebpf.SocketFilter,
Instructions: asm.Instructions{
asm.Mov.Imm(asm.R0, 0),
Expand All @@ -92,4 +100,36 @@ var haveV3ISA = internal.NewFeatureTest("v3 ISA", func() error {
asm.Return().WithSymbol("exit"),
},
})
// This sometimes bubbles up from the JIT on aarch64.
if errors.Is(err, sys.ENOTSUPP) {
return ebpf.ErrNotSupported
}
return err
}, "5.1")

// HaveV4ISA probes the running kernel if instructions of the v4 ISA are supported.
//
// Upstream commit 1f9a1ea821ff ("bpf: Support new sign-extension load insns").
//
// See the package documentation for the meaning of the error return value.
func HaveV4ISA() error {
return haveV4ISA()
}

var haveV4ISA = internal.NewFeatureTest("v4 ISA", func() error {
err := probeProgram(&ebpf.ProgramSpec{
Type: ebpf.SocketFilter,
Instructions: asm.Instructions{
asm.Mov.Imm(asm.R0, 0),
asm.JEq.Imm(asm.R0, 1, "error"),
asm.LongJump("exit"),
asm.Mov.Imm(asm.R0, 1).WithSymbol("error"),
asm.Return().WithSymbol("exit"),
},
})
// This sometimes bubbles up from the JIT on aarch64.
if errors.Is(err, sys.ENOTSUPP) {
return ebpf.ErrNotSupported
}
return err
}, "6.6")
4 changes: 4 additions & 0 deletions features/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func TestHaveV2ISA(t *testing.T) {
func TestHaveV3ISA(t *testing.T) {
testutils.CheckFeatureTest(t, HaveV3ISA)
}

func TestHaveV4ISA(t *testing.T) {
testutils.CheckFeatureTest(t, HaveV4ISA)
}
Loading