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