diff options
author | Dave Thaler <dthaler@microsoft.com> | 2023-05-09 20:08:45 +0200 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2023-05-17 16:18:33 +0200 |
commit | 8819495a754e71d3c3fde991c26ad832af995136 (patch) | |
tree | b27c2ab926bb0ed71515b80b25a3c85f363175a3 /Documentation/bpf | |
parent | bpftool: Support bpffs mountpoint as pin path for prog loadall (diff) | |
download | linux-8819495a754e71d3c3fde991c26ad832af995136.tar.xz linux-8819495a754e71d3c3fde991c26ad832af995136.zip |
bpf, docs: Shift operations are defined to use a mask
Update the documentation regarding shift operations to explain the
use of a mask, since otherwise shifting by a value out of range
(like negative) is undefined.
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20230509180845.1236-1-dthaler1968@googlemail.com
Diffstat (limited to 'Documentation/bpf')
-rw-r--r-- | Documentation/bpf/instruction-set.rst | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index 492980ece1ab..6644842cd3ea 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -163,13 +163,13 @@ BPF_MUL 0x20 dst \*= src BPF_DIV 0x30 dst = (src != 0) ? (dst / src) : 0 BPF_OR 0x40 dst \|= src BPF_AND 0x50 dst &= src -BPF_LSH 0x60 dst <<= src -BPF_RSH 0x70 dst >>= src +BPF_LSH 0x60 dst <<= (src & mask) +BPF_RSH 0x70 dst >>= (src & mask) BPF_NEG 0x80 dst = ~src BPF_MOD 0x90 dst = (src != 0) ? (dst % src) : dst BPF_XOR 0xa0 dst ^= src BPF_MOV 0xb0 dst = src -BPF_ARSH 0xc0 sign extending shift right +BPF_ARSH 0xc0 sign extending dst >>= (src & mask) BPF_END 0xd0 byte swap operations (see `Byte swap instructions`_ below) ======== ===== ========================================================== @@ -204,6 +204,9 @@ for ``BPF_ALU64``, 'imm' is first sign extended to 64 bits and the result interpreted as an unsigned 64-bit value. There are no instructions for signed division or modulo. +Shift operations use a mask of 0x3F (63) for 64-bit operations and 0x1F (31) +for 32-bit operations. + Byte swap instructions ~~~~~~~~~~~~~~~~~~~~~~ |