github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/features/misc.go (about) 1 package features 2 3 import ( 4 "github.com/cilium/ebpf" 5 "github.com/cilium/ebpf/asm" 6 "github.com/cilium/ebpf/internal" 7 ) 8 9 // HaveLargeInstructions probes the running kernel if more than 4096 instructions 10 // per program are supported. 11 // 12 // Upstream commit c04c0d2b968a ("bpf: increase complexity limit and maximum program size"). 13 // 14 // See the package documentation for the meaning of the error return value. 15 func HaveLargeInstructions() error { 16 return haveLargeInstructions() 17 } 18 19 var haveLargeInstructions = internal.NewFeatureTest(">4096 instructions", "5.2", func() error { 20 const maxInsns = 4096 21 22 insns := make(asm.Instructions, maxInsns, maxInsns+1) 23 for i := range insns { 24 insns[i] = asm.Mov.Imm(asm.R0, 1) 25 } 26 insns = append(insns, asm.Return()) 27 28 return probeProgram(&ebpf.ProgramSpec{ 29 Type: ebpf.SocketFilter, 30 Instructions: insns, 31 }) 32 }) 33 34 // HaveBoundedLoops probes the running kernel if bounded loops are supported. 35 // 36 // Upstream commit 2589726d12a1 ("bpf: introduce bounded loops"). 37 // 38 // See the package documentation for the meaning of the error return value. 39 func HaveBoundedLoops() error { 40 return haveBoundedLoops() 41 } 42 43 var haveBoundedLoops = internal.NewFeatureTest("bounded loops", "5.3", func() error { 44 return probeProgram(&ebpf.ProgramSpec{ 45 Type: ebpf.SocketFilter, 46 Instructions: asm.Instructions{ 47 asm.Mov.Imm(asm.R0, 10), 48 asm.Sub.Imm(asm.R0, 1).WithSymbol("loop"), 49 asm.JNE.Imm(asm.R0, 0, "loop"), 50 asm.Return(), 51 }, 52 }) 53 }) 54 55 // HaveV2ISA probes the running kernel if instructions of the v2 ISA are supported. 56 // 57 // Upstream commit 92b31a9af73b ("bpf: add BPF_J{LT,LE,SLT,SLE} instructions"). 58 // 59 // See the package documentation for the meaning of the error return value. 60 func HaveV2ISA() error { 61 return haveV2ISA() 62 } 63 64 var haveV2ISA = internal.NewFeatureTest("v2 ISA", "4.14", func() error { 65 return probeProgram(&ebpf.ProgramSpec{ 66 Type: ebpf.SocketFilter, 67 Instructions: asm.Instructions{ 68 asm.Mov.Imm(asm.R0, 0), 69 asm.JLT.Imm(asm.R0, 0, "exit"), 70 asm.Mov.Imm(asm.R0, 1), 71 asm.Return().WithSymbol("exit"), 72 }, 73 }) 74 }) 75 76 // HaveV3ISA probes the running kernel if instructions of the v3 ISA are supported. 77 // 78 // Upstream commit 092ed0968bb6 ("bpf: verifier support JMP32"). 79 // 80 // See the package documentation for the meaning of the error return value. 81 func HaveV3ISA() error { 82 return haveV3ISA() 83 } 84 85 var haveV3ISA = internal.NewFeatureTest("v3 ISA", "5.1", func() error { 86 return probeProgram(&ebpf.ProgramSpec{ 87 Type: ebpf.SocketFilter, 88 Instructions: asm.Instructions{ 89 asm.Mov.Imm(asm.R0, 0), 90 asm.JLT.Imm32(asm.R0, 0, "exit"), 91 asm.Mov.Imm(asm.R0, 1), 92 asm.Return().WithSymbol("exit"), 93 }, 94 }) 95 })