Skip to content

Commit

Permalink
add haveV4ISA probe for verifying ISA v4 support in the kernel
Browse files Browse the repository at this point in the history
This commit introduces the haveV4ISA probe and HaveV4ISA API to check
in the running kernel if instructions of the v4 ISA are supported.
The upstream commit used as reference is 1f9a1ea821ff
("bpf: Support new sign-extension load insns").
The probes tests the new asm.LongJump insn given by `BPF_JMP32 | BPF_JA`.
On arm64 with kernel prior to ISA v4 support (<= v6.6), this would return
sys.ENOTSUPP: handle this case by returning our ebpf.ErrNotSupported
instead.

Signed-off-by: Simone Magnani <[email protected]>
  • Loading branch information
smagnani96 committed Dec 11, 2024
1 parent 5ffd2ed commit 6da9a71
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions features/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,25 @@ var haveV3ISA = internal.NewFeatureTest("v3 ISA", func() error {
},
})
}, "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 {
return 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"),
},
})
}, "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)
}
4 changes: 2 additions & 2 deletions features/prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func probeProgram(spec *ebpf.ProgramSpec) error {
}

switch {
// ENOTSUPP with ebpf.StructOps means the program type is at least known to the kernel.
// With ebpf.StructOps, ENOTSUPP means the program type is at least known to the kernel.
case errors.Is(err, sys.ENOTSUPP) && spec.Type == ebpf.StructOps:
return nil
err = nil
// ENOTSUPP occurs when, for instance, JIT fails.
// EINVAL occurs when attempting to create a program with an unknown type.
// E2BIG occurs when ProgLoadAttr contains non-zero bytes past the end
Expand Down

0 comments on commit 6da9a71

Please sign in to comment.