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