>From fa9f3f47ddeb3e9a615c17aea57d2ecd53a7d201 Mon Sep 17 00:00:00 2001 From: lincyawer <53161583+Lincyaw@xxxxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 4 Jan 2024 10:51:36 +0800 Subject: [PATCH] The original documentation of BPF_JMP instructions is somehow misleading. The code part of instruction, e.g., BPF_JEQ's value is noted as 0x1, however, in `include/uapi/linux/bpf.h`, the value of BPF_JEQ is 0x10. At the same time, the description convention is inconsistent with the BPF_ALU, whose code are also 4bit, but the value of BPF_ADD is 0x00 Signed-off-by: lincyawer <53161583+Lincyaw@xxxxxxxxxxxxxxxxxxxxxxxx> --- .../bpf/standardization/instruction-set.rst | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst index 245b6defc..dee3b1fa8 100644 --- a/Documentation/bpf/standardization/instruction-set.rst +++ b/Documentation/bpf/standardization/instruction-set.rst @@ -355,23 +355,23 @@ The 'code' field encodes the operation as below: ======== ===== === =========================================== ========================================= code value src description notes ======== ===== === =========================================== ========================================= -BPF_JA 0x0 0x0 PC += offset BPF_JMP class -BPF_JA 0x0 0x0 PC += imm BPF_JMP32 class -BPF_JEQ 0x1 any PC += offset if dst == src -BPF_JGT 0x2 any PC += offset if dst > src unsigned -BPF_JGE 0x3 any PC += offset if dst >= src unsigned -BPF_JSET 0x4 any PC += offset if dst & src -BPF_JNE 0x5 any PC += offset if dst != src -BPF_JSGT 0x6 any PC += offset if dst > src signed -BPF_JSGE 0x7 any PC += offset if dst >= src signed -BPF_CALL 0x8 0x0 call helper function by address see `Helper functions`_ -BPF_CALL 0x8 0x1 call PC += imm see `Program-local functions`_ -BPF_CALL 0x8 0x2 call helper function by BTF ID see `Helper functions`_ -BPF_EXIT 0x9 0x0 return BPF_JMP only -BPF_JLT 0xa any PC += offset if dst < src unsigned -BPF_JLE 0xb any PC += offset if dst <= src unsigned -BPF_JSLT 0xc any PC += offset if dst < src signed -BPF_JSLE 0xd any PC += offset if dst <= src signed +BPF_JA 0x00 0x0 PC += offset BPF_JMP class +BPF_JA 0x00 0x0 PC += imm BPF_JMP32 class +BPF_JEQ 0x10 any PC += offset if dst == src +BPF_JGT 0x20 any PC += offset if dst > src unsigned +BPF_JGE 0x30 any PC += offset if dst >= src unsigned +BPF_JSET 0x40 any PC += offset if dst & src +BPF_JNE 0x50 any PC += offset if dst != src +BPF_JSGT 0x60 any PC += offset if dst > src signed +BPF_JSGE 0x70 any PC += offset if dst >= src signed +BPF_CALL 0x80 0x0 call helper function by address see `Helper functions`_ +BPF_CALL 0x80 0x1 call PC += imm see `Program-local functions`_ +BPF_CALL 0x80 0x2 call helper function by BTF ID see `Helper functions`_ +BPF_EXIT 0x90 0x0 return BPF_JMP only +BPF_JLT 0xa0 any PC += offset if dst < src unsigned +BPF_JLE 0xb0 any PC += offset if dst <= src unsigned +BPF_JSLT 0xc0 any PC += offset if dst < src signed +BPF_JSLE 0xd0 any PC += offset if dst <= src signed ======== ===== === =========================================== ========================================= The BPF program needs to store the return value into register R0 before doing a -- 2.42.0