bpf: make preloaded map iterators to display map elements countAdd another column to the /sys/fs/bpf/maps.debug iterator to displaycur_entries, the current number of entries in the map as is retur
bpf: make preloaded map iterators to display map elements countAdd another column to the /sys/fs/bpf/maps.debug iterator to displaycur_entries, the current number of entries in the map as is returnedby the bpf_map_sum_elem_count kfunc. Also fix formatting.Example: # cat /sys/fs/bpf/maps.debug id name max_entries cur_entries 2 iterator.rodata 1 0 125 cilium_auth_map 524288 666 126 cilium_runtime_ 256 0 127 cilium_signals 32 0 128 cilium_node_map 16384 1344 129 cilium_events 32 0 ...Signed-off-by: Anton Protopopov <aspsk@isovalent.com>Link: https://lore.kernel.org/r/20230706133932.45883-5-aspsk@isovalent.comSigned-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
bpf: Replace deprecated -target with --target= for ClangThe -target option has been deprecated since clang 3.4 in 2013. Therefore, usethe preferred --target=bpf form instead. This also matches how
bpf: Replace deprecated -target with --target= for ClangThe -target option has been deprecated since clang 3.4 in 2013. Therefore, usethe preferred --target=bpf form instead. This also matches how we use --target=in scripts/Makefile.clang.Signed-off-by: Fangrui Song <maskray@google.com>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Yonghong Song <yhs@fb.com>Acked-by: Quentin Monnet <quentin@isovalent.com>Link: https://github.com/llvm/llvm-project/commit/274b6f0c87a6a1798de0a68135afc7f95def6277Link: https://lore.kernel.org/bpf/20230624001856.1903733-1-maskray@google.com
bpf: iterators: Split iterators.lskel.h into little- and big- endian versionsiterators.lskel.h is little-endian, therefore bpf iterator is currentlybroken on big-endian systems. Introduce a big-en
bpf: iterators: Split iterators.lskel.h into little- and big- endian versionsiterators.lskel.h is little-endian, therefore bpf iterator is currentlybroken on big-endian systems. Introduce a big-endian version and addinstructions regarding its generation. Unfortunately bpftool'scross-endianness capabilities are limited to BTF right now, so theprocedure requires access to a big-endian machine or a configuredemulator.Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>Link: https://lore.kernel.org/r/20230128000650.1516334-25-iii@linux.ibm.comSigned-off-by: Alexei Starovoitov <ast@kernel.org>
bpf: iterators: Build and use lightweight bootstrap version of bpftoolkernel/bpf/preload/iterators use bpftool for vmlinux.h, skeleton, andstatic linking only. So we can use lightweight bootstrap
bpf: iterators: Build and use lightweight bootstrap version of bpftoolkernel/bpf/preload/iterators use bpftool for vmlinux.h, skeleton, andstatic linking only. So we can use lightweight bootstrap version ofbpftool to handle these, and it will be faster.Suggested-by: Andrii Nakryiko <andrii@kernel.org>Signed-off-by: Pu Lehui <pulehui@huawei.com>Signed-off-by: Andrii Nakryiko <andrii@kernel.org>Link: https://lore.kernel.org/bpf/20220714024612.944071-4-pulehui@huawei.com
bpf: Convert bpf_preload.ko to use light skeleton.The main change is a move of the single line #include "iterators.lskel.h"from iterators/iterators.c to bpf_preload_kern.c.Which means that gene
bpf: Convert bpf_preload.ko to use light skeleton.The main change is a move of the single line #include "iterators.lskel.h"from iterators/iterators.c to bpf_preload_kern.c.Which means that generated light skeleton can be used from user space oruser mode driver like iterators.c or from the kernel module or the kernel itself.The direct use of light skeleton from the kernel module simplifies the code,since UMD is no longer necessary. The libbpf.a required user space and UMD. TheCO-RE in the kernel and generated "loader bpf program" used by the lightskeleton are capable to perform complex loading operations traditionallyprovided by libbpf. In addition UMD approach was launching UMD processevery time bpffs has to be mounted. With light skeleton in the kernelthe bpf_preload kernel module loads bpf iterators once and pins themmultiple times into different bpffs mounts.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Yonghong Song <yhs@fb.com>Acked-by: Andrii Nakryiko <andrii@kernel.org>Link: https://lore.kernel.org/bpf/20220209232001.27490-6-alexei.starovoitov@gmail.com
bpf: Update iterators.lskel.h.Light skeleton and skel_internal.h have changed.Update iterators.lskel.h.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@i
bpf: Update iterators.lskel.h.Light skeleton and skel_internal.h have changed.Update iterators.lskel.h.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Yonghong Song <yhs@fb.com>Acked-by: Andrii Nakryiko <andrii@kernel.org>Link: https://lore.kernel.org/bpf/20220209232001.27490-5-alexei.starovoitov@gmail.com
bpf: Open code obj_get_info_by_fd in bpf preload.Open code obj_get_info_by_fd in bpf preload.It's the last part of libbpf that preload/iterators were using.Signed-off-by: Alexei Starovoitov <ast
bpf: Open code obj_get_info_by_fd in bpf preload.Open code obj_get_info_by_fd in bpf preload.It's the last part of libbpf that preload/iterators were using.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Martin KaFai Lau <kafai@fb.com>Link: https://lore.kernel.org/bpf/20220131220528.98088-7-alexei.starovoitov@gmail.com
bpf: Convert bpf preload to light skeleton.Convert bpffs preload iterators to light skeleton.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.ne
bpf: Convert bpf preload to light skeleton.Convert bpffs preload iterators to light skeleton.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Martin KaFai Lau <kafai@fb.com>Link: https://lore.kernel.org/bpf/20220131220528.98088-6-alexei.starovoitov@gmail.com
bpf: Remove unnecessary setrlimit from bpf preload.BPF programs and maps are memcg accounted. setrlimit is obsolete.Remove its use from bpf preload.Signed-off-by: Alexei Starovoitov <ast@kernel.
bpf: Remove unnecessary setrlimit from bpf preload.BPF programs and maps are memcg accounted. setrlimit is obsolete.Remove its use from bpf preload.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Martin KaFai Lau <kafai@fb.com>Link: https://lore.kernel.org/bpf/20220131220528.98088-5-alexei.starovoitov@gmail.com
bpftool: Add install-bin target to install binary onlyWith "make install", bpftool installs its binary and its bash completionfile. Usually, this is what we want. But a few components in the kerne
bpftool: Add install-bin target to install binary onlyWith "make install", bpftool installs its binary and its bash completionfile. Usually, this is what we want. But a few components in the kernelrepository (namely, BPF iterators and selftests) also install bpftoollocally before using it. In such a case, bash completion is notnecessary and is just a useless build artifact.Let's add an "install-bin" target to bpftool, to offer a way to installthe binary only.Signed-off-by: Quentin Monnet <quentin@isovalent.com>Signed-off-by: Andrii Nakryiko <andrii@kernel.org>Link: https://lore.kernel.org/bpf/20211007194438.34443-13-quentin@isovalent.com
bpf: iterators: Install libbpf headers when buildingAPI headers from libbpf should not be accessed directly from thelibrary's source directory. Instead, they should be exported with "makeinstall_
bpf: iterators: Install libbpf headers when buildingAPI headers from libbpf should not be accessed directly from thelibrary's source directory. Instead, they should be exported with "makeinstall_headers". Let's make sure that bpf/preload/iterators/Makefileinstalls the headers properly when building.Signed-off-by: Quentin Monnet <quentin@isovalent.com>Signed-off-by: Andrii Nakryiko <andrii@kernel.org>Link: https://lore.kernel.org/bpf/20211007194438.34443-8-quentin@isovalent.com
libbpf: Move BPF_SEQ_PRINTF and BPF_SNPRINTF to bpf_helpers.hThese macros are convenient wrappers around the bpf_seq_printf andbpf_snprintf helpers. They are currently provided by bpf_tracing.h wh
libbpf: Move BPF_SEQ_PRINTF and BPF_SNPRINTF to bpf_helpers.hThese macros are convenient wrappers around the bpf_seq_printf andbpf_snprintf helpers. They are currently provided by bpf_tracing.h whichtargets low level tracing primitives. bpf_helpers.h is a better fit.The __bpf_narg and __bpf_apply are needed in both files and providedtwice. __bpf_empty isn't used anywhere and is removed from bpf_tracing.hReported-by: Andrii Nakryiko <andrii@kernel.org>Signed-off-by: Florent Revest <revest@chromium.org>Signed-off-by: Andrii Nakryiko <andrii@kernel.org>Link: https://lore.kernel.org/bpf/20210526164643.2881368-1-revest@chromium.org
bpf: Remove unnecessary <argp.h> include from preload/iteratorsThis program does not use argp (which is a glibcism). Instead include <errno.h>directly, which was pulled in by <argp.h>.Signed-off
bpf: Remove unnecessary <argp.h> include from preload/iteratorsThis program does not use argp (which is a glibcism). Instead include <errno.h>directly, which was pulled in by <argp.h>.Signed-off-by: Leah Neukirchen <leah@vuxu.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Song Liu <songliubraving@fb.com>Link: https://lore.kernel.org/bpf/20201216100306.30942-1-leah@vuxu.orgSigned-off-by: Alexei Starovoitov <ast@kernel.org>
bpf: Move prog->aux->linked_prog and trampoline into bpf_link on attachIn preparation for allowing multiple attachments of freplace programs, movethe references to the target program and trampolin
bpf: Move prog->aux->linked_prog and trampoline into bpf_link on attachIn preparation for allowing multiple attachments of freplace programs, movethe references to the target program and trampoline into thebpf_tracing_link structure when that is created. To do this atomically,introduce a new mutex in prog->aux to protect writing to the two pointersto target prog and trampoline, and rename the members to make it clear thatthey are related.With this change, it is no longer possible to attach the same tracingprogram multiple times (detaching in-between), since the reference from thetracing program to the target disappears on the first attach. However,since the next patch will let the caller supply an attach target, that willalso make it possible to attach to the same place multiple times.Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>Signed-off-by: Alexei Starovoitov <ast@kernel.org>Acked-by: Andrii Nakryiko <andriin@fb.com>Link: https://lore.kernel.org/bpf/160138355059.48470.2503076992210324984.stgit@toke.dk
bpf: Add kernel module with user mode driver that populates bpffs.Add kernel module with user mode driver that populates bpffs withBPF iterators.$ mount bpffs /my/bpffs/ -t bpf$ ls -la /my/bpff
bpf: Add kernel module with user mode driver that populates bpffs.Add kernel module with user mode driver that populates bpffs withBPF iterators.$ mount bpffs /my/bpffs/ -t bpf$ ls -la /my/bpffs/total 4drwxrwxrwt 2 root root 0 Jul 2 00:27 .drwxr-xr-x 19 root root 4096 Jul 2 00:09 ..-rw------- 1 root root 0 Jul 2 00:27 maps.debug-rw------- 1 root root 0 Jul 2 00:27 progs.debugThe user mode driver will load BPF Type Formats, create BPF maps, populate BPFmaps, load two BPF programs, attach them to BPF iterators, and finally send twobpf_link IDs back to the kernel.The kernel will pin two bpf_links into newly mounted bpffs instance undernames "progs.debug" and "maps.debug". These two files become human readable.$ cat /my/bpffs/progs.debug id name attached 11 dump_bpf_map bpf_iter_bpf_map 12 dump_bpf_prog bpf_iter_bpf_prog 27 test_pkt_access 32 test_main test_pkt_access test_pkt_access 33 test_subprog1 test_pkt_access_subprog1 test_pkt_access 34 test_subprog2 test_pkt_access_subprog2 test_pkt_access 35 test_subprog3 test_pkt_access_subprog3 test_pkt_access 36 new_get_skb_len get_skb_len test_pkt_access 37 new_get_skb_ifindex get_skb_ifindex test_pkt_access 38 new_get_constant get_constant test_pkt_accessThe BPF program dump_bpf_prog() in iterators.bpf.c is printing this data aboutall BPF programs currently loaded in the system. This information is unstableand will change from kernel to kernel as ".debug" suffix conveys.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Link: https://lore.kernel.org/bpf/20200819042759.51280-4-alexei.starovoitov@gmail.com
bpf: Add BPF program and map iterators as built-in BPF programs.The program and map iterators work similar to seq_file-s.Once the program is pinned in bpffs it can be read with "cat" toolto print
bpf: Add BPF program and map iterators as built-in BPF programs.The program and map iterators work similar to seq_file-s.Once the program is pinned in bpffs it can be read with "cat" toolto print human readable output. In this case about BPF programs and maps.For example:$ cat /sys/fs/bpf/progs.debug id name attached 5 dump_bpf_map bpf_iter_bpf_map 6 dump_bpf_prog bpf_iter_bpf_prog$ cat /sys/fs/bpf/maps.debug id name max_entries 3 iterator.rodata 1To avoid kernel build dependency on clang 10 separate bpf skeleton generationinto manual "make" step and instead check-in generated .skel.h into git.Unlike 'bpftool prog show' in-kernel BTF name is used (when available)to print full name of BPF program instead of 16-byte truncated name.Signed-off-by: Alexei Starovoitov <ast@kernel.org>Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>Acked-by: Andrii Nakryiko <andriin@fb.com>Link: https://lore.kernel.org/bpf/20200819042759.51280-3-alexei.starovoitov@gmail.com