Skip to content

Commit

Permalink
add haveV4ISA probe
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 long jump given by `BPF_JMP32 | BPF_JA`.

Signed-off-by: Simone Magnani <[email protected]>
  • Loading branch information
smagnani96 committed Dec 9, 2024
1 parent 2eace67 commit 7aa1e62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 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)
}

0 comments on commit 7aa1e62

Please sign in to comment.