aboutsummaryrefslogtreecommitdiff
path: root/Documentation/bpf
diff options
context:
space:
mode:
authorChristoph Hellwig2022-01-03 19:35:52 +0100
committerAlexei Starovoitov2022-01-05 13:11:26 -0800
commitbe3193cded9d5c030be1713bf52d307427e88d19 (patch)
tree9c4ba903760e05dbfa337472b01fdc4ba30236cd /Documentation/bpf
parent62e4683849b6516c71e91f36e4fc0393a5883cfb (diff)
bpf, docs: Add subsections for ALU and JMP instructions
Add a little more stucture to the ALU/JMP documentation with sections and improve the example text. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220103183556.41040-3-hch@lst.de
Diffstat (limited to 'Documentation/bpf')
-rw-r--r--Documentation/bpf/instruction-set.rst52
1 files changed, 32 insertions, 20 deletions
diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst
index 80f42984b594..03bf3c6c5577 100644
--- a/Documentation/bpf/instruction-set.rst
+++ b/Documentation/bpf/instruction-set.rst
@@ -74,7 +74,13 @@ The 4th bit encodes the source operand:
The four MSB bits store the operation code.
-For class BPF_ALU or BPF_ALU64:
+
+Arithmetic instructions
+-----------------------
+
+BPF_ALU uses 32-bit wide operands while BPF_ALU64 uses 64-bit wide operands for
+otherwise identical operations.
+The code field encodes the operation as below:
======== ===== =========================
code value description
@@ -95,7 +101,29 @@ For class BPF_ALU or BPF_ALU64:
BPF_END 0xd0 endianness conversion
======== ===== =========================
-For class BPF_JMP or BPF_JMP32:
+BPF_ADD | BPF_X | BPF_ALU means::
+
+ dst_reg = (u32) dst_reg + (u32) src_reg;
+
+BPF_ADD | BPF_X | BPF_ALU64 means::
+
+ dst_reg = dst_reg + src_reg
+
+BPF_XOR | BPF_K | BPF_ALU means::
+
+ src_reg = (u32) src_reg ^ (u32) imm32
+
+BPF_XOR | BPF_K | BPF_ALU64 means::
+
+ src_reg = src_reg ^ imm32
+
+
+Jump instructions
+-----------------
+
+BPF_JMP32 uses 32-bit wide operands while BPF_JMP uses 64-bit wide operands for
+otherwise identical operations.
+The code field encodes the operation as below:
======== ===== =========================
code value description
@@ -116,24 +144,8 @@ For class BPF_JMP or BPF_JMP32:
BPF_JSLE 0xd0 signed '<='
======== ===== =========================
-So BPF_ADD | BPF_X | BPF_ALU means::
-
- dst_reg = (u32) dst_reg + (u32) src_reg;
-
-Similarly, BPF_XOR | BPF_K | BPF_ALU means::
-
- src_reg = (u32) src_reg ^ (u32) imm32
-
-eBPF is using BPF_MOV | BPF_X | BPF_ALU to represent A = B moves. BPF_ALU64
-is used to mean exactly the same operations as BPF_ALU, but with 64-bit wide
-operands instead. So BPF_ADD | BPF_X | BPF_ALU64 means 64-bit addition, i.e.::
-
- dst_reg = dst_reg + src_reg
-
-BPF_JMP | BPF_EXIT means function exit only. The eBPF program needs to store
-the return value into register R0 before doing a BPF_EXIT. Class 6 is used as
-BPF_JMP32 to mean exactly the same operations as BPF_JMP, but with 32-bit wide
-operands for the comparisons instead.
+The eBPF program needs to store the return value into register R0 before doing a
+BPF_EXIT.
Load and store instructions