]> asedeno.scripts.mit.edu Git - linux.git/commit
tools: bpftool: add delimiters to multi-function JITed dumps
authorSandipan Das <sandipan@linux.vnet.ibm.com>
Thu, 24 May 2018 06:56:54 +0000 (12:26 +0530)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 24 May 2018 07:20:50 +0000 (09:20 +0200)
commitf7f62c7134288a704f90b137097e1ee689ff25ab
tree368c31f0f2cd07cab7ff8abd445b8dc84aa761ec
parentbd980d43b977c0b6582be906da23b08e0ae1b3dc
tools: bpftool: add delimiters to multi-function JITed dumps

This splits up the contiguous JITed dump obtained via the bpf
system call into more relatable chunks for each function in
the program. If the kernel symbols corresponding to these are
known, they are printed in the header for each JIT image dump
otherwise the masked start address is printed.

Before applying this patch:

  # bpftool prog dump jited id 1

     0: push   %rbp
     1: mov    %rsp,%rbp
  ...
    70: leaveq
    71: retq
    72: push   %rbp
    73: mov    %rsp,%rbp
  ...
    dd: leaveq
    de: retq

  # bpftool -p prog dump jited id 1

  [{
          "pc": "0x0",
          "operation": "push",
          "operands": ["%rbp"
          ]
      },{
  ...
      },{
          "pc": "0x71",
          "operation": "retq",
          "operands": [null
          ]
      },{
          "pc": "0x72",
          "operation": "push",
          "operands": ["%rbp"
          ]
      },{
  ...
      },{
          "pc": "0xde",
          "operation": "retq",
          "operands": [null
          ]
      }
  ]

After applying this patch:

  # echo 0 > /proc/sys/net/core/bpf_jit_kallsyms
  # bpftool prog dump jited id 1

  0xffffffffc02c7000:
     0: push   %rbp
     1: mov    %rsp,%rbp
  ...
    70: leaveq
    71: retq

  0xffffffffc02cf000:
     0: push   %rbp
     1: mov    %rsp,%rbp
  ...
    6b: leaveq
    6c: retq

  # bpftool -p prog dump jited id 1

  [{
          "name": "0xffffffffc02c7000",
          "insns": [{
                  "pc": "0x0",
                  "operation": "push",
                  "operands": ["%rbp"
                  ]
              },{
  ...
              },{
                  "pc": "0x71",
                  "operation": "retq",
                  "operands": [null
                  ]
              }
          ]
      },{
          "name": "0xffffffffc02cf000",
          "insns": [{
                  "pc": "0x0",
                  "operation": "push",
                  "operands": ["%rbp"
                  ]
              },{
  ...
              },{
                  "pc": "0x6c",
                  "operation": "retq",
                  "operands": [null
                  ]
              }
          ]
      }
  ]

  # echo 1 > /proc/sys/net/core/bpf_jit_kallsyms
  # bpftool prog dump jited id 1

  bpf_prog_b811aab41a39ad3d_foo:
     0: push   %rbp
     1: mov    %rsp,%rbp
  ...
    70: leaveq
    71: retq

  bpf_prog_cf418ac8b67bebd9_F:
     0: push   %rbp
     1: mov    %rsp,%rbp
  ...
    6b: leaveq
    6c: retq

  # bpftool -p prog dump jited id 1

  [{
          "name": "bpf_prog_b811aab41a39ad3d_foo",
          "insns": [{
                  "pc": "0x0",
                  "operation": "push",
                  "operands": ["%rbp"
                  ]
              },{
  ...
              },{
                  "pc": "0x71",
                  "operation": "retq",
                  "operands": [null
                  ]
              }
          ]
      },{
          "name": "bpf_prog_cf418ac8b67bebd9_F",
          "insns": [{
                  "pc": "0x0",
                  "operation": "push",
                  "operands": ["%rbp"
                  ]
              },{
  ...
              },{
                  "pc": "0x6c",
                  "operation": "retq",
                  "operands": [null
                  ]
              }
          ]
      }
  ]

Signed-off-by: Sandipan Das <sandipan@linux.vnet.ibm.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/bpf/bpftool/prog.c
tools/bpf/bpftool/xlated_dumper.c
tools/bpf/bpftool/xlated_dumper.h