Linux Audio

Check our new training course

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