Skip to content

Commit d405c74

Browse files
Jiong WangAlexei Starovoitov
authored andcommitted
bpf: allocate 0x06 to new eBPF instruction class JMP32
The new eBPF instruction class JMP32 uses the reserved class number 0x6. Kernel BPF ISA documentation updated accordingly. Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Jiong Wang <jiong.wang@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent dbbd79a commit d405c74

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎Documentation/networking/filter.txt‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ Three LSB bits store instruction class which is one of:
865865
BPF_STX 0x03 BPF_STX 0x03
866866
BPF_ALU 0x04 BPF_ALU 0x04
867867
BPF_JMP 0x05 BPF_JMP 0x05
868-
BPF_RET 0x06 [ class 6 unused, for future if needed ]
868+
BPF_RET 0x06 BPF_JMP32 0x06
869869
BPF_MISC 0x07 BPF_ALU64 0x07
870870

871871
When BPF_CLASS(code) == BPF_ALU or BPF_JMP, 4th bit encodes source operand ...
@@ -902,18 +902,18 @@ If BPF_CLASS(code) == BPF_ALU or BPF_ALU64 [ in eBPF ], BPF_OP(code) is one of:
902902
BPF_ARSH 0xc0 /* eBPF only: sign extending shift right */
903903
BPF_END 0xd0 /* eBPF only: endianness conversion */
904904

905-
If BPF_CLASS(code) == BPF_JMP, BPF_OP(code) is one of:
905+
If BPF_CLASS(code) == BPF_JMP or BPF_JMP32 [ in eBPF ], BPF_OP(code) is one of:
906906

907-
BPF_JA 0x00
907+
BPF_JA 0x00 /* BPF_JMP only */
908908
BPF_JEQ 0x10
909909
BPF_JGT 0x20
910910
BPF_JGE 0x30
911911
BPF_JSET 0x40
912912
BPF_JNE 0x50 /* eBPF only: jump != */
913913
BPF_JSGT 0x60 /* eBPF only: signed '>' */
914914
BPF_JSGE 0x70 /* eBPF only: signed '>=' */
915-
BPF_CALL 0x80 /* eBPF only: function call */
916-
BPF_EXIT 0x90 /* eBPF only: function return */
915+
BPF_CALL 0x80 /* eBPF BPF_JMP only: function call */
916+
BPF_EXIT 0x90 /* eBPF BPF_JMP only: function return */
917917
BPF_JLT 0xa0 /* eBPF only: unsigned '<' */
918918
BPF_JLE 0xb0 /* eBPF only: unsigned '<=' */
919919
BPF_JSLT 0xc0 /* eBPF only: signed '<' */
@@ -936,8 +936,9 @@ Classic BPF wastes the whole BPF_RET class to represent a single 'ret'
936936
operation. Classic BPF_RET | BPF_K means copy imm32 into return register
937937
and perform function exit. eBPF is modeled to match CPU, so BPF_JMP | BPF_EXIT
938938
in eBPF means function exit only. The eBPF program needs to store return
939-
value into register R0 before doing a BPF_EXIT. Class 6 in eBPF is currently
940-
unused and reserved for future use.
939+
value into register R0 before doing a BPF_EXIT. Class 6 in eBPF is used as
940+
BPF_JMP32 to mean exactly the same operations as BPF_JMP, but with 32-bit wide
941+
operands for the comparisons instead.
941942

942943
For load and store instructions the 8-bit 'code' field is divided as:
943944

‎include/uapi/linux/bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/* Extended instruction set based on top of classic BPF */
1515

1616
/* instruction classes */
17+
#define BPF_JMP32 0x06 /* jmp mode in word width */
1718
#define BPF_ALU64 0x07 /* alu mode in double word width */
1819

1920
/* ld/ldx fields */

‎tools/include/uapi/linux/bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/* Extended instruction set based on top of classic BPF */
1515

1616
/* instruction classes */
17+
#define BPF_JMP32 0x06 /* jmp mode in word width */
1718
#define BPF_ALU64 0x07 /* alu mode in double word width */
1819

1920
/* ld/ldx fields */

0 commit comments

Comments
 (0)