diff options
| -rw-r--r-- | tools/bpf/bpftool/Documentation/bpftool-map.rst | 55 | ||||
| -rw-r--r-- | tools/bpf/bpftool/Documentation/bpftool-prog.rst | 101 | ||||
| -rw-r--r-- | tools/bpf/bpftool/common.c | 4 | ||||
| -rw-r--r-- | tools/bpf/bpftool/json_writer.c | 6 | ||||
| -rw-r--r-- | tools/bpf/bpftool/main.h | 2 | ||||
| -rw-r--r-- | tools/bpf/bpftool/prog.c | 4 | ||||
| -rw-r--r-- | tools/bpf/bpftool/xlated_dumper.c | 7 |
7 files changed, 124 insertions, 55 deletions
diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst index 5318dcb2085e..3221be1b9ccc 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-map.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst | |||
| @@ -170,6 +170,61 @@ The following three commands are equivalent: | |||
| 170 | | **# bpftool map pin id 10 /sys/fs/bpf/map** | 170 | | **# bpftool map pin id 10 /sys/fs/bpf/map** |
| 171 | | **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00** | 171 | | **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00** |
| 172 | 172 | ||
| 173 | Note that map update can also be used in order to change the program references | ||
| 174 | hold by a program array map. This can be used, for example, to change the | ||
| 175 | programs used for tail-call jumps at runtime, without having to reload the | ||
| 176 | entry-point program. Below is an example for this use case: we load a program | ||
| 177 | defining a prog array map, and with a main function that contains a tail call | ||
| 178 | to other programs that can be used either to "process" packets or to "debug" | ||
| 179 | processing. Note that the prog array map MUST be pinned into the BPF virtual | ||
| 180 | file system for the map update to work successfully, as kernel flushes prog | ||
| 181 | array maps when they have no more references from user space (and the update | ||
| 182 | would be lost as soon as bpftool exits). | ||
| 183 | |||
| 184 | | | ||
| 185 | | **# bpftool prog loadall tail_calls.o /sys/fs/bpf/foo type xdp** | ||
| 186 | | **# bpftool prog --bpffs** | ||
| 187 | |||
| 188 | :: | ||
| 189 | |||
| 190 | 545: xdp name main_func tag 674b4b5597193dc3 gpl | ||
| 191 | loaded_at 2018-12-12T15:02:58+0000 uid 0 | ||
| 192 | xlated 240B jited 257B memlock 4096B map_ids 294 | ||
| 193 | pinned /sys/fs/bpf/foo/xdp | ||
| 194 | 546: xdp name bpf_func_process tag e369a529024751fc gpl | ||
| 195 | loaded_at 2018-12-12T15:02:58+0000 uid 0 | ||
| 196 | xlated 200B jited 164B memlock 4096B | ||
| 197 | pinned /sys/fs/bpf/foo/process | ||
| 198 | 547: xdp name bpf_func_debug tag 0b597868bc7f0976 gpl | ||
| 199 | loaded_at 2018-12-12T15:02:58+0000 uid 0 | ||
| 200 | xlated 200B jited 164B memlock 4096B | ||
| 201 | pinned /sys/fs/bpf/foo/debug | ||
| 202 | |||
| 203 | **# bpftool map** | ||
| 204 | |||
| 205 | :: | ||
| 206 | |||
| 207 | 294: prog_array name jmp_table flags 0x0 | ||
| 208 | key 4B value 4B max_entries 1 memlock 4096B | ||
| 209 | owner_prog_type xdp owner jited | ||
| 210 | |||
| 211 | | | ||
| 212 | | **# bpftool map pin id 294 /sys/fs/bpf/bar** | ||
| 213 | | **# bpftool map dump pinned /sys/fs/bpf/bar** | ||
| 214 | |||
| 215 | :: | ||
| 216 | |||
| 217 | Found 0 elements | ||
| 218 | |||
| 219 | | | ||
| 220 | | **# bpftool map update pinned /sys/fs/bpf/bar key 0 0 0 0 value pinned /sys/fs/bpf/foo/debug** | ||
| 221 | | **# bpftool map dump pinned /sys/fs/bpf/bar** | ||
| 222 | |||
| 223 | :: | ||
| 224 | |||
| 225 | key: 00 00 00 00 value: 22 02 00 00 | ||
| 226 | Found 1 element | ||
| 227 | |||
| 173 | SEE ALSO | 228 | SEE ALSO |
| 174 | ======== | 229 | ======== |
| 175 | **bpf**\ (2), | 230 | **bpf**\ (2), |
diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst index bb1aeb98b6da..53920ffc48dd 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst | |||
| @@ -158,83 +158,94 @@ OPTIONS | |||
| 158 | When showing BPF programs, show file names of pinned | 158 | When showing BPF programs, show file names of pinned |
| 159 | programs. | 159 | programs. |
| 160 | 160 | ||
| 161 | -m, --mapcompat | ||
| 162 | Allow loading maps with unknown map definitions. | ||
| 163 | |||
| 161 | EXAMPLES | 164 | EXAMPLES |
| 162 | ======== | 165 | ======== |
| 163 | **# bpftool prog show** | 166 | **# bpftool prog show** |
| 167 | |||
| 164 | :: | 168 | :: |
| 165 | 169 | ||
| 166 | 10: xdp name some_prog tag 005a3d2123620c8b gpl | 170 | 10: xdp name some_prog tag 005a3d2123620c8b gpl |
| 167 | loaded_at Sep 29/20:11 uid 0 | 171 | loaded_at 2017-09-29T20:11:00+0000 uid 0 |
| 168 | xlated 528B jited 370B memlock 4096B map_ids 10 | 172 | xlated 528B jited 370B memlock 4096B map_ids 10 |
| 169 | 173 | ||
| 170 | **# bpftool --json --pretty prog show** | 174 | **# bpftool --json --pretty prog show** |
| 171 | 175 | ||
| 172 | :: | 176 | :: |
| 173 | 177 | ||
| 174 | { | 178 | [{ |
| 175 | "programs": [{ | 179 | "id": 10, |
| 176 | "id": 10, | 180 | "type": "xdp", |
| 177 | "type": "xdp", | 181 | "tag": "005a3d2123620c8b", |
| 178 | "tag": "005a3d2123620c8b", | 182 | "gpl_compatible": true, |
| 179 | "gpl_compatible": true, | 183 | "loaded_at": 1506715860, |
| 180 | "loaded_at": "Sep 29/20:11", | 184 | "uid": 0, |
| 181 | "uid": 0, | 185 | "bytes_xlated": 528, |
| 182 | "bytes_xlated": 528, | 186 | "jited": true, |
| 183 | "jited": true, | 187 | "bytes_jited": 370, |
| 184 | "bytes_jited": 370, | 188 | "bytes_memlock": 4096, |
| 185 | "bytes_memlock": 4096, | 189 | "map_ids": [10 |
| 186 | "map_ids": [10 | 190 | ] |
| 187 | ] | 191 | } |
| 188 | } | 192 | ] |
| 189 | ] | ||
| 190 | } | ||
| 191 | 193 | ||
| 192 | | | 194 | | |
| 193 | | **# bpftool prog dump xlated id 10 file /tmp/t** | 195 | | **# bpftool prog dump xlated id 10 file /tmp/t** |
| 194 | | **# ls -l /tmp/t** | 196 | | **# ls -l /tmp/t** |
| 195 | | -rw------- 1 root root 560 Jul 22 01:42 /tmp/t | ||
| 196 | 197 | ||
| 197 | **# bpftool prog dum jited tag 005a3d2123620c8b** | 198 | :: |
| 199 | |||
| 200 | -rw------- 1 root root 560 Jul 22 01:42 /tmp/t | ||
| 201 | |||
| 202 | **# bpftool prog dump jited tag 005a3d2123620c8b** | ||
| 198 | 203 | ||
| 199 | :: | 204 | :: |
| 200 | 205 | ||
| 201 | push %rbp | 206 | 0: push %rbp |
| 202 | mov %rsp,%rbp | 207 | 1: mov %rsp,%rbp |
| 203 | sub $0x228,%rsp | 208 | 2: sub $0x228,%rsp |
| 204 | sub $0x28,%rbp | 209 | 3: sub $0x28,%rbp |
| 205 | mov %rbx,0x0(%rbp) | 210 | 4: mov %rbx,0x0(%rbp) |
| 206 | 211 | ||
| 207 | | | 212 | | |
| 208 | | **# mount -t bpf none /sys/fs/bpf/** | 213 | | **# mount -t bpf none /sys/fs/bpf/** |
| 209 | | **# bpftool prog pin id 10 /sys/fs/bpf/prog** | 214 | | **# bpftool prog pin id 10 /sys/fs/bpf/prog** |
| 210 | | **# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2** | 215 | | **# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2** |
| 211 | | **# ls -l /sys/fs/bpf/** | 216 | | **# ls -l /sys/fs/bpf/** |
| 212 | | -rw------- 1 root root 0 Jul 22 01:43 prog | ||
| 213 | | -rw------- 1 root root 0 Jul 22 01:44 prog2 | ||
| 214 | 217 | ||
| 215 | **# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes** | 218 | :: |
| 219 | |||
| 220 | -rw------- 1 root root 0 Jul 22 01:43 prog | ||
| 221 | -rw------- 1 root root 0 Jul 22 01:44 prog2 | ||
| 222 | |||
| 223 | **# bpftool prog dump jited pinned /sys/fs/bpf/prog opcodes** | ||
| 216 | 224 | ||
| 217 | :: | 225 | :: |
| 218 | 226 | ||
| 219 | push %rbp | 227 | 0: push %rbp |
| 220 | 55 | 228 | 55 |
| 221 | mov %rsp,%rbp | 229 | 1: mov %rsp,%rbp |
| 222 | 48 89 e5 | 230 | 48 89 e5 |
| 223 | sub $0x228,%rsp | 231 | 4: sub $0x228,%rsp |
| 224 | 48 81 ec 28 02 00 00 | 232 | 48 81 ec 28 02 00 00 |
| 225 | sub $0x28,%rbp | 233 | b: sub $0x28,%rbp |
| 226 | 48 83 ed 28 | 234 | 48 83 ed 28 |
| 227 | mov %rbx,0x0(%rbp) | 235 | f: mov %rbx,0x0(%rbp) |
| 228 | 48 89 5d 00 | 236 | 48 89 5d 00 |
| 229 | 237 | ||
| 230 | | | 238 | | |
| 231 | | **# bpftool prog load xdp1_kern.o /sys/fs/bpf/xdp1 type xdp map name rxcnt id 7** | 239 | | **# bpftool prog load xdp1_kern.o /sys/fs/bpf/xdp1 type xdp map name rxcnt id 7** |
| 232 | | **# bpftool prog show pinned /sys/fs/bpf/xdp1** | 240 | | **# bpftool prog show pinned /sys/fs/bpf/xdp1** |
| 233 | | 9: xdp name xdp_prog1 tag 539ec6ce11b52f98 gpl | 241 | |
| 234 | | loaded_at 2018-06-25T16:17:31-0700 uid 0 | 242 | :: |
| 235 | | xlated 488B jited 336B memlock 4096B map_ids 7 | 243 | |
| 236 | | **# rm /sys/fs/bpf/xdp1** | 244 | 9: xdp name xdp_prog1 tag 539ec6ce11b52f98 gpl |
| 237 | | | 245 | loaded_at 2018-06-25T16:17:31-0700 uid 0 |
| 246 | xlated 488B jited 336B memlock 4096B map_ids 7 | ||
| 247 | |||
| 248 | **# rm /sys/fs/bpf/xdp1** | ||
| 238 | 249 | ||
| 239 | SEE ALSO | 250 | SEE ALSO |
| 240 | ======== | 251 | ======== |
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 99e4027dde75..24582e8a96fb 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c | |||
| @@ -28,7 +28,7 @@ | |||
| 28 | #define BPF_FS_MAGIC 0xcafe4a11 | 28 | #define BPF_FS_MAGIC 0xcafe4a11 |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| 31 | void p_err(const char *fmt, ...) | 31 | void __printf(1, 2) p_err(const char *fmt, ...) |
| 32 | { | 32 | { |
| 33 | va_list ap; | 33 | va_list ap; |
| 34 | 34 | ||
| @@ -46,7 +46,7 @@ void p_err(const char *fmt, ...) | |||
| 46 | va_end(ap); | 46 | va_end(ap); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | void p_info(const char *fmt, ...) | 49 | void __printf(1, 2) p_info(const char *fmt, ...) |
| 50 | { | 50 | { |
| 51 | va_list ap; | 51 | va_list ap; |
| 52 | 52 | ||
diff --git a/tools/bpf/bpftool/json_writer.c b/tools/bpf/bpftool/json_writer.c index a07d17918725..bff7ee026680 100644 --- a/tools/bpf/bpftool/json_writer.c +++ b/tools/bpf/bpftool/json_writer.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <malloc.h> | 20 | #include <malloc.h> |
| 21 | #include <inttypes.h> | 21 | #include <inttypes.h> |
| 22 | #include <stdint.h> | 22 | #include <stdint.h> |
| 23 | #include <linux/compiler.h> | ||
| 23 | 24 | ||
| 24 | #include "json_writer.h" | 25 | #include "json_writer.h" |
| 25 | 26 | ||
| @@ -157,7 +158,8 @@ void jsonw_name(json_writer_t *self, const char *name) | |||
| 157 | putc(' ', self->out); | 158 | putc(' ', self->out); |
| 158 | } | 159 | } |
| 159 | 160 | ||
| 160 | void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap) | 161 | void __printf(2, 0) |
| 162 | jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap) | ||
| 161 | { | 163 | { |
| 162 | jsonw_eor(self); | 164 | jsonw_eor(self); |
| 163 | putc('"', self->out); | 165 | putc('"', self->out); |
| @@ -165,7 +167,7 @@ void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap) | |||
| 165 | putc('"', self->out); | 167 | putc('"', self->out); |
| 166 | } | 168 | } |
| 167 | 169 | ||
| 168 | void jsonw_printf(json_writer_t *self, const char *fmt, ...) | 170 | void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...) |
| 169 | { | 171 | { |
| 170 | va_list ap; | 172 | va_list ap; |
| 171 | 173 | ||
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index d2beb88f0e2e..9487345b04a7 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h | |||
| @@ -147,8 +147,8 @@ int prog_parse_fd(int *argc, char ***argv); | |||
| 147 | int map_parse_fd(int *argc, char ***argv); | 147 | int map_parse_fd(int *argc, char ***argv); |
| 148 | int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len); | 148 | int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len); |
| 149 | 149 | ||
| 150 | #ifdef HAVE_LIBBFD_SUPPORT | ||
| 151 | struct bpf_prog_linfo; | 150 | struct bpf_prog_linfo; |
| 151 | #ifdef HAVE_LIBBFD_SUPPORT | ||
| 152 | void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, | 152 | void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, |
| 153 | const char *arch, const char *disassembler_options, | 153 | const char *arch, const char *disassembler_options, |
| 154 | const struct btf *btf, | 154 | const struct btf *btf, |
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index ee51279be9c7..2d1bb7d6ff51 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c | |||
| @@ -32,7 +32,7 @@ static const char * const attach_type_strings[] = { | |||
| 32 | [__MAX_BPF_ATTACH_TYPE] = NULL, | 32 | [__MAX_BPF_ATTACH_TYPE] = NULL, |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | enum bpf_attach_type parse_attach_type(const char *str) | 35 | static enum bpf_attach_type parse_attach_type(const char *str) |
| 36 | { | 36 | { |
| 37 | enum bpf_attach_type type; | 37 | enum bpf_attach_type type; |
| 38 | 38 | ||
| @@ -798,7 +798,7 @@ struct map_replace { | |||
| 798 | char *name; | 798 | char *name; |
| 799 | }; | 799 | }; |
| 800 | 800 | ||
| 801 | int map_replace_compar(const void *p1, const void *p2) | 801 | static int map_replace_compar(const void *p1, const void *p2) |
| 802 | { | 802 | { |
| 803 | const struct map_replace *a = p1, *b = p2; | 803 | const struct map_replace *a = p1, *b = p2; |
| 804 | 804 | ||
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index 640ffe86a655..7073dbe1ff27 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c | |||
| @@ -81,7 +81,7 @@ struct kernel_sym *kernel_syms_search(struct dump_data *dd, | |||
| 81 | sizeof(*dd->sym_mapping), kernel_syms_cmp) : NULL; | 81 | sizeof(*dd->sym_mapping), kernel_syms_cmp) : NULL; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | static void print_insn(void *private_data, const char *fmt, ...) | 84 | static void __printf(2, 3) print_insn(void *private_data, const char *fmt, ...) |
| 85 | { | 85 | { |
| 86 | va_list args; | 86 | va_list args; |
| 87 | 87 | ||
| @@ -90,7 +90,7 @@ static void print_insn(void *private_data, const char *fmt, ...) | |||
| 90 | va_end(args); | 90 | va_end(args); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | static void | 93 | static void __printf(2, 3) |
| 94 | print_insn_for_graph(void *private_data, const char *fmt, ...) | 94 | print_insn_for_graph(void *private_data, const char *fmt, ...) |
| 95 | { | 95 | { |
| 96 | char buf[64], *p; | 96 | char buf[64], *p; |
| @@ -121,7 +121,8 @@ print_insn_for_graph(void *private_data, const char *fmt, ...) | |||
| 121 | printf("%s", buf); | 121 | printf("%s", buf); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | static void print_insn_json(void *private_data, const char *fmt, ...) | 124 | static void __printf(2, 3) |
| 125 | print_insn_json(void *private_data, const char *fmt, ...) | ||
| 125 | { | 126 | { |
| 126 | unsigned int l = strlen(fmt); | 127 | unsigned int l = strlen(fmt); |
| 127 | char chomped_fmt[l]; | 128 | char chomped_fmt[l]; |
