Skip to content

Commit e48f0f4

Browse files
Dave Thalerborkmann
authored andcommitted
bpf, docs: Clarify definitions of various instructions
Clarify definitions of several instructions: * BPF_NEG does not support BPF_X * BPF_CALL does not support BPF_JMP32 or BPF_X * BPF_EXIT does not support BPF_X * BPF_JA does not support BPF_X (was implied but not explicitly stated) Also fix a typo in the wide instruction figure where the field is actually named "opcode" not "code". Signed-off-by: Dave Thaler <dthaler1968@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/bpf/20240126040050.8464-1-dthaler1968@gmail.com
1 parent e6be8cd commit e48f0f4

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

Documentation/bpf/standardization/instruction-set.rst

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ and imm containing the high 32 bits of the immediate value.
174174
This is depicted in the following figure::
175175

176176
basic_instruction
177-
.-----------------------------.
178-
| |
179-
code:8 regs:8 offset:16 imm:32 unused:32 imm:32
180-
| |
181-
'--------------'
182-
pseudo instruction
177+
.------------------------------.
178+
| |
179+
opcode:8 regs:8 offset:16 imm:32 unused:32 imm:32
180+
| |
181+
'--------------'
182+
pseudo instruction
183183

184184
Thus the 64-bit immediate value is constructed as follows:
185185

@@ -320,6 +320,9 @@ bit operands, and zeroes the remaining upper 32 bits.
320320
operands into 64 bit operands. Unlike other arithmetic instructions,
321321
``BPF_MOVSX`` is only defined for register source operands (``BPF_X``).
322322

323+
The ``BPF_NEG`` instruction is only defined when the source bit is clear
324+
(``BPF_K``).
325+
323326
Shift operations use a mask of 0x3F (63) for 64-bit operations and 0x1F (31)
324327
for 32-bit operations.
325328

@@ -375,27 +378,27 @@ Jump instructions
375378
otherwise identical operations.
376379
The 'code' field encodes the operation as below:
377380

378-
======== ===== === =========================================== =========================================
379-
code value src description notes
380-
======== ===== === =========================================== =========================================
381-
BPF_JA 0x0 0x0 PC += offset BPF_JMP class
382-
BPF_JA 0x0 0x0 PC += imm BPF_JMP32 class
381+
======== ===== === =============================== =============================================
382+
code value src description notes
383+
======== ===== === =============================== =============================================
384+
BPF_JA 0x0 0x0 PC += offset BPF_JMP | BPF_K only
385+
BPF_JA 0x0 0x0 PC += imm BPF_JMP32 | BPF_K only
383386
BPF_JEQ 0x1 any PC += offset if dst == src
384-
BPF_JGT 0x2 any PC += offset if dst > src unsigned
385-
BPF_JGE 0x3 any PC += offset if dst >= src unsigned
387+
BPF_JGT 0x2 any PC += offset if dst > src unsigned
388+
BPF_JGE 0x3 any PC += offset if dst >= src unsigned
386389
BPF_JSET 0x4 any PC += offset if dst & src
387390
BPF_JNE 0x5 any PC += offset if dst != src
388-
BPF_JSGT 0x6 any PC += offset if dst > src signed
389-
BPF_JSGE 0x7 any PC += offset if dst >= src signed
390-
BPF_CALL 0x8 0x0 call helper function by address see `Helper functions`_
391-
BPF_CALL 0x8 0x1 call PC += imm see `Program-local functions`_
392-
BPF_CALL 0x8 0x2 call helper function by BTF ID see `Helper functions`_
393-
BPF_EXIT 0x9 0x0 return BPF_JMP only
394-
BPF_JLT 0xa any PC += offset if dst < src unsigned
395-
BPF_JLE 0xb any PC += offset if dst <= src unsigned
396-
BPF_JSLT 0xc any PC += offset if dst < src signed
397-
BPF_JSLE 0xd any PC += offset if dst <= src signed
398-
======== ===== === =========================================== =========================================
391+
BPF_JSGT 0x6 any PC += offset if dst > src signed
392+
BPF_JSGE 0x7 any PC += offset if dst >= src signed
393+
BPF_CALL 0x8 0x0 call helper function by address BPF_JMP | BPF_K only, see `Helper functions`_
394+
BPF_CALL 0x8 0x1 call PC += imm BPF_JMP | BPF_K only, see `Program-local functions`_
395+
BPF_CALL 0x8 0x2 call helper function by BTF ID BPF_JMP | BPF_K only, see `Helper functions`_
396+
BPF_EXIT 0x9 0x0 return BPF_JMP | BPF_K only
397+
BPF_JLT 0xa any PC += offset if dst < src unsigned
398+
BPF_JLE 0xb any PC += offset if dst <= src unsigned
399+
BPF_JSLT 0xc any PC += offset if dst < src signed
400+
BPF_JSLE 0xd any PC += offset if dst <= src signed
401+
======== ===== === =============================== =============================================
399402

400403
The BPF program needs to store the return value into register R0 before doing a
401404
``BPF_EXIT``.

0 commit comments

Comments
 (0)