bpftool: miscellaneous fixes
Subsystems (4)
cover bpftool: miscellaneous fixes
This set contains several independent minor fixes for bpftool, its Makefile, and its documentation. Please refer to individual commits for details.
Quentin Monnet (6):
bpftool: Fix memory leak in prog_dump()
bpftool: Remove inclusion of utilities.mak from Makefiles
bpftool: Use $(OUTPUT) and not $(O) for VMLINUX_BTF_PATHS in Makefile
bpftool: Fix indent in option lists in the documentation
bpftool: Update the lists of names for maps and prog-attach types
bpftool: Fix mixed indentation in documentation
tools/bpf/bpftool/Documentation/Makefile | 1 - .../bpf/bpftool/Documentation/bpftool-btf.rst | 2 +- .../bpftool/Documentation/bpftool-cgroup.rst | 12 ++-- .../bpf/bpftool/Documentation/bpftool-gen.rst | 2 +- .../bpftool/Documentation/bpftool-link.rst | 2 +- .../bpf/bpftool/Documentation/bpftool-map.rst | 8 +-- .../bpf/bpftool/Documentation/bpftool-net.rst | 62 +++++++++---------- .../bpftool/Documentation/bpftool-prog.rst | 8 +-- tools/bpf/bpftool/Documentation/bpftool.rst | 6 +- tools/bpf/bpftool/Makefile | 3 +- tools/bpf/bpftool/bash-completion/bpftool | 3 +- tools/bpf/bpftool/common.c | 1 + tools/bpf/bpftool/map.c | 3 +- tools/bpf/bpftool/prog.c | 15 +++-- 14 files changed, 66 insertions(+), 62 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/6 bpftool: Fix memory leak in prog_dump()
Following the extraction of prog_dump() from do_dump(), the struct btf allocated in prog_dump() is no longer freed on error; the struct bpf_prog_linfo is not freed at all. Make sure we release them before exiting the function.
--- tools/bpf/bpftool/prog.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
tools/bpf/bpftool/prog.c +9 -6
@@ -709,8 +709,8 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,char func_sig[1024 ];unsigned char *buf;__u32 member_len; +int fd, err =-1 ;ssize_t n; -int fd;if (mode ==DUMP_JITED ) {if (info->jited_prog_len ==0 || !info->jited_prog_insns) {
@@ -749,7 +749,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,if (fd <0 ) {p_err ("can't open file %s: %s" , filepath,strerror (errno)); -return -1 ; + goto exit_free; } n =write (fd, buf, member_len);
@@ -757,7 +757,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,if (n != (ssize_t )member_len) {p_err ("error writing output file: %s" , n <0 ?strerror (errno) :"short write" ); -return -1 ; + goto exit_free; }if (json_output)
@@ -771,7 +771,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, info->netns_ino, &disasm_opt);if (!name) -return -1 ; + goto exit_free; }if (info->nr_jited_func_lens && info->jited_func_lens) {
@@ -866,9 +866,12 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,kernel_syms_destroy (&dd); } -btf__free (btf); + err =0 ; -return 0 ; +exit_free: +btf__free (btf); +bpf_prog_linfo__free (prog_linfo); +return err; }static int do_dump (int argc,char **argv)
Signature · 1 line
2.32.0
PATCH 2/6 bpftool: Remove inclusion of utilities.mak from Makefiles
In reply to Quentin MonnetBpftool's Makefile, and the Makefile for its documentation, both include scripts/utilities.mak, but they use none of the items defined in this file. Remove the includes.
--- tools/bpf/bpftool/Documentation/Makefile | 1 - tools/bpf/bpftool/Makefile | 1 - 2 files changed, 2 deletions(-)
tools/bpf/bpftool/Documentation/Makefile +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only include ../../../scripts/Makefile.include -include ../../../scripts/utilities.mak INSTALL ?= install RM ?= rm -f
tools/bpf/bpftool/Makefile +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only include ../../scripts/Makefile.include -include ../../scripts/utilities.mak ifeq ($(srctree),) srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Signature · 1 line
2.32.0
PATCH 3/6 bpftool: Use $(OUTPUT) and not $(O) for VMLINUX_BTF_PATHS in Makefile
In reply to Quentin MonnetThe Makefile for bpftool relies on $(OUTPUT), and not on $(O), for passing the output directory. So $(VMLINUX_BTF_PATHS), used for searching for kernel BTF info, should use the same variable.
--- tools/bpf/bpftool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/Makefile +1 -1
@@ -150,7 +150,7 @@ $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o $(OBJS): $(LIBBPF) $(LIBBPF_INTERNAL_HDRS) -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +VMLINUX_BTF_PATHS ?= $(if $(OUTPUT),$(OUTPUT)/vmlinux) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ ../../../vmlinux \ /sys/kernel/btf/vmlinux \
Signature · 1 line
2.32.0
Re: [PATCH bpf-next 3/6] bpftool: Use $(OUTPUT) and not $(O) for VMLINUX_BTF_PATHS in Makefile
Quoted 16 lines · Quentin Monnet
The
Makefilefor bpftool relies on $(OUTPUT), and not on $(O), for passing the output directory. So $(VMLINUX_BTF_PATHS), used for searching for kernel BTF info, should use the same variable.Fixes 05aca6da3b5a ("tools/bpftool: Generalize BPF skeleton support and generate vmlinux.h")Signed-off-by Quentin Monnet <[email protected]>--- tools/bpf/bpftool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/bpftool/Makefile +0
-0
tools/bpf/bpftool/Makefile $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) · line 154
Quoted 6 lines
tools/bpf/bpftool/Makefile +1
-1@@ -150,7 +150,7 @@ $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o $(OBJS): $(LIBBPF) $(LIBBPF_INTERNAL_HDRS) -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +VMLINUX_BTF_PATHS ?= $(if $(OUTPUT),$(OUTPUT)/vmlinux) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
But you still check KBUILD_OUTPUT? O overrides KBUILD_OUTPUT as far as kernel build goes. So if you still support KBUILD_OUTPUT, you should support O. And the $(OUTPUT) seems to be completely unrelated, as that defines the output of bpftool build files, not the vmlinux image. Or am I missing something?
Quoted 5 lines
tools/bpf/bpftool/Makefile +0
-1../../../vmlinux \ /sys/kernel/btf/vmlinux \ --2.32.0
Re: [PATCH bpf-next 3/6] bpftool: Use $(OUTPUT) and not $(O) for VMLINUX_BTF_PATHS in Makefile
Quoted 21 lines · Andrii Nakryiko
Quoted 19 lines · Quentin Monnet
The
Makefilefor bpftool relies on $(OUTPUT), and not on $(O), for passing the output directory. So $(VMLINUX_BTF_PATHS), used for searching for kernel BTF info, should use the same variable.Fixes 05aca6da3b5a ("tools/bpftool: Generalize BPF skeleton support and generate vmlinux.h")Signed-off-by Quentin Monnet <[email protected]>--- tools/bpf/bpftool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/bpftool/Makefile +0
-0@@ -150,7 +150,7 @@ $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o $(OBJS): $(LIBBPF) $(LIBBPF_INTERNAL_HDRS)
Quoted 9 lines
tools/bpf/bpftool/Makefile $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) · line 154
Quoted 3 lines
tools/bpf/bpftool/Makefile +1
-1-VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +VMLINUX_BTF_PATHS ?= $(if $(OUTPUT),$(OUTPUT)/vmlinux) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \But you still check
KBUILD_OUTPUT? O overridesKBUILD_OUTPUTas far as kernel build goes. So if you still supportKBUILD_OUTPUT, you should support O. And the $(OUTPUT) seems to be completely unrelated, as that defines the output of bpftool build files, not the vmlinux image. Or am I missing something?
OK, I think I'm the one who missed the point. I simply figured we meant to search the output directory, and that it should be $(OUTPUT) like everywhere else in the Makefile. But from what I understand now, it's not the case. Let's drop this patch.
If the rest of the set looks good to you, can you just skip this patch, or do you prefer me to send a v2?
Quentin
Re: [PATCH bpf-next 3/6] bpftool: Use $(OUTPUT) and not $(O) for VMLINUX_BTF_PATHS in Makefile
Quoted 33 lines · Quentin Monnet
Quoted 21 lines · Andrii Nakryiko
Quoted 19 lines · Quentin Monnet
The
Makefilefor bpftool relies on $(OUTPUT), and not on $(O), for passing the output directory. So $(VMLINUX_BTF_PATHS), used for searching for kernel BTF info, should use the same variable.Fixes 05aca6da3b5a ("tools/bpftool: Generalize BPF skeleton support and generate vmlinux.h")Signed-off-by Quentin Monnet <[email protected]>--- tools/bpf/bpftool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/bpftool/Makefile +0
-0@@ -150,7 +150,7 @@ $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o $(OBJS): $(LIBBPF) $(LIBBPF_INTERNAL_HDRS)Quoted 9 lines
tools/bpf/bpftool/Makefile $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) · line 154
Quoted 3 lines
tools/bpf/bpftool/Makefile +1
-1-VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ +VMLINUX_BTF_PATHS ?= $(if $(OUTPUT),$(OUTPUT)/vmlinux) \ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \But you still check
KBUILD_OUTPUT? O overridesKBUILD_OUTPUTas far as kernel build goes. So if you still supportKBUILD_OUTPUT, you should support O. And the $(OUTPUT) seems to be completely unrelated, as that defines the output of bpftool build files, not the vmlinux image. Or am I missing something?
Quoted 8 lines
OK, I think I'm the one who missed the point. I simply figured we meant to search the output directory, and that it should be $(OUTPUT) like everywhere else in the
Makefile. But from what I understand now, it's not the case. Let's drop this patch.If the rest of the set looks good to you, can you just skip this patch, or do you prefer me to send a v2?
I can just drop it when applying.
Quoted 1 line
Quentin
PATCH 4/6 bpftool: Fix indent in option lists in the documentation
In reply to Quentin MonnetMixed indentation levels in the lists of options in bpftool's documentation produces some unexpected results. For the "bpftool" man page, it prints a warning:
$ make -C bpftool.8
GEN bpftool.8
<stdin>:26: (ERROR/3) Unexpected indentation.For other pages, there is no warning, but it results in a line break appearing in the option lists in the generated man pages.
RST paragraphs should have a uniform indentation level. Let's fix it.
--- tools/bpf/bpftool/Documentation/bpftool-btf.rst | 2 +- tools/bpf/bpftool/Documentation/bpftool-cgroup.rst | 2 +- tools/bpf/bpftool/Documentation/bpftool-gen.rst | 2 +- tools/bpf/bpftool/Documentation/bpftool-link.rst | 2 +- tools/bpf/bpftool/Documentation/bpftool-map.rst | 6 +++--- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 8 ++++---- tools/bpf/bpftool/Documentation/bpftool.rst | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-btf.rst +1 -1
@@ -13,7 +13,7 @@ SYNOPSIS **bpftool** [*OPTIONS*] **btf** *COMMAND* *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | {**-d** | **--debug** } | - { **-B** | **--base-btf** } } + { **-B** | **--base-btf** } } *COMMANDS* := { **dump** | **help** }
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst +1 -1
@@ -13,7 +13,7 @@ SYNOPSIS **bpftool** [*OPTIONS*] **cgroup** *COMMAND* *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | - { **-f** | **--bpffs** } } + { **-f** | **--bpffs** } } *COMMANDS* := { **show** | **list** | **tree** | **attach** | **detach** | **help** }
tools/bpf/bpftool/Documentation/bpftool-gen.rst +1 -1
@@ -13,7 +13,7 @@ SYNOPSIS **bpftool** [*OPTIONS*] **gen** *COMMAND* *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | - { **-L** | **--use-loader** } } + { **-L** | **--use-loader** } } *COMMAND* := { **object** | **skeleton** | **help** }
tools/bpf/bpftool/Documentation/bpftool-link.rst +1 -1
@@ -13,7 +13,7 @@ SYNOPSIS **bpftool** [*OPTIONS*] **link** *COMMAND* *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | - { **-f** | **--bpffs** } | { **-n** | **--nomount** } } + { **-f** | **--bpffs** } | { **-n** | **--nomount** } } *COMMANDS* := { **show** | **list** | **pin** | **help** }
tools/bpf/bpftool/Documentation/bpftool-map.rst +3 -3
@@ -13,11 +13,11 @@ SYNOPSIS **bpftool** [*OPTIONS*] **map** *COMMAND* *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | - { **-f** | **--bpffs** } | { **-n** | **--nomount** } } + { **-f** | **--bpffs** } | { **-n** | **--nomount** } } *COMMANDS* := - { **show** | **list** | **create** | **dump** | **update** | **lookup** | **getnext** - | **delete** | **pin** | **help** } + { **show** | **list** | **create** | **dump** | **update** | **lookup** | **getnext** | + **delete** | **pin** | **help** } MAP COMMANDS =============
tools/bpf/bpftool/Documentation/bpftool-prog.rst +4 -4
@@ -13,12 +13,12 @@ SYNOPSIS **bpftool** [*OPTIONS*] **prog** *COMMAND* *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | - { **-f** | **--bpffs** } | { **-m** | **--mapcompat** } | { **-n** | **--nomount** } | - { **-L** | **--use-loader** } } + { **-f** | **--bpffs** } | { **-m** | **--mapcompat** } | { **-n** | **--nomount** } | + { **-L** | **--use-loader** } } *COMMANDS* := - { **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** - | **loadall** | **help** } + { **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** | + **loadall** | **help** } PROG COMMANDS =============
tools/bpf/bpftool/Documentation/bpftool.rst +3 -3
@@ -19,14 +19,14 @@ SYNOPSIS *OBJECT* := { **map** | **program** | **cgroup** | **perf** | **net** | **feature** } *OPTIONS* := { { **-V** | **--version** } | - { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } } + { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } } *MAP-COMMANDS* := { **show** | **list** | **create** | **dump** | **update** | **lookup** | **getnext** | - **delete** | **pin** | **event_pipe** | **help** } + **delete** | **pin** | **event_pipe** | **help** } *PROG-COMMANDS* := { **show** | **list** | **dump jited** | **dump xlated** | **pin** | - **load** | **attach** | **detach** | **help** } + **load** | **attach** | **detach** | **help** } *CGROUP-COMMANDS* := { **show** | **list** | **attach** | **detach** | **help** }
Signature · 1 line
2.32.0
PATCH 5/6 bpftool: Update the lists of names for maps and prog-attach types
In reply to Quentin MonnetTo support the different BPF map or attach types, bpftool must remain up-to-date with the types supported by the kernel. Let's update the lists, by adding the missing Bloom filter map type and the perf_event attach type.
Both missing items were found with test_bpftool_synctypes.py.
--- tools/bpf/bpftool/Documentation/bpftool-map.rst | 2 +- tools/bpf/bpftool/bash-completion/bpftool | 3 ++- tools/bpf/bpftool/common.c | 1 + tools/bpf/bpftool/map.c | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-map.rst +1 -1
@@ -52,7 +52,7 @@ MAP COMMANDS | | **devmap** | **devmap_hash** | **sockmap** | **cpumap** | **xskmap** | **sockhash** | | **cgroup_storage** | **reuseport_sockarray** | **percpu_cgroup_storage** | | **queue** | **stack** | **sk_storage** | **struct_ops** | **ringbuf** | **inode_storage** - | **task_storage** } +| | **task_storage** | **bloom_filter** } DESCRIPTION ===========
tools/bpf/bpftool/bash-completion/bpftool +2 -1
@@ -710,7 +710,8 @@ _bpftool() hash_of_maps devmap devmap_hash sockmap cpumap \ xskmap sockhash cgroup_storage reuseport_sockarray \ percpu_cgroup_storage queue stack sk_storage \ - struct_ops inode_storage task_storage ringbuf' + struct_ops ringbuf inode_storage task_storage \ + bloom_filter' COMPREPLY=( $( compgen -W "$BPFTOOL_MAP_CREATE_TYPES" -- "$cur" ) ) return 0 ;;
tools/bpf/bpftool/common.c +1 -0
@@ -74,6 +74,7 @@ const char * const attach_type_name[__MAX_BPF_ATTACH_TYPE] = { [BPF_XDP] = "xdp", [BPF_SK_REUSEPORT_SELECT] = "sk_skb_reuseport_select", [BPF_SK_REUSEPORT_SELECT_OR_MIGRATE] = "sk_skb_reuseport_select_or_migrate", + [BPF_PERF_EVENT] = "perf_event", };void p_err (const char *fmt, ...)
tools/bpf/bpftool/map.c +2 -1
@@ -53,6 +53,7 @@ const char * const map_type_name[] = { [BPF_MAP_TYPE_RINGBUF] = "ringbuf", [BPF_MAP_TYPE_INODE_STORAGE] = "inode_storage", [BPF_MAP_TYPE_TASK_STORAGE] = "task_storage", + [BPF_MAP_TYPE_BLOOM_FILTER] = "bloom_filter", };const size_t map_type_name_size =ARRAY_SIZE (map_type_name);
@@ -1477,7 +1478,7 @@ static int do_help(int argc, char **argv)" devmap | devmap_hash | sockmap | cpumap | xskmap | sockhash |\n" " cgroup_storage | reuseport_sockarray | percpu_cgroup_storage |\n" " queue | stack | sk_storage | struct_ops | ringbuf | inode_storage |\n" -" task_storage }\n" +" task_storage | bloom_filter }\n" " " HELP_SPEC_OPTIONS " |\n" " {-f|--bpffs} | {-n|--nomount} }\n" "",
Signature · 1 line
2.32.0
PATCH 6/6 bpftool: Fix mixed indentation in documentation
In reply to Quentin MonnetSome paragraphs in bpftool's documentation have a mix of tabs and spaces for indentation. Let's make it consistent.
This patch brings no change to the text content.
--- .../bpftool/Documentation/bpftool-cgroup.rst | 10 +-- .../bpf/bpftool/Documentation/bpftool-net.rst | 62 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst +5 -5
@@ -30,9 +30,9 @@ CGROUP COMMANDS | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } | *ATTACH_TYPE* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** | | **bind4** | **bind6** | **post_bind4** | **post_bind6** | **connect4** | **connect6** | -| **getpeername4** | **getpeername6** | **getsockname4** | **getsockname6** | **sendmsg4** | -| **sendmsg6** | **recvmsg4** | **recvmsg6** | **sysctl** | **getsockopt** | **setsockopt** | -| **sock_release** } +| **getpeername4** | **getpeername6** | **getsockname4** | **getsockname6** | **sendmsg4** | +| **sendmsg6** | **recvmsg4** | **recvmsg6** | **sysctl** | **getsockopt** | **setsockopt** | +| **sock_release** } | *ATTACH_FLAGS* := { **multi** | **override** } DESCRIPTION
@@ -98,9 +98,9 @@ DESCRIPTION **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an unconnected udp6 socket (since 4.18); **recvmsg4** call to recvfrom(2), recvmsg(2), recvmmsg(2) for - an unconnected udp4 socket (since 5.2); + an unconnected udp4 socket (since 5.2); **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for - an unconnected udp6 socket (since 5.2); + an unconnected udp6 socket (since 5.2); **sysctl** sysctl access (since 5.2); **getsockopt** call to getsockopt (since 5.3); **setsockopt** call to setsockopt (since 5.3);
tools/bpf/bpftool/Documentation/bpftool-net.rst +31 -31
75 lines not on this page · raw message
Signature · 1 line
2.32.0