Skip to content

Commit d6c49c4

Browse files
dthalerKernel Patches Daemon
authored andcommitted
bpf, docs: Explain helper functions
Explain helper functions Signed-off-by: Dave Thaler <dthaler@microsoft.com>
1 parent a202538 commit d6c49c4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Documentation/bpf/instruction-set.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ BPF_JSET 0x40 PC += off if dst & src
242242
BPF_JNE 0x50 PC += off if dst != src
243243
BPF_JSGT 0x60 PC += off if dst > src signed
244244
BPF_JSGE 0x70 PC += off if dst >= src signed
245-
BPF_CALL 0x80 function call
245+
BPF_CALL 0x80 function call see `Helper functions`_
246246
BPF_EXIT 0x90 function / program return BPF_JMP only
247247
BPF_JLT 0xa0 PC += off if dst < src unsigned
248248
BPF_JLE 0xb0 PC += off if dst <= src unsigned
@@ -253,6 +253,22 @@ BPF_JSLE 0xd0 PC += off if dst <= src signed
253253
The eBPF program needs to store the return value into register R0 before doing a
254254
BPF_EXIT.
255255

256+
Helper functions
257+
~~~~~~~~~~~~~~~~
258+
Helper functions are a concept whereby BPF programs can call into a
259+
set of function calls exposed by the eBPF runtime. Each helper
260+
function is identified by an integer used in a ``BPF_CALL`` instruction.
261+
The available helper functions may differ for each eBPF program type.
262+
263+
Conceptually, each helper function is implemented with a commonly shared function
264+
signature defined as:
265+
266+
u64 function(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
267+
268+
In actuality, each helper function is defined as taking between 0 and 5 arguments,
269+
with the remaining registers being ignored. The definition of a helper function
270+
is responsible for specifying the type (e.g., integer, pointer, etc.) of the value returned,
271+
the number of arguments, and the type of each argument.
256272

257273
Load and store instructions
258274
===========================

0 commit comments

Comments
 (0)