Skip to content

Commit bc84e95

Browse files
Christoph HellwigAlexei Starovoitov
authored andcommitted
bpf, docs: Move handling of maps to Documentation/bpf/maps.rst
Move the general maps documentation into the maps.rst file from the overall networking filter documentation and add a link instead. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 06edc59 commit bc84e95

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

Documentation/bpf/maps.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
1+
2+
=========
3+
eBPF maps
14
=========
5+
6+
'maps' is a generic storage of different types for sharing data between kernel
7+
and userspace.
8+
9+
The maps are accessed from user space via BPF syscall, which has commands:
10+
11+
- create a map with given type and attributes
12+
``map_fd = bpf(BPF_MAP_CREATE, union bpf_attr *attr, u32 size)``
13+
using attr->map_type, attr->key_size, attr->value_size, attr->max_entries
14+
returns process-local file descriptor or negative error
15+
16+
- lookup key in a given map
17+
``err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size)``
18+
using attr->map_fd, attr->key, attr->value
19+
returns zero and stores found elem into value or negative error
20+
21+
- create or update key/value pair in a given map
22+
``err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)``
23+
using attr->map_fd, attr->key, attr->value
24+
returns zero or negative error
25+
26+
- find and delete element by key in a given map
27+
``err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size)``
28+
using attr->map_fd, attr->key
29+
30+
- to delete map: close(fd)
31+
Exiting process will delete maps automatically
32+
33+
userspace programs use this syscall to create/access maps that eBPF programs
34+
are concurrently updating.
35+
36+
maps can have different types: hash, array, bloom filter, radix-tree, etc.
37+
38+
The map is defined by:
39+
40+
- type
41+
- max number of elements
42+
- key size in bytes
43+
- value size in bytes
44+
245
Map Types
346
=========
447

Documentation/networking/filter.rst

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,9 @@ pointer type. The types of pointers describe their base, as follows:
12321232
Pointer to the value stored in a map element.
12331233
PTR_TO_MAP_VALUE_OR_NULL
12341234
Either a pointer to a map value, or NULL; map accesses
1235-
(see section 'eBPF maps', below) return this type,
1236-
which becomes a PTR_TO_MAP_VALUE when checked != NULL.
1237-
Arithmetic on these pointers is forbidden.
1235+
(see maps.rst) return this type, which becomes a
1236+
a PTR_TO_MAP_VALUE when checked != NULL. Arithmetic on
1237+
these pointers is forbidden.
12381238
PTR_TO_STACK
12391239
Frame pointer.
12401240
PTR_TO_PACKET
@@ -1402,47 +1402,6 @@ using normal C code as::
14021402
which makes such programs easier to write comparing to LD_ABS insn
14031403
and significantly faster.
14041404

1405-
eBPF maps
1406-
---------
1407-
'maps' is a generic storage of different types for sharing data between kernel
1408-
and userspace.
1409-
1410-
The maps are accessed from user space via BPF syscall, which has commands:
1411-
1412-
- create a map with given type and attributes
1413-
``map_fd = bpf(BPF_MAP_CREATE, union bpf_attr *attr, u32 size)``
1414-
using attr->map_type, attr->key_size, attr->value_size, attr->max_entries
1415-
returns process-local file descriptor or negative error
1416-
1417-
- lookup key in a given map
1418-
``err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size)``
1419-
using attr->map_fd, attr->key, attr->value
1420-
returns zero and stores found elem into value or negative error
1421-
1422-
- create or update key/value pair in a given map
1423-
``err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)``
1424-
using attr->map_fd, attr->key, attr->value
1425-
returns zero or negative error
1426-
1427-
- find and delete element by key in a given map
1428-
``err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size)``
1429-
using attr->map_fd, attr->key
1430-
1431-
- to delete map: close(fd)
1432-
Exiting process will delete maps automatically
1433-
1434-
userspace programs use this syscall to create/access maps that eBPF programs
1435-
are concurrently updating.
1436-
1437-
maps can have different types: hash, array, bloom filter, radix-tree, etc.
1438-
1439-
The map is defined by:
1440-
1441-
- type
1442-
- max number of elements
1443-
- key size in bytes
1444-
- value size in bytes
1445-
14461405
Pruning
14471406
-------
14481407
The verifier does not actually walk all possible paths through the program. For

0 commit comments

Comments
 (0)