Merge tag 'hwlock-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/andersson...
[linux-2.6-microblaze.git] / tools / bpf / bpftool / Documentation / bpftool-map.rst
1 ================
2 bpftool-map
3 ================
4 -------------------------------------------------------------------------------
5 tool for inspection and simple manipulation of eBPF maps
6 -------------------------------------------------------------------------------
7
8 :Manual section: 8
9
10 SYNOPSIS
11 ========
12
13         **bpftool** [*OPTIONS*] **map** *COMMAND*
14
15         *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
16
17         *COMMANDS* :=
18         { **show** | **list** | **create** | **dump** | **update** | **lookup** | **getnext**
19         | **delete** | **pin** | **help** }
20
21 MAP COMMANDS
22 =============
23
24 |       **bpftool** **map { show | list }**   [*MAP*]
25 |       **bpftool** **map create**     *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE* \
26 |               **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
27 |       **bpftool** **map dump**       *MAP*
28 |       **bpftool** **map update**     *MAP* [**key** *DATA*] [**value** *VALUE*] [*UPDATE_FLAGS*]
29 |       **bpftool** **map lookup**     *MAP* [**key** *DATA*]
30 |       **bpftool** **map getnext**    *MAP* [**key** *DATA*]
31 |       **bpftool** **map delete**     *MAP*  **key** *DATA*
32 |       **bpftool** **map pin**        *MAP*  *FILE*
33 |       **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
34 |       **bpftool** **map peek**       *MAP*
35 |       **bpftool** **map push**       *MAP* **value** *VALUE*
36 |       **bpftool** **map pop**        *MAP*
37 |       **bpftool** **map enqueue**    *MAP* **value** *VALUE*
38 |       **bpftool** **map dequeue**    *MAP*
39 |       **bpftool** **map freeze**     *MAP*
40 |       **bpftool** **map help**
41 |
42 |       *MAP* := { **id** *MAP_ID* | **pinned** *FILE* | **name** *MAP_NAME* }
43 |       *DATA* := { [**hex**] *BYTES* }
44 |       *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* }
45 |       *VALUE* := { *DATA* | *MAP* | *PROG* }
46 |       *UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
47 |       *TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash**
48 |               | **percpu_array** | **stack_trace** | **cgroup_array** | **lru_hash**
49 |               | **lru_percpu_hash** | **lpm_trie** | **array_of_maps** | **hash_of_maps**
50 |               | **devmap** | **devmap_hash** | **sockmap** | **cpumap** | **xskmap** | **sockhash**
51 |               | **cgroup_storage** | **reuseport_sockarray** | **percpu_cgroup_storage**
52 |               | **queue** | **stack** }
53
54 DESCRIPTION
55 ===========
56         **bpftool map { show | list }**   [*MAP*]
57                   Show information about loaded maps.  If *MAP* is specified
58                   show information only about given maps, otherwise list all
59                   maps currently loaded on the system.  In case of **name**,
60                   *MAP* may match several maps which will all be shown.
61
62                   Output will start with map ID followed by map type and
63                   zero or more named attributes (depending on kernel version).
64
65         **bpftool map create** *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE*  **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
66                   Create a new map with given parameters and pin it to *bpffs*
67                   as *FILE*.
68
69         **bpftool map dump**    *MAP*
70                   Dump all entries in a given *MAP*.  In case of **name**,
71                   *MAP* may match several maps which will all be dumped.
72
73         **bpftool map update**  *MAP* [**key** *DATA*] [**value** *VALUE*] [*UPDATE_FLAGS*]
74                   Update map entry for a given *KEY*.
75
76                   *UPDATE_FLAGS* can be one of: **any** update existing entry
77                   or add if doesn't exit; **exist** update only if entry already
78                   exists; **noexist** update only if entry doesn't exist.
79
80                   If the **hex** keyword is provided in front of the bytes
81                   sequence, the bytes are parsed as hexadeximal values, even if
82                   no "0x" prefix is added. If the keyword is not provided, then
83                   the bytes are parsed as decimal values, unless a "0x" prefix
84                   (for hexadecimal) or a "0" prefix (for octal) is provided.
85
86         **bpftool map lookup**  *MAP* [**key** *DATA*]
87                   Lookup **key** in the map.
88
89         **bpftool map getnext** *MAP* [**key** *DATA*]
90                   Get next key.  If *key* is not specified, get first key.
91
92         **bpftool map delete**  *MAP*  **key** *DATA*
93                   Remove entry from the map.
94
95         **bpftool map pin**     *MAP*  *FILE*
96                   Pin map *MAP* as *FILE*.
97
98                   Note: *FILE* must be located in *bpffs* mount. It must not
99                   contain a dot character ('.'), which is reserved for future
100                   extensions of *bpffs*.
101
102         **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
103                   Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.
104
105                   Install perf rings into a perf event array map and dump
106                   output of any bpf_perf_event_output() call in the kernel.
107                   By default read the number of CPUs on the system and
108                   install perf ring for each CPU in the corresponding index
109                   in the array.
110
111                   If **cpu** and **index** are specified, install perf ring
112                   for given **cpu** at **index** in the array (single ring).
113
114                   Note that installing a perf ring into an array will silently
115                   replace any existing ring.  Any other application will stop
116                   receiving events if it installed its rings earlier.
117
118         **bpftool map peek**  *MAP*
119                   Peek next **value** in the queue or stack.
120
121         **bpftool map push**  *MAP* **value** *VALUE*
122                   Push **value** onto the stack.
123
124         **bpftool map pop**  *MAP*
125                   Pop and print **value** from the stack.
126
127         **bpftool map enqueue**  *MAP* **value** *VALUE*
128                   Enqueue **value** into the queue.
129
130         **bpftool map dequeue**  *MAP*
131                   Dequeue and print **value** from the queue.
132
133         **bpftool map freeze**  *MAP*
134                   Freeze the map as read-only from user space. Entries from a
135                   frozen map can not longer be updated or deleted with the
136                   **bpf\ ()** system call. This operation is not reversible,
137                   and the map remains immutable from user space until its
138                   destruction. However, read and write permissions for BPF
139                   programs to the map remain unchanged.
140
141         **bpftool map help**
142                   Print short help message.
143
144 OPTIONS
145 =======
146         -h, --help
147                   Print short generic help message (similar to **bpftool help**).
148
149         -V, --version
150                   Print version number (similar to **bpftool version**).
151
152         -j, --json
153                   Generate JSON output. For commands that cannot produce JSON, this
154                   option has no effect.
155
156         -p, --pretty
157                   Generate human-readable JSON output. Implies **-j**.
158
159         -f, --bpffs
160                   Show file names of pinned maps.
161
162         -n, --nomount
163                   Do not automatically attempt to mount any virtual file system
164                   (such as tracefs or BPF virtual file system) when necessary.
165
166         -d, --debug
167                   Print all logs available from libbpf, including debug-level
168                   information.
169
170 EXAMPLES
171 ========
172 **# bpftool map show**
173 ::
174
175   10: hash  name some_map  flags 0x0
176         key 4B  value 8B  max_entries 2048  memlock 167936B
177
178 The following three commands are equivalent:
179
180 |
181 | **# bpftool map update id 10 key hex   20   c4   b7   00 value hex   0f   ff   ff   ab   01   02   03   4c**
182 | **# bpftool map update id 10 key     0x20 0xc4 0xb7 0x00 value     0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
183 | **# bpftool map update id 10 key       32  196  183    0 value       15  255  255  171    1    2    3   76**
184
185 **# bpftool map lookup id 10 key 0 1 2 3**
186
187 ::
188
189   key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
190
191
192 **# bpftool map dump id 10**
193 ::
194
195   key: 00 01 02 03  value: 00 01 02 03 04 05 06 07
196   key: 0d 00 07 00  value: 02 00 00 00 01 02 03 04
197   Found 2 elements
198
199 **# bpftool map getnext id 10 key 0 1 2 3**
200 ::
201
202   key:
203   00 01 02 03
204   next key:
205   0d 00 07 00
206
207 |
208 | **# mount -t bpf none /sys/fs/bpf/**
209 | **# bpftool map pin id 10 /sys/fs/bpf/map**
210 | **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
211
212 Note that map update can also be used in order to change the program references
213 hold by a program array map. This can be used, for example, to change the
214 programs used for tail-call jumps at runtime, without having to reload the
215 entry-point program. Below is an example for this use case: we load a program
216 defining a prog array map, and with a main function that contains a tail call
217 to other programs that can be used either to "process" packets or to "debug"
218 processing. Note that the prog array map MUST be pinned into the BPF virtual
219 file system for the map update to work successfully, as kernel flushes prog
220 array maps when they have no more references from user space (and the update
221 would be lost as soon as bpftool exits).
222
223 |
224 | **# bpftool prog loadall tail_calls.o /sys/fs/bpf/foo type xdp**
225 | **# bpftool prog --bpffs**
226
227 ::
228
229   545: xdp  name main_func  tag 674b4b5597193dc3  gpl
230           loaded_at 2018-12-12T15:02:58+0000  uid 0
231           xlated 240B  jited 257B  memlock 4096B  map_ids 294
232           pinned /sys/fs/bpf/foo/xdp
233   546: xdp  name bpf_func_process  tag e369a529024751fc  gpl
234           loaded_at 2018-12-12T15:02:58+0000  uid 0
235           xlated 200B  jited 164B  memlock 4096B
236           pinned /sys/fs/bpf/foo/process
237   547: xdp  name bpf_func_debug  tag 0b597868bc7f0976  gpl
238           loaded_at 2018-12-12T15:02:58+0000  uid 0
239           xlated 200B  jited 164B  memlock 4096B
240           pinned /sys/fs/bpf/foo/debug
241
242 **# bpftool map**
243
244 ::
245
246   294: prog_array  name jmp_table  flags 0x0
247           key 4B  value 4B  max_entries 1  memlock 4096B
248           owner_prog_type xdp  owner jited
249
250 |
251 | **# bpftool map pin id 294 /sys/fs/bpf/bar**
252 | **# bpftool map dump pinned /sys/fs/bpf/bar**
253
254 ::
255
256   Found 0 elements
257
258 |
259 | **# bpftool map update pinned /sys/fs/bpf/bar key 0 0 0 0 value pinned /sys/fs/bpf/foo/debug**
260 | **# bpftool map dump pinned /sys/fs/bpf/bar**
261
262 ::
263
264   key: 00 00 00 00  value: 22 02 00 00
265   Found 1 element
266
267 SEE ALSO
268 ========
269         **bpf**\ (2),
270         **bpf-helpers**\ (7),
271         **bpftool**\ (8),
272         **bpftool-prog**\ (8),
273         **bpftool-cgroup**\ (8),
274         **bpftool-feature**\ (8),
275         **bpftool-net**\ (8),
276         **bpftool-perf**\ (8),
277         **bpftool-btf**\ (8)