<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 6, 2023, at 1:53 AM, Christophe Leroy <<a href="mailto:christophe.leroy@csgroup.eu" class="">christophe.leroy@csgroup.eu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Le 05/01/2023 à 04:06,<span class="Apple-converted-space"> </span></span><a href="mailto:tong@infragraf.org" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">tong@infragraf.org</a><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>a écrit :</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">From: Tonghao Zhang <<a href="mailto:tong@infragraf.org" class="">tong@infragraf.org</a>><br class=""><br class="">The x86_64 can't dump the valid insn in this way. A test BPF prog<br class="">which include subprog:<br class=""><br class="">$ llvm-objdump -d subprog.o<br class="">Disassembly of section .text:<br class="">0000000000000000 <subprog>:<br class="">       0:       18 01 00 00 73 75 62 70 00 00 00 00 72 6f 67 00 r1 = 29114459903653235 ll<br class="">       2:       7b 1a f8 ff 00 00 00 00 *(u64 *)(r10 - 8) = r1<br class="">       3:       bf a1 00 00 00 00 00 00 r1 = r10<br class="">       4:       07 01 00 00 f8 ff ff ff r1 += -8<br class="">       5:       b7 02 00 00 08 00 00 00 r2 = 8<br class="">       6:       85 00 00 00 06 00 00 00 call 6<br class="">       7:       95 00 00 00 00 00 00 00 exit<br class="">Disassembly of section raw_tp/sys_enter:<br class="">0000000000000000 <entry>:<br class="">       0:       85 10 00 00 ff ff ff ff call -1<br class="">       1:       b7 00 00 00 00 00 00 00 r0 = 0<br class="">       2:       95 00 00 00 00 00 00 00 exit<br class=""><br class="">kernel print message:<br class="">[  580.775387] flen=8 proglen=51 pass=3 image=ffffffffa000c20c from=kprobe-load pid=1643<br class="">[  580.777236] JIT code: 00000000: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc<br class="">[  580.779037] JIT code: 00000010: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc<br class="">[  580.780767] JIT code: 00000020: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc<br class="">[  580.782568] JIT code: 00000030: cc cc cc<br class=""><br class="">$ bpf_jit_disasm<br class="">51 bytes emitted from JIT compiler (pass:3, flen:8)<br class="">ffffffffa000c20c + <x>:<br class="">   0:   int3<br class="">   1:   int3<br class="">   2:   int3<br class="">   3:   int3<br class="">   4:   int3<br class="">   5:   int3<br class="">   ...<br class=""><br class="">Until bpf_jit_binary_pack_finalize is invoked, we copy rw_header to header<br class="">and then image/insn is valid. BTW, we can use the "bpftool prog dump" JITed instructions.<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">NACK.</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Because the feature is buggy on x86_64, you remove it for all<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">architectures ?</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">On powerpc bpf_jit_enable == 2 works and is very usefull.</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Last time I tried to use bpftool on powerpc/32 it didn't work. I don't<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">remember the details, I think it was an issue with endianess. Maybe it<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">is fixed now, but it needs to be verified.</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div></blockquote><div><br class=""></div>I think bpftool may dump the jited insn too.<br class=""><blockquote type="cite" class=""><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">So please, before removing a working and usefull feature, make sure<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">there is an alternative available to it for all architectures in all<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">configurations.</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Also, I don't think bpftool is usable to dump kernel BPF selftests.<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div></blockquote><div>Why bpftool does’t work for you ? I think this is a core function for bpf. If you can dump the jited insn using bpf_jit_enable == 2, you should</div><div>dump the inns tool, while in <font face="Menlo-Regular" class=""><span style="font-size: 11px;" class="">selftest</span></font> case.</div><div><br class=""></div><div>Alexei any thoughts?</div><br class=""><blockquote type="cite" class=""><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">That's vital when a selftest fails if you want to have a chance to<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">understand why it fails.</span></div></blockquote><blockquote type="cite" class=""><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Thanks</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Christophe</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="">Signed-off-by: Tonghao Zhang <<a href="mailto:tong@infragraf.org" class="">tong@infragraf.org</a>><br class="">Suggested-by: Alexei Starovoitov <<a href="mailto:ast@kernel.org" class="">ast@kernel.org</a>><br class="">Cc: Alexei Starovoitov <<a href="mailto:ast@kernel.org" class="">ast@kernel.org</a>><br class="">Cc: Daniel Borkmann <<a href="mailto:daniel@iogearbox.net" class="">daniel@iogearbox.net</a>><br class="">Cc: Andrii Nakryiko <<a href="mailto:andrii@kernel.org" class="">andrii@kernel.org</a>><br class="">Cc: Martin KaFai Lau <<a href="mailto:martin.lau@linux.dev" class="">martin.lau@linux.dev</a>><br class="">Cc: Song Liu <<a href="mailto:song@kernel.org" class="">song@kernel.org</a>><br class="">Cc: Yonghong Song <<a href="mailto:yhs@fb.com" class="">yhs@fb.com</a>><br class="">Cc: John Fastabend <<a href="mailto:john.fastabend@gmail.com" class="">john.fastabend@gmail.com</a>><br class="">Cc: KP Singh <<a href="mailto:kpsingh@kernel.org" class="">kpsingh@kernel.org</a>><br class="">Cc: Stanislav Fomichev <<a href="mailto:sdf@google.com" class="">sdf@google.com</a>><br class="">Cc: Hao Luo <<a href="mailto:haoluo@google.com" class="">haoluo@google.com</a>><br class="">Cc: Jiri Olsa <<a href="mailto:jolsa@kernel.org" class="">jolsa@kernel.org</a>><br class="">Cc: Hou Tao <<a href="mailto:houtao1@huawei.com" class="">houtao1@huawei.com</a>><br class="">---<br class=""> Documentation/admin-guide/sysctl/net.rst |   1 +<br class=""> Documentation/networking/filter.rst      |  98 +------<br class=""> arch/arm/net/bpf_jit_32.c                |   4 -<br class=""> arch/arm64/net/bpf_jit_comp.c            |   4 -<br class=""> arch/loongarch/net/bpf_jit.c             |   4 -<br class=""> arch/mips/net/bpf_jit_comp.c             |   3 -<br class=""> arch/powerpc/net/bpf_jit_comp.c          |  11 -<br class=""> arch/riscv/net/bpf_jit_core.c            |   3 -<br class=""> arch/s390/net/bpf_jit_comp.c             |   4 -<br class=""> arch/sparc/net/bpf_jit_comp_32.c         |   3 -<br class=""> arch/sparc/net/bpf_jit_comp_64.c         |  13 -<br class=""> arch/x86/net/bpf_jit_comp.c              |   3 -<br class=""> arch/x86/net/bpf_jit_comp32.c            |   3 -<br class=""> net/core/sysctl_net_core.c               |  12 +-<br class=""> tools/bpf/.gitignore                     |   1 -<br class=""> tools/bpf/Makefile                       |  10 +-<br class=""> tools/bpf/bpf_jit_disasm.c               | 332 -----------------------<br class=""> 17 files changed, 9 insertions(+), 500 deletions(-)<br class=""> delete mode 100644 tools/bpf/bpf_jit_disasm.c<br class=""><br class="">diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst<br class="">index 6394f5dc2303..82ca05ca6ed0 100644<br class="">--- a/Documentation/admin-guide/sysctl/net.rst<br class="">+++ b/Documentation/admin-guide/sysctl/net.rst<br class="">@@ -88,6 +88,7 @@ Values:<br class="">        - 0 - disable the JIT (default value)<br class="">        - 1 - enable the JIT<br class="">        - 2 - enable the JIT and ask the compiler to emit traces on kernel log.<br class="">+              (deprecated since v6.3, use ``bpftool prog dump jited id <id>`` instead)<br class=""><br class=""> bpf_jit_harden<br class=""> --------------<br class="">diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst<br class="">index f69da5074860..5f51c050e88f 100644<br class="">--- a/Documentation/networking/filter.rst<br class="">+++ b/Documentation/networking/filter.rst<br class="">@@ -520,102 +520,8 @@ been previously enabled by root::<br class=""><br class="">   echo 1 > /proc/sys/net/core/bpf_jit_enable<br class=""><br class="">-For JIT developers, doing audits etc, each compile run can output the generated<br class="">-opcode image into the kernel log via::<br class="">-<br class="">-  echo 2 > /proc/sys/net/core/bpf_jit_enable<br class="">-<br class="">-Example output from dmesg::<br class="">-<br class="">-    [ 3389.935842] flen=6 proglen=70 pass=3 image=ffffffffa0069c8f<br class="">-    [ 3389.935847] JIT code: 00000000: 55 48 89 e5 48 83 ec 60 48 89 5d f8 44 8b 4f 68<br class="">-    [ 3389.935849] JIT code: 00000010: 44 2b 4f 6c 4c 8b 87 d8 00 00 00 be 0c 00 00 00<br class="">-    [ 3389.935850] JIT code: 00000020: e8 1d 94 ff e0 3d 00 08 00 00 75 16 be 17 00 00<br class="">-    [ 3389.935851] JIT code: 00000030: 00 e8 28 94 ff e0 83 f8 01 75 07 b8 ff ff 00 00<br class="">-    [ 3389.935852] JIT code: 00000040: eb 02 31 c0 c9 c3<br class="">-<br class="">-When CONFIG_BPF_JIT_ALWAYS_ON is enabled, bpf_jit_enable is permanently set to 1 and<br class="">-setting any other value than that will return in failure. This is even the case for<br class="">-setting bpf_jit_enable to 2, since dumping the final JIT image into the kernel log<br class="">-is discouraged and introspection through bpftool (under tools/bpf/bpftool/) is the<br class="">-generally recommended approach instead.<br class="">-<br class="">-In the kernel source tree under tools/bpf/, there's bpf_jit_disasm for<br class="">-generating disassembly out of the kernel log's hexdump::<br class="">-<br class="">-       # ./bpf_jit_disasm<br class="">-       70 bytes emitted from JIT compiler (pass:3, flen:6)<br class="">-       ffffffffa0069c8f + <x>:<br class="">-       0:      push   %rbp<br class="">-       1:      mov    %rsp,%rbp<br class="">-       4:      sub    $0x60,%rsp<br class="">-       8:      mov    %rbx,-0x8(%rbp)<br class="">-       c:      mov    0x68(%rdi),%r9d<br class="">-       10:     sub    0x6c(%rdi),%r9d<br class="">-       14:     mov    0xd8(%rdi),%r8<br class="">-       1b:     mov    $0xc,%esi<br class="">-       20:     callq  0xffffffffe0ff9442<br class="">-       25:     cmp    $0x800,%eax<br class="">-       2a:     jne    0x0000000000000042<br class="">-       2c:     mov    $0x17,%esi<br class="">-       31:     callq  0xffffffffe0ff945e<br class="">-       36:     cmp    $0x1,%eax<br class="">-       39:     jne    0x0000000000000042<br class="">-       3b:     mov    $0xffff,%eax<br class="">-       40:     jmp    0x0000000000000044<br class="">-       42:     xor    %eax,%eax<br class="">-       44:     leaveq<br class="">-       45:     retq<br class="">-<br class="">-       Issuing option `-o` will "annotate" opcodes to resulting assembler<br class="">-       instructions, which can be very useful for JIT developers:<br class="">-<br class="">-       # ./bpf_jit_disasm -o<br class="">-       70 bytes emitted from JIT compiler (pass:3, flen:6)<br class="">-       ffffffffa0069c8f + <x>:<br class="">-       0:      push   %rbp<br class="">-               55<br class="">-       1:      mov    %rsp,%rbp<br class="">-               48 89 e5<br class="">-       4:      sub    $0x60,%rsp<br class="">-               48 83 ec 60<br class="">-       8:      mov    %rbx,-0x8(%rbp)<br class="">-               48 89 5d f8<br class="">-       c:      mov    0x68(%rdi),%r9d<br class="">-               44 8b 4f 68<br class="">-       10:     sub    0x6c(%rdi),%r9d<br class="">-               44 2b 4f 6c<br class="">-       14:     mov    0xd8(%rdi),%r8<br class="">-               4c 8b 87 d8 00 00 00<br class="">-       1b:     mov    $0xc,%esi<br class="">-               be 0c 00 00 00<br class="">-       20:     callq  0xffffffffe0ff9442<br class="">-               e8 1d 94 ff e0<br class="">-       25:     cmp    $0x800,%eax<br class="">-               3d 00 08 00 00<br class="">-       2a:     jne    0x0000000000000042<br class="">-               75 16<br class="">-       2c:     mov    $0x17,%esi<br class="">-               be 17 00 00 00<br class="">-       31:     callq  0xffffffffe0ff945e<br class="">-               e8 28 94 ff e0<br class="">-       36:     cmp    $0x1,%eax<br class="">-               83 f8 01<br class="">-       39:     jne    0x0000000000000042<br class="">-               75 07<br class="">-       3b:     mov    $0xffff,%eax<br class="">-               b8 ff ff 00 00<br class="">-       40:     jmp    0x0000000000000044<br class="">-               eb 02<br class="">-       42:     xor    %eax,%eax<br class="">-               31 c0<br class="">-       44:     leaveq<br class="">-               c9<br class="">-       45:     retq<br class="">-               c3<br class="">-<br class="">-For BPF JIT developers, bpf_jit_disasm, bpf_asm and bpf_dbg provides a useful<br class="">-toolchain for developing and testing the kernel's JIT compiler.<br class="">+For JIT developers, doing audits etc, should use `bpftool prog dump` to<br class="">+veiw the JIT generated opcode image.<br class=""><br class=""> BPF kernel internals<br class=""> --------------------<br class="">diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c<br class="">index 6a1c9fca5260..39301d59b537 100644<br class="">--- a/arch/arm/net/bpf_jit_32.c<br class="">+++ b/arch/arm/net/bpf_jit_32.c<br class="">@@ -1999,10 +1999,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">        }<br class="">        flush_icache_range((u32)header, (u32)(ctx.target + ctx.idx));<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               /* there are 2 passes here */<br class="">-               bpf_jit_dump(prog->len, image_size, 2, ctx.target);<br class="">-<br class="">        bpf_jit_binary_lock_ro(header);<br class="">        prog->bpf_func = (void *)ctx.target;<br class="">        prog->jited = 1;<br class="">diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c<br class="">index 62f805f427b7..59c35b4d77b7 100644<br class="">--- a/arch/arm64/net/bpf_jit_comp.c<br class="">+++ b/arch/arm64/net/bpf_jit_comp.c<br class="">@@ -1567,10 +1567,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">                goto out_off;<br class="">        }<br class=""><br class="">-       /* And we're done. */<br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, prog_size, 2, ctx.image);<br class="">-<br class="">        bpf_flush_icache(header, ctx.image + ctx.idx);<br class=""><br class="">        if (!prog->is_func || extra_pass) {<br class="">diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c<br class="">index bdcd0c7719a9..ea37f52faa6e 100644<br class="">--- a/arch/loongarch/net/bpf_jit.c<br class="">+++ b/arch/loongarch/net/bpf_jit.c<br class="">@@ -1123,10 +1123,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">                goto out_offset;<br class="">        }<br class=""><br class="">-       /* And we're done */<br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, image_size, 2, ctx.image);<br class="">-<br class="">        /* Update the icache */<br class="">        flush_icache_range((unsigned long)header, (unsigned long)(ctx.image + ctx.idx));<br class=""><br class="">diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c<br class="">index b17130d510d4..ccbb7c231cb0 100644<br class="">--- a/arch/mips/net/bpf_jit_comp.c<br class="">+++ b/arch/mips/net/bpf_jit_comp.c<br class="">@@ -1012,9 +1012,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">        flush_icache_range((unsigned long)header,<br class="">                           (unsigned long)&ctx.target[ctx.jit_index]);<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, image_size, 2, ctx.target);<br class="">-<br class="">        prog->bpf_func = (void *)ctx.target;<br class="">        prog->jited = 1;<br class="">        prog->jited_len = image_size;<br class="">diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c<br class="">index 43e634126514..f0f7d8ff2022 100644<br class="">--- a/arch/powerpc/net/bpf_jit_comp.c<br class="">+++ b/arch/powerpc/net/bpf_jit_comp.c<br class="">@@ -262,20 +262,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)<br class="">                        goto out_addrs;<br class="">                }<br class="">                bpf_jit_build_epilogue(code_base, &cgctx);<br class="">-<br class="">-               if (bpf_jit_enable > 1)<br class="">-                       pr_info("Pass %d: shrink = %d, seen = 0x%x\n", pass,<br class="">-                               proglen - (cgctx.idx * 4), cgctx.seen);<br class="">        }<br class=""><br class=""> skip_codegen_passes:<br class="">-       if (bpf_jit_enable > 1)<br class="">-               /*<br class="">-                * Note that we output the base address of the code_base<br class="">-                * rather than image, since opcodes are in code_base.<br class="">-                */<br class="">-               bpf_jit_dump(flen, proglen, pass, code_base);<br class="">-<br class=""> #ifdef CONFIG_PPC64_ELF_ABI_V1<br class="">        /* Function descriptor nastiness: Address + TOC */<br class="">        ((u64 *)image)[0] = (u64)code_base;<br class="">diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c<br class="">index 737baf8715da..ff168c50d46a 100644<br class="">--- a/arch/riscv/net/bpf_jit_core.c<br class="">+++ b/arch/riscv/net/bpf_jit_core.c<br class="">@@ -151,9 +151,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">        }<br class="">        bpf_jit_build_epilogue(ctx);<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, prog_size, pass, ctx->insns);<br class="">-<br class="">        prog->bpf_func = (void *)ctx->insns;<br class="">        prog->jited = 1;<br class="">        prog->jited_len = prog_size;<br class="">diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c<br class="">index af35052d06ed..13d996e27602 100644<br class="">--- a/arch/s390/net/bpf_jit_comp.c<br class="">+++ b/arch/s390/net/bpf_jit_comp.c<br class="">@@ -1831,10 +1831,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)<br class="">                fp = orig_fp;<br class="">                goto free_addrs;<br class="">        }<br class="">-       if (bpf_jit_enable > 1) {<br class="">-               bpf_jit_dump(fp->len, jit.size, pass, jit.prg_buf);<br class="">-               print_fn_code(jit.prg_buf, jit.size_prg);<br class="">-       }<br class="">        if (!fp->is_func || extra_pass) {<br class="">                bpf_jit_binary_lock_ro(header);<br class="">        } else {<br class="">diff --git a/arch/sparc/net/bpf_jit_comp_32.c b/arch/sparc/net/bpf_jit_comp_32.c<br class="">index a74e5004c6c8..08de0ed84831 100644<br class="">--- a/arch/sparc/net/bpf_jit_comp_32.c<br class="">+++ b/arch/sparc/net/bpf_jit_comp_32.c<br class="">@@ -743,9 +743,6 @@ cond_branch:                        f_offset = addrs[i + filter[i].jf];<br class="">                oldproglen = proglen;<br class="">        }<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(flen, proglen, pass + 1, image);<br class="">-<br class="">        if (image) {<br class="">                fp->bpf_func = (void *)image;<br class="">                fp->jited = 1;<br class="">diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c<br class="">index fa0759bfe498..14c9e5ce4100 100644<br class="">--- a/arch/sparc/net/bpf_jit_comp_64.c<br class="">+++ b/arch/sparc/net/bpf_jit_comp_64.c<br class="">@@ -1549,16 +1549,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">                }<br class="">                build_epilogue(&ctx);<br class=""><br class="">-               if (bpf_jit_enable > 1)<br class="">-                       pr_info("Pass %d: size = %u, seen = [%c%c%c%c%c%c]\n", pass,<br class="">-                               ctx.idx * 4,<br class="">-                               ctx.tmp_1_used ? '1' : ' ',<br class="">-                               ctx.tmp_2_used ? '2' : ' ',<br class="">-                               ctx.tmp_3_used ? '3' : ' ',<br class="">-                               ctx.saw_frame_pointer ? 'F' : ' ',<br class="">-                               ctx.saw_call ? 'C' : ' ',<br class="">-                               ctx.saw_tail_call ? 'T' : ' ');<br class="">-<br class="">                if (ctx.idx * 4 == prev_image_size)<br class="">                        break;<br class="">                prev_image_size = ctx.idx * 4;<br class="">@@ -1596,9 +1586,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">                goto out_off;<br class="">        }<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, image_size, pass, ctx.image);<br class="">-<br class="">        bpf_flush_icache(header, (u8 *)header + header->size);<br class=""><br class="">        if (!prog->is_func || extra_pass) {<br class="">diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c<br class="">index e3e2b57e4e13..197ff8651a56 100644<br class="">--- a/arch/x86/net/bpf_jit_comp.c<br class="">+++ b/arch/x86/net/bpf_jit_comp.c<br class="">@@ -2551,9 +2551,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">                cond_resched();<br class="">        }<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, proglen, pass + 1, image);<br class="">-<br class="">        if (image) {<br class="">                if (!prog->is_func || extra_pass) {<br class="">                        /*<br class="">diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c<br class="">index 429a89c5468b..ca53f20aca73 100644<br class="">--- a/arch/x86/net/bpf_jit_comp32.c<br class="">+++ b/arch/x86/net/bpf_jit_comp32.c<br class="">@@ -2597,9 +2597,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)<br class="">                cond_resched();<br class="">        }<br class=""><br class="">-       if (bpf_jit_enable > 1)<br class="">-               bpf_jit_dump(prog->len, proglen, pass + 1, image);<br class="">-<br class="">        if (image) {<br class="">                bpf_jit_binary_lock_ro(header);<br class="">                prog->bpf_func = (void *)image;<br class="">diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c<br class="">index 5b1ce656baa1..562ace48e1c9 100644<br class="">--- a/net/core/sysctl_net_core.c<br class="">+++ b/net/core/sysctl_net_core.c<br class="">@@ -276,14 +276,10 @@ static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write,<br class="">        tmp.data = &jit_enable;<br class="">        ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);<br class="">        if (write && !ret) {<br class="">-               if (jit_enable < 2 ||<br class="">-                   (jit_enable == 2 && bpf_dump_raw_ok(current_cred()))) {<br class="">-                       *(int *)table->data = jit_enable;<br class="">-                       if (jit_enable == 2)<br class="">-                               pr_warn("bpf_jit_enable = 2 was set! NEVER use this in production, only for JIT debugging!\n");<br class="">-               } else {<br class="">-                       ret = -EPERM;<br class="">-               }<br class="">+               *(int *)table->data = jit_enable;<br class="">+<br class="">+               if (jit_enable == 2)<br class="">+                       pr_warn_once("bpf_jit_enable == 2 was deprecated! Use bpftool prog dump instead.\n");<br class="">        }<br class=""><br class="">        if (write && ret && min == max)<br class="">diff --git a/tools/bpf/.gitignore b/tools/bpf/.gitignore<br class="">index cf53342175e7..5c70cfb9092e 100644<br class="">--- a/tools/bpf/.gitignore<br class="">+++ b/tools/bpf/.gitignore<br class="">@@ -4,4 +4,3 @@ feature<br class=""> bpf_asm<br class=""> bpf_dbg<br class=""> bpf_exp.yacc.*<br class="">-bpf_jit_disasm<br class="">diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile<br class="">index 243b79f2b451..9264d7b0edf6 100644<br class="">--- a/tools/bpf/Makefile<br class="">+++ b/tools/bpf/Makefile<br class="">@@ -74,14 +74,10 @@ $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c<br class=""> $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c<br class="">        $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<<br class=""><br class="">-PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm<br class="">+PROGS = $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm<br class=""><br class=""> all: $(PROGS) bpftool runqslower<br class=""><br class="">-$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'<br class="">-$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o<br class="">-       $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl<br class="">-<br class=""> $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o<br class="">        $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline<br class=""><br class="">@@ -94,16 +90,14 @@ $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c<br class=""><br class=""> clean: bpftool_clean runqslower_clean resolve_btfids_clean<br class="">        $(call QUIET_CLEAN, bpf-progs)<br class="">-       $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \<br class="">+       $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_dbg \<br class="">               $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*<br class="">        $(call QUIET_CLEAN, core-gen)<br class="">        $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf<br class="">        $(Q)$(RM) -r -- $(OUTPUT)feature<br class=""><br class=""> install: $(PROGS) bpftool_install<br class="">-       $(call QUIET_INSTALL, bpf_jit_disasm)<br class="">        $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin<br class="">-       $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm<br class="">        $(call QUIET_INSTALL, bpf_dbg)<br class="">        $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg<br class="">        $(call QUIET_INSTALL, bpf_asm)<br class="">diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c<br class="">deleted file mode 100644<br class="">index a90a5d110f92..000000000000<br class="">--- a/tools/bpf/bpf_jit_disasm.c<br class="">+++ /dev/null<br class="">@@ -1,332 +0,0 @@<br class="">-// SPDX-License-Identifier: GPL-2.0-only<br class="">-/*<br class="">- * Minimal BPF JIT image disassembler<br class="">- *<br class="">- * Disassembles BPF JIT compiler emitted opcodes back to asm insn's for<br class="">- * debugging or verification purposes.<br class="">- *<br class="">- * To get the disassembly of the JIT code, do the following:<br class="">- *<br class="">- *  1) `echo 2 > /proc/sys/net/core/bpf_jit_enable`<br class="">- *  2) Load a BPF filter (e.g. `tcpdump -p -n -s 0 -i eth1 host 192.168.20.0/24`)<br class="">- *  3) Run e.g. `bpf_jit_disasm -o` to read out the last JIT code<br class="">- *<br class="">- * Copyright 2013 Daniel Borkmann <<a href="mailto:borkmann@redhat.com" class="">borkmann@redhat.com</a>><br class="">- */<br class="">-<br class="">-#include <stdint.h><br class="">-#include <stdio.h><br class="">-#include <stdlib.h><br class="">-#include <assert.h><br class="">-#include <unistd.h><br class="">-#include <string.h><br class="">-#include <bfd.h><br class="">-#include <dis-asm.h><br class="">-#include <regex.h><br class="">-#include <fcntl.h><br class="">-#include <sys/klog.h><br class="">-#include <sys/types.h><br class="">-#include <sys/stat.h><br class="">-#include <limits.h><br class="">-#include <tools/dis-asm-compat.h><br class="">-<br class="">-#define CMD_ACTION_SIZE_BUFFER         10<br class="">-#define CMD_ACTION_READ_ALL            3<br class="">-<br class="">-static void get_exec_path(char *tpath, size_t size)<br class="">-{<br class="">-       char *path;<br class="">-       ssize_t len;<br class="">-<br class="">-       snprintf(tpath, size, "/proc/%d/exe", (int) getpid());<br class="">-       tpath[size - 1] = 0;<br class="">-<br class="">-       path = strdup(tpath);<br class="">-       assert(path);<br class="">-<br class="">-       len = readlink(path, tpath, size);<br class="">-       tpath[len] = 0;<br class="">-<br class="">-       free(path);<br class="">-}<br class="">-<br class="">-static void get_asm_insns(uint8_t *image, size_t len, int opcodes)<br class="">-{<br class="">-       int count, i, pc = 0;<br class="">-       char tpath[PATH_MAX];<br class="">-       struct disassemble_info info;<br class="">-       disassembler_ftype disassemble;<br class="">-       bfd *bfdf;<br class="">-<br class="">-       memset(tpath, 0, sizeof(tpath));<br class="">-       get_exec_path(tpath, sizeof(tpath));<br class="">-<br class="">-       bfdf = bfd_openr(tpath, NULL);<br class="">-       assert(bfdf);<br class="">-       assert(bfd_check_format(bfdf, bfd_object));<br class="">-<br class="">-       init_disassemble_info_compat(&info, stdout,<br class="">-                                    (fprintf_ftype) fprintf,<br class="">-                                    fprintf_styled);<br class="">-       info.arch = bfd_get_arch(bfdf);<br class="">-       info.mach = bfd_get_mach(bfdf);<br class="">-       info.buffer = image;<br class="">-       info.buffer_length = len;<br class="">-<br class="">-       disassemble_init_for_target(&info);<br class="">-<br class="">-#ifdef DISASM_FOUR_ARGS_SIGNATURE<br class="">-       disassemble = disassembler(info.arch,<br class="">-                                  bfd_big_endian(bfdf),<br class="">-                                  info.mach,<br class="">-                                  bfdf);<br class="">-#else<br class="">-       disassemble = disassembler(bfdf);<br class="">-#endif<br class="">-       assert(disassemble);<br class="">-<br class="">-       do {<br class="">-               printf("%4x:\t", pc);<br class="">-<br class="">-               count = disassemble(pc, &info);<br class="">-<br class="">-               if (opcodes) {<br class="">-                       printf("\n\t");<br class="">-                       for (i = 0; i < count; ++i)<br class="">-                               printf("%02x ", (uint8_t) image[pc + i]);<br class="">-               }<br class="">-               printf("\n");<br class="">-<br class="">-               pc += count;<br class="">-       } while(count > 0 && pc < len);<br class="">-<br class="">-       bfd_close(bfdf);<br class="">-}<br class="">-<br class="">-static char *get_klog_buff(unsigned int *klen)<br class="">-{<br class="">-       int ret, len;<br class="">-       char *buff;<br class="">-<br class="">-       len = klogctl(CMD_ACTION_SIZE_BUFFER, NULL, 0);<br class="">-       if (len < 0)<br class="">-               return NULL;<br class="">-<br class="">-       buff = malloc(len);<br class="">-       if (!buff)<br class="">-               return NULL;<br class="">-<br class="">-       ret = klogctl(CMD_ACTION_READ_ALL, buff, len);<br class="">-       if (ret < 0) {<br class="">-               free(buff);<br class="">-               return NULL;<br class="">-       }<br class="">-<br class="">-       *klen = ret;<br class="">-       return buff;<br class="">-}<br class="">-<br class="">-static char *get_flog_buff(const char *file, unsigned int *klen)<br class="">-{<br class="">-       int fd, ret, len;<br class="">-       struct stat fi;<br class="">-       char *buff;<br class="">-<br class="">-       fd = open(file, O_RDONLY);<br class="">-       if (fd < 0)<br class="">-               return NULL;<br class="">-<br class="">-       ret = fstat(fd, &fi);<br class="">-       if (ret < 0 || !S_ISREG(fi.st_mode))<br class="">-               goto out;<br class="">-<br class="">-       len = fi.st_size + 1;<br class="">-       buff = malloc(len);<br class="">-       if (!buff)<br class="">-               goto out;<br class="">-<br class="">-       memset(buff, 0, len);<br class="">-       ret = read(fd, buff, len - 1);<br class="">-       if (ret <= 0)<br class="">-               goto out_free;<br class="">-<br class="">-       close(fd);<br class="">-       *klen = ret;<br class="">-       return buff;<br class="">-out_free:<br class="">-       free(buff);<br class="">-out:<br class="">-       close(fd);<br class="">-       return NULL;<br class="">-}<br class="">-<br class="">-static char *get_log_buff(const char *file, unsigned int *klen)<br class="">-{<br class="">-       return file ? get_flog_buff(file, klen) : get_klog_buff(klen);<br class="">-}<br class="">-<br class="">-static void put_log_buff(char *buff)<br class="">-{<br class="">-       free(buff);<br class="">-}<br class="">-<br class="">-static uint8_t *get_last_jit_image(char *haystack, size_t hlen,<br class="">-                                  unsigned int *ilen)<br class="">-{<br class="">-       char *ptr, *pptr, *tmp;<br class="">-       off_t off = 0;<br class="">-       unsigned int proglen;<br class="">-       int ret, flen, pass, ulen = 0;<br class="">-       regmatch_t pmatch[1];<br class="">-       unsigned long base;<br class="">-       regex_t regex;<br class="">-       uint8_t *image;<br class="">-<br class="">-       if (hlen == 0)<br class="">-               return NULL;<br class="">-<br class="">-       ret = regcomp(&regex, "flen=[[:alnum:]]+ proglen=[[:digit:]]+ "<br class="">-                     "pass=[[:digit:]]+ image=[[:xdigit:]]+", REG_EXTENDED);<br class="">-       assert(ret == 0);<br class="">-<br class="">-       ptr = haystack;<br class="">-       memset(pmatch, 0, sizeof(pmatch));<br class="">-<br class="">-       while (1) {<br class="">-               ret = regexec(&regex, ptr, 1, pmatch, 0);<br class="">-               if (ret == 0) {<br class="">-                       ptr += pmatch[0].rm_eo;<br class="">-                       off += pmatch[0].rm_eo;<br class="">-                       assert(off < hlen);<br class="">-               } else<br class="">-                       break;<br class="">-       }<br class="">-<br class="">-       ptr = haystack + off - (pmatch[0].rm_eo - pmatch[0].rm_so);<br class="">-       ret = sscanf(ptr, "flen=%d proglen=%u pass=%d image=%lx",<br class="">-                    &flen, &proglen, &pass, &base);<br class="">-       if (ret != 4) {<br class="">-               regfree(&regex);<br class="">-               return NULL;<br class="">-       }<br class="">-       if (proglen > 1000000) {<br class="">-               printf("proglen of %d too big, stopping\n", proglen);<br class="">-               return NULL;<br class="">-       }<br class="">-<br class="">-       image = malloc(proglen);<br class="">-       if (!image) {<br class="">-               printf("Out of memory\n");<br class="">-               return NULL;<br class="">-       }<br class="">-       memset(image, 0, proglen);<br class="">-<br class="">-       tmp = ptr = haystack + off;<br class="">-       while ((ptr = strtok(tmp, "\n")) != NULL && ulen < proglen) {<br class="">-               tmp = NULL;<br class="">-               if (!strstr(ptr, "JIT code"))<br class="">-                       continue;<br class="">-               pptr = ptr;<br class="">-               while ((ptr = strstr(pptr, ":")))<br class="">-                       pptr = ptr + 1;<br class="">-               ptr = pptr;<br class="">-               do {<br class="">-                       image[ulen++] = (uint8_t) strtoul(pptr, &pptr, 16);<br class="">-                       if (ptr == pptr) {<br class="">-                               ulen--;<br class="">-                               break;<br class="">-                       }<br class="">-                       if (ulen >= proglen)<br class="">-                               break;<br class="">-                       ptr = pptr;<br class="">-               } while (1);<br class="">-       }<br class="">-<br class="">-       assert(ulen == proglen);<br class="">-       printf("%u bytes emitted from JIT compiler (pass:%d, flen:%d)\n",<br class="">-              proglen, pass, flen);<br class="">-       printf("%lx + <x>:\n", base);<br class="">-<br class="">-       regfree(&regex);<br class="">-       *ilen = ulen;<br class="">-       return image;<br class="">-}<br class="">-<br class="">-static void usage(void)<br class="">-{<br class="">-       printf("Usage: bpf_jit_disasm [...]\n");<br class="">-       printf("       -o          Also display related opcodes (default: off).\n");<br class="">-       printf("       -O <file>   Write binary image of code to file, don't disassemble to stdout.\n");<br class="">-       printf("       -f <file>   Read last image dump from file or stdin (default: klog).\n");<br class="">-       printf("       -h          Display this help.\n");<br class="">-}<br class="">-<br class="">-int main(int argc, char **argv)<br class="">-{<br class="">-       unsigned int len, klen, opt, opcodes = 0;<br class="">-       char *kbuff, *file = NULL;<br class="">-       char *ofile = NULL;<br class="">-       int ofd;<br class="">-       ssize_t nr;<br class="">-       uint8_t *pos;<br class="">-       uint8_t *image = NULL;<br class="">-<br class="">-       while ((opt = getopt(argc, argv, "of:O:")) != -1) {<br class="">-               switch (opt) {<br class="">-               case 'o':<br class="">-                       opcodes = 1;<br class="">-                       break;<br class="">-               case 'O':<br class="">-                       ofile = optarg;<br class="">-                       break;<br class="">-               case 'f':<br class="">-                       file = optarg;<br class="">-                       break;<br class="">-               default:<br class="">-                       usage();<br class="">-                       return -1;<br class="">-               }<br class="">-       }<br class="">-<br class="">-       bfd_init();<br class="">-<br class="">-       kbuff = get_log_buff(file, &klen);<br class="">-       if (!kbuff) {<br class="">-               fprintf(stderr, "Could not retrieve log buffer!\n");<br class="">-               return -1;<br class="">-       }<br class="">-<br class="">-       image = get_last_jit_image(kbuff, klen, &len);<br class="">-       if (!image) {<br class="">-               fprintf(stderr, "No JIT image found!\n");<br class="">-               goto done;<br class="">-       }<br class="">-       if (!ofile) {<br class="">-               get_asm_insns(image, len, opcodes);<br class="">-               goto done;<br class="">-       }<br class="">-<br class="">-       ofd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE);<br class="">-       if (ofd < 0) {<br class="">-               fprintf(stderr, "Could not open file %s for writing: ", ofile);<br class="">-               perror(NULL);<br class="">-               goto done;<br class="">-       }<br class="">-       pos = image;<br class="">-       do {<br class="">-               nr = write(ofd, pos, len);<br class="">-               if (nr < 0) {<br class="">-                       fprintf(stderr, "Could not write data to %s: ", ofile);<br class="">-                       perror(NULL);<br class="">-                       goto done;<br class="">-               }<br class="">-               len -= nr;<br class="">-               pos += nr;<br class="">-       } while (len);<br class="">-       close(ofd);<br class="">-<br class="">-done:<br class="">-       put_log_buff(kbuff);<br class="">-       free(image);<br class="">-       return 0;<br class="">-}<br class="">--<br class="">2.27.0</blockquote></div></blockquote></div><br class=""></body></html>