~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/bpf/linux-notes.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 .. contents::
  2 .. sectnum::
  3 
  4 ==========================
  5 Linux implementation notes
  6 ==========================
  7 
  8 This document provides more details specific to the Linux kernel implementation of the eBPF instruction set.
  9 
 10 Byte swap instructions
 11 ======================
 12 
 13 ``BPF_FROM_LE`` and ``BPF_FROM_BE`` exist as aliases for ``BPF_TO_LE`` and ``BPF_TO_BE`` respectively.
 14 
 15 Jump instructions
 16 =================
 17 
 18 ``BPF_CALL | BPF_X | BPF_JMP`` (0x8d), where the helper function
 19 integer would be read from a specified register, is not currently supported
 20 by the verifier.  Any programs with this instruction will fail to load
 21 until such support is added.
 22 
 23 Maps
 24 ====
 25 
 26 Linux only supports the 'map_val(map)' operation on array maps with a single element.
 27 
 28 Linux uses an fd_array to store maps associated with a BPF program. Thus,
 29 map_by_idx(imm) uses the fd at that index in the array.
 30 
 31 Variables
 32 =========
 33 
 34 The following 64-bit immediate instruction specifies that a variable address,
 35 which corresponds to some integer stored in the 'imm' field, should be loaded:
 36 
 37 =========================  ======  ===  =========================================  ===========  ==============
 38 opcode construction        opcode  src  pseudocode                                 imm type     dst type
 39 =========================  ======  ===  =========================================  ===========  ==============
 40 BPF_IMM | BPF_DW | BPF_LD  0x18    0x3  dst = var_addr(imm)                        variable id  data pointer
 41 =========================  ======  ===  =========================================  ===========  ==============
 42 
 43 On Linux, this integer is a BTF ID.
 44 
 45 Legacy BPF Packet access instructions
 46 =====================================
 47 
 48 As mentioned in the `ISA standard documentation
 49 <instruction-set.html#legacy-bpf-packet-access-instructions>`_,
 50 Linux has special eBPF instructions for access to packet data that have been
 51 carried over from classic BPF to retain the performance of legacy socket
 52 filters running in the eBPF interpreter.
 53 
 54 The instructions come in two forms: ``BPF_ABS | <size> | BPF_LD`` and
 55 ``BPF_IND | <size> | BPF_LD``.
 56 
 57 These instructions are used to access packet data and can only be used when
 58 the program context is a pointer to a networking packet.  ``BPF_ABS``
 59 accesses packet data at an absolute offset specified by the immediate data
 60 and ``BPF_IND`` access packet data at an offset that includes the value of
 61 a register in addition to the immediate data.
 62 
 63 These instructions have seven implicit operands:
 64 
 65 * Register R6 is an implicit input that must contain a pointer to a
 66   struct sk_buff.
 67 * Register R0 is an implicit output which contains the data fetched from
 68   the packet.
 69 * Registers R1-R5 are scratch registers that are clobbered by the
 70   instruction.
 71 
 72 These instructions have an implicit program exit condition as well. If an
 73 eBPF program attempts access data beyond the packet boundary, the
 74 program execution will be aborted.
 75 
 76 ``BPF_ABS | BPF_W | BPF_LD`` (0x20) means::
 77 
 78   R0 = ntohl(*(u32 *) ((struct sk_buff *) R6->data + imm))
 79 
 80 where ``ntohl()`` converts a 32-bit value from network byte order to host byte order.
 81 
 82 ``BPF_IND | BPF_W | BPF_LD`` (0x40) means::
 83 
 84   R0 = ntohl(*(u32 *) ((struct sk_buff *) R6->data + src + imm))

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php