diff options
Diffstat (limited to 'tools/bpf/bpftool')
| -rw-r--r-- | tools/bpf/bpftool/Makefile | 9 | ||||
| -rw-r--r-- | tools/bpf/bpftool/btf_dumper.c | 13 | ||||
| -rw-r--r-- | tools/bpf/bpftool/common.c | 6 | ||||
| -rw-r--r-- | tools/bpf/bpftool/json_writer.c | 7 | ||||
| -rw-r--r-- | tools/bpf/bpftool/json_writer.h | 5 | ||||
| -rw-r--r-- | tools/bpf/bpftool/map.c | 33 | ||||
| -rw-r--r-- | tools/bpf/bpftool/prog.c | 5 |
7 files changed, 44 insertions, 34 deletions
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index 492f0f24e2d3..4ad1f0894d53 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile | |||
| @@ -93,9 +93,16 @@ BFD_SRCS = jit_disasm.c | |||
| 93 | SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) | 93 | SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) |
| 94 | 94 | ||
| 95 | ifeq ($(feature-libbfd),1) | 95 | ifeq ($(feature-libbfd),1) |
| 96 | LIBS += -lbfd -ldl -lopcodes | ||
| 97 | else ifeq ($(feature-libbfd-liberty),1) | ||
| 98 | LIBS += -lbfd -ldl -lopcodes -liberty | ||
| 99 | else ifeq ($(feature-libbfd-liberty-z),1) | ||
| 100 | LIBS += -lbfd -ldl -lopcodes -liberty -lz | ||
| 101 | endif | ||
| 102 | |||
| 103 | ifneq ($(filter -lbfd,$(LIBS)),) | ||
| 96 | CFLAGS += -DHAVE_LIBBFD_SUPPORT | 104 | CFLAGS += -DHAVE_LIBBFD_SUPPORT |
| 97 | SRCS += $(BFD_SRCS) | 105 | SRCS += $(BFD_SRCS) |
| 98 | LIBS += -lbfd -lopcodes | ||
| 99 | endif | 106 | endif |
| 100 | 107 | ||
| 101 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o | 108 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index 3f0629edbca5..6ba5f567a9d8 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c | |||
| @@ -82,8 +82,6 @@ static void btf_dumper_bitfield(__u32 nr_bits, __u8 bit_offset, | |||
| 82 | int bits_to_copy; | 82 | int bits_to_copy; |
| 83 | __u64 print_num; | 83 | __u64 print_num; |
| 84 | 84 | ||
| 85 | data += BITS_ROUNDDOWN_BYTES(bit_offset); | ||
| 86 | bit_offset = BITS_PER_BYTE_MASKED(bit_offset); | ||
| 87 | bits_to_copy = bit_offset + nr_bits; | 85 | bits_to_copy = bit_offset + nr_bits; |
| 88 | bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy); | 86 | bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy); |
| 89 | 87 | ||
| @@ -118,7 +116,9 @@ static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset, | |||
| 118 | * BTF_INT_OFFSET() cannot exceed 64 bits. | 116 | * BTF_INT_OFFSET() cannot exceed 64 bits. |
| 119 | */ | 117 | */ |
| 120 | total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type); | 118 | total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type); |
| 121 | btf_dumper_bitfield(nr_bits, total_bits_offset, data, jw, | 119 | data += BITS_ROUNDDOWN_BYTES(total_bits_offset); |
| 120 | bit_offset = BITS_PER_BYTE_MASKED(total_bits_offset); | ||
| 121 | btf_dumper_bitfield(nr_bits, bit_offset, data, jw, | ||
| 122 | is_plain_text); | 122 | is_plain_text); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| @@ -216,11 +216,12 @@ static int btf_dumper_struct(const struct btf_dumper *d, __u32 type_id, | |||
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | jsonw_name(d->jw, btf__name_by_offset(d->btf, m[i].name_off)); | 218 | jsonw_name(d->jw, btf__name_by_offset(d->btf, m[i].name_off)); |
| 219 | data_off = data + BITS_ROUNDDOWN_BYTES(bit_offset); | ||
| 219 | if (bitfield_size) { | 220 | if (bitfield_size) { |
| 220 | btf_dumper_bitfield(bitfield_size, bit_offset, | 221 | btf_dumper_bitfield(bitfield_size, |
| 221 | data, d->jw, d->is_plain_text); | 222 | BITS_PER_BYTE_MASKED(bit_offset), |
| 223 | data_off, d->jw, d->is_plain_text); | ||
| 222 | } else { | 224 | } else { |
| 223 | data_off = data + BITS_ROUNDDOWN_BYTES(bit_offset); | ||
| 224 | ret = btf_dumper_do_type(d, m[i].type, | 225 | ret = btf_dumper_do_type(d, m[i].type, |
| 225 | BITS_PER_BYTE_MASKED(bit_offset), | 226 | BITS_PER_BYTE_MASKED(bit_offset), |
| 226 | data_off); | 227 | data_off); |
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 897483457bf0..f7261fad45c1 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c | |||
| @@ -297,10 +297,8 @@ char *get_fdinfo(int fd, const char *key) | |||
| 297 | snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); | 297 | snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); |
| 298 | 298 | ||
| 299 | fdi = fopen(path, "r"); | 299 | fdi = fopen(path, "r"); |
| 300 | if (!fdi) { | 300 | if (!fdi) |
| 301 | p_err("can't open fdinfo: %s", strerror(errno)); | ||
| 302 | return NULL; | 301 | return NULL; |
| 303 | } | ||
| 304 | 302 | ||
| 305 | while ((n = getline(&line, &line_n, fdi)) > 0) { | 303 | while ((n = getline(&line, &line_n, fdi)) > 0) { |
| 306 | char *value; | 304 | char *value; |
| @@ -313,7 +311,6 @@ char *get_fdinfo(int fd, const char *key) | |||
| 313 | 311 | ||
| 314 | value = strchr(line, '\t'); | 312 | value = strchr(line, '\t'); |
| 315 | if (!value || !value[1]) { | 313 | if (!value || !value[1]) { |
| 316 | p_err("malformed fdinfo!?"); | ||
| 317 | free(line); | 314 | free(line); |
| 318 | return NULL; | 315 | return NULL; |
| 319 | } | 316 | } |
| @@ -326,7 +323,6 @@ char *get_fdinfo(int fd, const char *key) | |||
| 326 | return line; | 323 | return line; |
| 327 | } | 324 | } |
| 328 | 325 | ||
| 329 | p_err("key '%s' not found in fdinfo", key); | ||
| 330 | free(line); | 326 | free(line); |
| 331 | fclose(fdi); | 327 | fclose(fdi); |
| 332 | return NULL; | 328 | return NULL; |
diff --git a/tools/bpf/bpftool/json_writer.c b/tools/bpf/bpftool/json_writer.c index bff7ee026680..6046dcab51cc 100644 --- a/tools/bpf/bpftool/json_writer.c +++ b/tools/bpf/bpftool/json_writer.c | |||
| @@ -1,15 +1,10 @@ | |||
| 1 | // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) |
| 2 | /* | 2 | /* |
| 3 | * Simple streaming JSON writer | 3 | * Simple streaming JSON writer |
| 4 | * | 4 | * |
| 5 | * This takes care of the annoying bits of JSON syntax like the commas | 5 | * This takes care of the annoying bits of JSON syntax like the commas |
| 6 | * after elements | 6 | * after elements |
| 7 | * | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License | ||
| 10 | * as published by the Free Software Foundation; either version | ||
| 11 | * 2 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * Authors: Stephen Hemminger <stephen@networkplumber.org> | 8 | * Authors: Stephen Hemminger <stephen@networkplumber.org> |
| 14 | */ | 9 | */ |
| 15 | 10 | ||
diff --git a/tools/bpf/bpftool/json_writer.h b/tools/bpf/bpftool/json_writer.h index c1ab51aed99c..cb9a1993681c 100644 --- a/tools/bpf/bpftool/json_writer.h +++ b/tools/bpf/bpftool/json_writer.h | |||
| @@ -5,11 +5,6 @@ | |||
| 5 | * This takes care of the annoying bits of JSON syntax like the commas | 5 | * This takes care of the annoying bits of JSON syntax like the commas |
| 6 | * after elements | 6 | * after elements |
| 7 | * | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License | ||
| 10 | * as published by the Free Software Foundation; either version | ||
| 11 | * 2 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * Authors: Stephen Hemminger <stephen@networkplumber.org> | 8 | * Authors: Stephen Hemminger <stephen@networkplumber.org> |
| 14 | */ | 9 | */ |
| 15 | 10 | ||
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 2037e3dc864b..1ef1ee2280a2 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c | |||
| @@ -347,6 +347,20 @@ static char **parse_bytes(char **argv, const char *name, unsigned char *val, | |||
| 347 | return argv + i; | 347 | return argv + i; |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | /* on per cpu maps we must copy the provided value on all value instances */ | ||
| 351 | static void fill_per_cpu_value(struct bpf_map_info *info, void *value) | ||
| 352 | { | ||
| 353 | unsigned int i, n, step; | ||
| 354 | |||
| 355 | if (!map_is_per_cpu(info->type)) | ||
| 356 | return; | ||
| 357 | |||
| 358 | n = get_possible_cpus(); | ||
| 359 | step = round_up(info->value_size, 8); | ||
| 360 | for (i = 1; i < n; i++) | ||
| 361 | memcpy(value + i * step, value, info->value_size); | ||
| 362 | } | ||
| 363 | |||
| 350 | static int parse_elem(char **argv, struct bpf_map_info *info, | 364 | static int parse_elem(char **argv, struct bpf_map_info *info, |
| 351 | void *key, void *value, __u32 key_size, __u32 value_size, | 365 | void *key, void *value, __u32 key_size, __u32 value_size, |
| 352 | __u32 *flags, __u32 **value_fd) | 366 | __u32 *flags, __u32 **value_fd) |
| @@ -426,6 +440,8 @@ static int parse_elem(char **argv, struct bpf_map_info *info, | |||
| 426 | argv = parse_bytes(argv, "value", value, value_size); | 440 | argv = parse_bytes(argv, "value", value, value_size); |
| 427 | if (!argv) | 441 | if (!argv) |
| 428 | return -1; | 442 | return -1; |
| 443 | |||
| 444 | fill_per_cpu_value(info, value); | ||
| 429 | } | 445 | } |
| 430 | 446 | ||
| 431 | return parse_elem(argv, info, key, NULL, key_size, value_size, | 447 | return parse_elem(argv, info, key, NULL, key_size, value_size, |
| @@ -497,10 +513,9 @@ static int show_map_close_json(int fd, struct bpf_map_info *info) | |||
| 497 | jsonw_uint_field(json_wtr, "owner_prog_type", | 513 | jsonw_uint_field(json_wtr, "owner_prog_type", |
| 498 | prog_type); | 514 | prog_type); |
| 499 | } | 515 | } |
| 500 | if (atoi(owner_jited)) | 516 | if (owner_jited) |
| 501 | jsonw_bool_field(json_wtr, "owner_jited", true); | 517 | jsonw_bool_field(json_wtr, "owner_jited", |
| 502 | else | 518 | !!atoi(owner_jited)); |
| 503 | jsonw_bool_field(json_wtr, "owner_jited", false); | ||
| 504 | 519 | ||
| 505 | free(owner_prog_type); | 520 | free(owner_prog_type); |
| 506 | free(owner_jited); | 521 | free(owner_jited); |
| @@ -553,7 +568,8 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info) | |||
| 553 | char *owner_prog_type = get_fdinfo(fd, "owner_prog_type"); | 568 | char *owner_prog_type = get_fdinfo(fd, "owner_prog_type"); |
| 554 | char *owner_jited = get_fdinfo(fd, "owner_jited"); | 569 | char *owner_jited = get_fdinfo(fd, "owner_jited"); |
| 555 | 570 | ||
| 556 | printf("\n\t"); | 571 | if (owner_prog_type || owner_jited) |
| 572 | printf("\n\t"); | ||
| 557 | if (owner_prog_type) { | 573 | if (owner_prog_type) { |
| 558 | unsigned int prog_type = atoi(owner_prog_type); | 574 | unsigned int prog_type = atoi(owner_prog_type); |
| 559 | 575 | ||
| @@ -563,10 +579,9 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info) | |||
| 563 | else | 579 | else |
| 564 | printf("owner_prog_type %d ", prog_type); | 580 | printf("owner_prog_type %d ", prog_type); |
| 565 | } | 581 | } |
| 566 | if (atoi(owner_jited)) | 582 | if (owner_jited) |
| 567 | printf("owner jited"); | 583 | printf("owner%s jited", |
| 568 | else | 584 | atoi(owner_jited) ? "" : " not"); |
| 569 | printf("owner not jited"); | ||
| 570 | 585 | ||
| 571 | free(owner_prog_type); | 586 | free(owner_prog_type); |
| 572 | free(owner_jited); | 587 | free(owner_jited); |
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 2d1bb7d6ff51..b54ed82b9589 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c | |||
| @@ -78,13 +78,14 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size) | |||
| 78 | 78 | ||
| 79 | static int prog_fd_by_tag(unsigned char *tag) | 79 | static int prog_fd_by_tag(unsigned char *tag) |
| 80 | { | 80 | { |
| 81 | struct bpf_prog_info info = {}; | ||
| 82 | __u32 len = sizeof(info); | ||
| 83 | unsigned int id = 0; | 81 | unsigned int id = 0; |
| 84 | int err; | 82 | int err; |
| 85 | int fd; | 83 | int fd; |
| 86 | 84 | ||
| 87 | while (true) { | 85 | while (true) { |
| 86 | struct bpf_prog_info info = {}; | ||
| 87 | __u32 len = sizeof(info); | ||
| 88 | |||
| 88 | err = bpf_prog_get_next_id(id, &id); | 89 | err = bpf_prog_get_next_id(id, &id); |
| 89 | if (err) { | 90 | if (err) { |
| 90 | p_err("%s", strerror(errno)); | 91 | p_err("%s", strerror(errno)); |
