.\" Man page generated from reStructuredText. . .TH BPFTOOL-PROG 8 "" "" "" .SH NAME bpftool-prog \- tool for inspection and simple manipulation of eBPF progs . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 \fBbpftool\fP [\fIOPTIONS\fP] \fBprog\fP \fICOMMAND\fP .sp \fIOPTIONS\fP := { { \fB\-j\fP | \fB\-\-json\fP } [{ \fB\-p\fP | \fB\-\-pretty\fP }] | { \fB\-d\fP | \fB\-\-debug\fP } | { \fB\-l\fP | \fB\-\-legacy\fP } | { \fB\-f\fP | \fB\-\-bpffs\fP } | { \fB\-m\fP | \fB\-\-mapcompat\fP } | { \fB\-n\fP | \fB\-\-nomount\fP } | { \fB\-L\fP | \fB\-\-use\-loader\fP } } .sp \fICOMMANDS\fP := { \fBshow\fP | \fBlist\fP | \fBdump xlated\fP | \fBdump jited\fP | \fBpin\fP | \fBload\fP | \fBloadall\fP | \fBhelp\fP } .UNINDENT .UNINDENT .SH PROG COMMANDS .nf \fBbpftool\fP \fBprog\fP { \fBshow\fP | \fBlist\fP } [\fIPROG\fP] \fBbpftool\fP \fBprog dump xlated\fP \fIPROG\fP [{\fBfile\fP \fIFILE\fP | \fBopcodes\fP | \fBvisual\fP | \fBlinum\fP}] \fBbpftool\fP \fBprog dump jited\fP \fIPROG\fP [{\fBfile\fP \fIFILE\fP | \fBopcodes\fP | \fBlinum\fP}] \fBbpftool\fP \fBprog pin\fP \fIPROG\fP \fIFILE\fP \fBbpftool\fP \fBprog\fP { \fBload\fP | \fBloadall\fP } \fIOBJ\fP \fIPATH\fP [\fBtype\fP \fITYPE\fP] [\fBmap\fP {\fBidx\fP \fIIDX\fP | \fBname\fP \fINAME\fP} \fIMAP\fP] [\fBdev\fP \fINAME\fP] [\fBpinmaps\fP \fIMAP_DIR\fP] \fBbpftool\fP \fBprog attach\fP \fIPROG\fP \fIATTACH_TYPE\fP [\fIMAP\fP] \fBbpftool\fP \fBprog detach\fP \fIPROG\fP \fIATTACH_TYPE\fP [\fIMAP\fP] \fBbpftool\fP \fBprog tracelog\fP \fBbpftool\fP \fBprog run\fP \fIPROG\fP \fBdata_in\fP \fIFILE\fP [\fBdata_out\fP \fIFILE\fP [\fBdata_size_out\fP \fIL\fP]] [\fBctx_in\fP \fIFILE\fP [\fBctx_out\fP \fIFILE\fP [\fBctx_size_out\fP \fIM\fP]]] [\fBrepeat\fP \fIN\fP] \fBbpftool\fP \fBprog profile\fP \fIPROG\fP [\fBduration\fP \fIDURATION\fP] \fIMETRICs\fP \fBbpftool\fP \fBprog help\fP \fIMAP\fP := { \fBid\fP \fIMAP_ID\fP | \fBpinned\fP \fIFILE\fP } \fIPROG\fP := { \fBid\fP \fIPROG_ID\fP | \fBpinned\fP \fIFILE\fP | \fBtag\fP \fIPROG_TAG\fP | \fBname\fP \fIPROG_NAME\fP } \fITYPE\fP := { .in +2 \fBsocket\fP | \fBkprobe\fP | \fBkretprobe\fP | \fBclassifier\fP | \fBaction\fP | \fBtracepoint\fP | \fBraw_tracepoint\fP | \fBxdp\fP | \fBperf_event\fP | \fBcgroup/skb\fP | \fBcgroup/sock\fP | \fBcgroup/dev\fP | \fBlwt_in\fP | \fBlwt_out\fP | \fBlwt_xmit\fP | \fBlwt_seg6local\fP | \fBsockops\fP | \fBsk_skb\fP | \fBsk_msg\fP | \fBlirc_mode2\fP | \fBcgroup/bind4\fP | \fBcgroup/bind6\fP | \fBcgroup/post_bind4\fP | \fBcgroup/post_bind6\fP | \fBcgroup/connect4\fP | \fBcgroup/connect6\fP | \fBcgroup/getpeername4\fP | \fBcgroup/getpeername6\fP | \fBcgroup/getsockname4\fP | \fBcgroup/getsockname6\fP | \fBcgroup/sendmsg4\fP | \fBcgroup/sendmsg6\fP | \fBcgroup/recvmsg4\fP | \fBcgroup/recvmsg6\fP | \fBcgroup/sysctl\fP | \fBcgroup/getsockopt\fP | \fBcgroup/setsockopt\fP | \fBcgroup/sock_release\fP | \fBstruct_ops\fP | \fBfentry\fP | \fBfexit\fP | \fBfreplace\fP | \fBsk_lookup\fP .in -2 } \fIATTACH_TYPE\fP := { .in +2 \fBsk_msg_verdict\fP | \fBsk_skb_verdict\fP | \fBsk_skb_stream_verdict\fP | \fBsk_skb_stream_parser\fP | \fBflow_dissector\fP .in -2 } \fIMETRICs\fP := { .in +2 \fBcycles\fP | \fBinstructions\fP | \fBl1d_loads\fP | \fBllc_misses\fP | \fBitlb_misses\fP | \fBdtlb_misses\fP .in -2 } .fi .sp .SH DESCRIPTION .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .TP .B \fBbpftool prog { show | list }\fP [\fIPROG\fP] Show information about loaded programs. If \fIPROG\fP is specified show information only about given programs, otherwise list all programs currently loaded on the system. In case of \fBtag\fP or \fBname\fP, \fIPROG\fP may match several programs which will all be shown. .sp Output will start with program ID followed by program type and zero or more named attributes (depending on kernel version). .sp Since Linux 5.1 the kernel can collect statistics on BPF programs (such as the total time spent running the program, and the number of times it was run). If available, bpftool shows such statistics. However, the kernel does not collect them by defaults, as it slightly impacts performance on each program run. Activation or deactivation of the feature is performed via the \fBkernel.bpf_stats_enabled\fP sysctl knob. .sp Since Linux 5.8 bpftool is able to discover information about processes that hold open file descriptors (FDs) against BPF programs. On such kernels bpftool will automatically emit this information as well. .TP .B \fBbpftool prog dump xlated\fP \fIPROG\fP [{ \fBfile\fP \fIFILE\fP | \fBopcodes\fP | \fBvisual\fP | \fBlinum\fP }] Dump eBPF instructions of the programs from the kernel. By default, eBPF will be disassembled and printed to standard output in human\-readable format. In this case, \fBopcodes\fP controls if raw opcodes should be printed as well. .sp In case of \fBtag\fP or \fBname\fP, \fIPROG\fP may match several programs which will all be dumped. However, if \fBfile\fP or \fBvisual\fP is specified, \fIPROG\fP must match a single program. .sp If \fBfile\fP is specified, the binary image will instead be written to \fIFILE\fP\&. .sp If \fBvisual\fP is specified, control flow graph (CFG) will be built instead, and eBPF instructions will be presented with CFG in DOT format, on standard output. .sp If the programs have line_info available, the source line will be displayed by default. If \fBlinum\fP is specified, the filename, line number and line column will also be displayed on top of the source line. .TP .B \fBbpftool prog dump jited\fP \fIPROG\fP [{ \fBfile\fP \fIFILE\fP | \fBopcodes\fP | \fBlinum\fP }] Dump jited image (host machine code) of the program. .sp If \fIFILE\fP is specified image will be written to a file, otherwise it will be disassembled and printed to stdout. \fIPROG\fP must match a single program when \fBfile\fP is specified. .sp \fBopcodes\fP controls if raw opcodes will be printed. .sp If the prog has line_info available, the source line will be displayed by default. If \fBlinum\fP is specified, the filename, line number and line column will also be displayed on top of the source line. .TP .B \fBbpftool prog pin\fP \fIPROG\fP \fIFILE\fP Pin program \fIPROG\fP as \fIFILE\fP\&. .sp Note: \fIFILE\fP must be located in \fIbpffs\fP mount. It must not contain a dot character (\(aq.\(aq), which is reserved for future extensions of \fIbpffs\fP\&. .TP .B \fBbpftool prog { load | loadall }\fP \fIOBJ\fP \fIPATH\fP [\fBtype\fP \fITYPE\fP] [\fBmap\fP {\fBidx\fP \fIIDX\fP | \fBname\fP \fINAME\fP} \fIMAP\fP] [\fBdev\fP \fINAME\fP] [\fBpinmaps\fP \fIMAP_DIR\fP] Load bpf program(s) from binary \fIOBJ\fP and pin as \fIPATH\fP\&. \fBbpftool prog load\fP pins only the first program from the \fIOBJ\fP as \fIPATH\fP\&. \fBbpftool prog loadall\fP pins all programs from the \fIOBJ\fP under \fIPATH\fP directory. \fBtype\fP is optional, if not specified program type will be inferred from section names. By default bpftool will create new maps as declared in the ELF object being loaded. \fBmap\fP parameter allows for the reuse of existing maps. It can be specified multiple times, each time for a different map. \fIIDX\fP refers to index of the map to be replaced in the ELF file counting from 0, while \fINAME\fP allows to replace a map by name. \fIMAP\fP specifies the map to use, referring to it by \fBid\fP or through a \fBpinned\fP file. If \fBdev\fP \fINAME\fP is specified program will be loaded onto given networking device (offload). Optional \fBpinmaps\fP argument can be provided to pin all maps under \fIMAP_DIR\fP directory. .sp Note: \fIPATH\fP must be located in \fIbpffs\fP mount. It must not contain a dot character (\(aq.\(aq), which is reserved for future extensions of \fIbpffs\fP\&. .TP .B \fBbpftool prog attach\fP \fIPROG\fP \fIATTACH_TYPE\fP [\fIMAP\fP] Attach bpf program \fIPROG\fP (with type specified by \fIATTACH_TYPE\fP). Most \fIATTACH_TYPEs\fP require a \fIMAP\fP parameter, with the exception of \fIflow_dissector\fP which is attached to current networking name space. .TP .B \fBbpftool prog detach\fP \fIPROG\fP \fIATTACH_TYPE\fP [\fIMAP\fP] Detach bpf program \fIPROG\fP (with type specified by \fIATTACH_TYPE\fP). Most \fIATTACH_TYPEs\fP require a \fIMAP\fP parameter, with the exception of \fIflow_dissector\fP which is detached from the current networking name space. .TP .B \fBbpftool prog tracelog\fP Dump the trace pipe of the system to the console (stdout). Hit to stop printing. BPF programs can write to this trace pipe at runtime with the \fBbpf_trace_printk\fP() helper. This should be used only for debugging purposes. For streaming data from BPF programs to user space, one can use perf events (see also \fBbpftool\-map\fP(8)). .TP .B \fBbpftool prog run\fP \fIPROG\fP \fBdata_in\fP \fIFILE\fP [\fBdata_out\fP \fIFILE\fP [\fBdata_size_out\fP \fIL\fP]] [\fBctx_in\fP \fIFILE\fP [\fBctx_out\fP \fIFILE\fP [\fBctx_size_out\fP \fIM\fP]]] [\fBrepeat\fP \fIN\fP] Run BPF program \fIPROG\fP in the kernel testing infrastructure for BPF, meaning that the program works on the data and context provided by the user, and not on actual packets or monitored functions etc. Return value and duration for the test run are printed out to the console. .sp Input data is read from the \fIFILE\fP passed with \fBdata_in\fP\&. If this \fIFILE\fP is "\fB\-\fP", input data is read from standard input. Input context, if any, is read from \fIFILE\fP passed with \fBctx_in\fP\&. Again, "\fB\-\fP" can be used to read from standard input, but only if standard input is not already in use for input data. If a \fIFILE\fP is passed with \fBdata_out\fP, output data is written to that file. Similarly, output context is written to the \fIFILE\fP passed with \fBctx_out\fP\&. For both output flows, "\fB\-\fP" can be used to print to the standard output (as plain text, or JSON if relevant option was passed). If output keywords are omitted, output data and context are discarded. Keywords \fBdata_size_out\fP and \fBctx_size_out\fP are used to pass the size (in bytes) for the output buffers to the kernel, although the default of 32 kB should be more than enough for most cases. .sp Keyword \fBrepeat\fP is used to indicate the number of consecutive runs to perform. Note that output data and context printed to files correspond to the last of those runs. The duration printed out at the end of the runs is an average over all runs performed by the command. .sp Not all program types support test run. Among those which do, not all of them can take the \fBctx_in\fP/\fBctx_out\fP arguments. bpftool does not perform checks on program types. .TP .B \fBbpftool prog profile\fP \fIPROG\fP [\fBduration\fP \fIDURATION\fP] \fIMETRICs\fP Profile \fIMETRICs\fP for bpf program \fIPROG\fP for \fIDURATION\fP seconds or until user hits . \fIDURATION\fP is optional. If \fIDURATION\fP is not specified, the profiling will run up to \fBUINT_MAX\fP seconds. .TP .B \fBbpftool prog help\fP Print short help message. .UNINDENT .UNINDENT .UNINDENT .SH OPTIONS .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .TP .B \-h\fP,\fB \-\-help Print short help message (similar to \fBbpftool help\fP). .TP .B \-V\fP,\fB \-\-version Print bpftool\(aqs version number (similar to \fBbpftool version\fP), the number of the libbpf version in use, and optional features that were included when bpftool was compiled. Optional features include linking against libbfd to provide the disassembler for JIT\-ted programs (\fBbpftool prog dump jited\fP) and usage of BPF skeletons (some features like \fBbpftool prog profile\fP or showing pids associated to BPF objects may rely on it). .TP .B \-j\fP,\fB \-\-json Generate JSON output. For commands that cannot produce JSON, this option has no effect. .TP .B \-p\fP,\fB \-\-pretty Generate human\-readable JSON output. Implies \fB\-j\fP\&. .TP .B \-d\fP,\fB \-\-debug Print all logs available, even debug\-level information. This includes logs from libbpf as well as from the verifier, when attempting to load programs. .TP .B \-l\fP,\fB \-\-legacy Use legacy libbpf mode which has more relaxed BPF program requirements. By default, bpftool has more strict requirements about section names, changes pinning logic and doesn\(aqt support some of the older non\-BTF map declarations. .sp See \fI\%https://github.com/libbpf/libbpf/wiki/Libbpf:\-the\-road\-to\-v1.0\fP for details. .TP .B \-f\fP,\fB \-\-bpffs When showing BPF programs, show file names of pinned programs. .TP .B \-m\fP,\fB \-\-mapcompat Allow loading maps with unknown map definitions. .TP .B \-n\fP,\fB \-\-nomount Do not automatically attempt to mount any virtual file system (such as tracefs or BPF virtual file system) when necessary. .TP .B \-L\fP,\fB \-\-use\-loader Load program as a "loader" program. This is useful to debug the generation of such programs. When this option is in use, bpftool attempts to load the programs from the object file into the kernel, but does not pin them (therefore, the \fIPATH\fP must not be provided). .sp When combined with the \fB\-d\fP|\fB\-\-debug\fP option, additional debug messages are generated, and the execution of the loader program will use the \fBbpf_trace_printk\fP() helper to log each step of loading BTF, creating the maps, and loading the programs (see \fBbpftool prog tracelog\fP as a way to dump those messages). .UNINDENT .UNINDENT .UNINDENT .SH EXAMPLES .sp \fB# bpftool prog show\fP .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 10: xdp name some_prog tag 005a3d2123620c8b gpl run_time_ns 81632 run_cnt 10 loaded_at 2017\-09\-29T20:11:00+0000 uid 0 xlated 528B jited 370B memlock 4096B map_ids 10 pids systemd(1) .ft P .fi .UNINDENT .UNINDENT .sp \fB# bpftool \-\-json \-\-pretty prog show\fP .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C [{ "id": 10, "type": "xdp", "tag": "005a3d2123620c8b", "gpl_compatible": true, "run_time_ns": 81632, "run_cnt": 10, "loaded_at": 1506715860, "uid": 0, "bytes_xlated": 528, "jited": true, "bytes_jited": 370, "bytes_memlock": 4096, "map_ids": [10 ], "pids": [{ "pid": 1, "comm": "systemd" } ] } ] .ft P .fi .UNINDENT .UNINDENT .nf \fB# bpftool prog dump xlated id 10 file /tmp/t\fP \fB$ ls \-l /tmp/t\fP .fi .sp .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-rw\-\-\-\-\-\-\- 1 root root 560 Jul 22 01:42 /tmp/t .ft P .fi .UNINDENT .UNINDENT .sp \fB# bpftool prog dump jited tag 005a3d2123620c8b\fP .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 0: push %rbp 1: mov %rsp,%rbp 2: sub $0x228,%rsp 3: sub $0x28,%rbp 4: mov %rbx,0x0(%rbp) .ft P .fi .UNINDENT .UNINDENT .nf \fB# mount \-t bpf none /sys/fs/bpf/\fP \fB# bpftool prog pin id 10 /sys/fs/bpf/prog\fP \fB# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2\fP \fB# ls \-l /sys/fs/bpf/\fP .fi .sp .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-rw\-\-\-\-\-\-\- 1 root root 0 Jul 22 01:43 prog \-rw\-\-\-\-\-\-\- 1 root root 0 Jul 22 01:44 prog2 .ft P .fi .UNINDENT .UNINDENT .sp \fB# bpftool prog dump jited pinned /sys/fs/bpf/prog opcodes\fP .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 0: push %rbp 55 1: mov %rsp,%rbp 48 89 e5 4: sub $0x228,%rsp 48 81 ec 28 02 00 00 b: sub $0x28,%rbp 48 83 ed 28 f: mov %rbx,0x0(%rbp) 48 89 5d 00 .ft P .fi .UNINDENT .UNINDENT .nf \fB# bpftool prog load xdp1_kern.o /sys/fs/bpf/xdp1 type xdp map name rxcnt id 7\fP \fB# bpftool prog show pinned /sys/fs/bpf/xdp1\fP .fi .sp .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 9: xdp name xdp_prog1 tag 539ec6ce11b52f98 gpl loaded_at 2018\-06\-25T16:17:31\-0700 uid 0 xlated 488B jited 336B memlock 4096B map_ids 7 .ft P .fi .UNINDENT .UNINDENT .sp \fB# rm /sys/fs/bpf/xdp1\fP .nf \fB# bpftool prog profile id 337 duration 10 cycles instructions llc_misses\fP .fi .sp .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 51397 run_cnt 40176203 cycles (83.05%) 42518139 instructions # 1.06 insns per cycle (83.39%) 123 llc_misses # 2.89 LLC misses per million insns (83.15%) .ft P .fi .UNINDENT .UNINDENT .nf Output below is for the trace logs. Run in separate terminals: \fB# bpftool prog tracelog\fP \fB# bpftool prog load \-L \-d file.o\fP .fi .sp .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C bpftool\-620059 [004] d... 2634685.517903: bpf_trace_printk: btf_load size 665 r=5 bpftool\-620059 [004] d... 2634685.517912: bpf_trace_printk: map_create sample_map idx 0 type 2 value_size 4 value_btf_id 0 r=6 bpftool\-620059 [004] d... 2634685.517997: bpf_trace_printk: prog_load sample insn_cnt 13 r=7 bpftool\-620059 [004] d... 2634685.517999: bpf_trace_printk: close(5) = 0 .ft P .fi .UNINDENT .UNINDENT .SH SEE ALSO .INDENT 0.0 .INDENT 3.5 \fBbpf\fP(2), \fBbpf\-helpers\fP(7), \fBbpftool\fP(8), \fBbpftool\-btf\fP(8), \fBbpftool\-cgroup\fP(8), \fBbpftool\-feature\fP(8), \fBbpftool\-gen\fP(8), \fBbpftool\-iter\fP(8), \fBbpftool\-link\fP(8), \fBbpftool\-map\fP(8), \fBbpftool\-net\fP(8), \fBbpftool\-perf\fP(8), \fBbpftool\-struct_ops\fP(8) .UNINDENT .UNINDENT .\" Generated by docutils manpage writer. .