14 Mar, 2019

2 commits

  • [ Upstream commit b0ca5ecb8e2279d706261f525f1bd0ba9e3fe800 ]

    When updating a percpu map, bpftool currently copies the provided
    value only into the first per CPU copy of the specified value,
    all others instances are left zeroed.

    This change explicitly copies the user-provided bytes to all the
    per CPU instances, keeping the sub-command syntax unchanged.

    v2 -> v3:
    - drop unused argument, as per Quentin's suggestion
    v1 -> v2:
    - rename the helper as per Quentin's suggestion

    Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
    Signed-off-by: Paolo Abeni
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Sasha Levin

    Paolo Abeni
     
  • [ Upstream commit 752bcf80f5549c9901b2e8bc77b2138de55b1026 ]

    Lance reported an issue with bpftool not being able to
    dump program if there are more programs loaded and you
    want to dump any but the first program, like:

    # bpftool prog
    28: kprobe name trace_req_start tag 1dfc28ba8b3dd597 gpl
    loaded_at 2019-01-18T17:02:40+1100 uid 0
    xlated 112B jited 109B memlock 4096B map_ids 13
    29: kprobe name trace_req_compl tag 5b6a5ecc6030a683 gpl
    loaded_at 2019-01-18T17:02:40+1100 uid 0
    xlated 928B jited 575B memlock 4096B map_ids 13,14
    # bpftool prog dum jited tag 1dfc28ba8b3dd597
    0: push %rbp
    1: mov %rsp,%rbp
    ...

    # bpftool prog dum jited tag 5b6a5ecc6030a683
    Error: can't get prog info (29): Bad address

    The problem is in the prog_fd_by_tag function not cleaning
    the struct bpf_prog_info before another request, so the
    previous program length is still in there and kernel assumes
    it needs to dump the program, which fails because there's no
    user pointer set.

    Moving the struct bpf_prog_info declaration into the loop,
    so it gets cleaned before each query.

    Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
    Reported-by: Lance Digby
    Signed-off-by: Jiri Olsa
    Reviewed-by: Quentin Monnet
    Acked-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Sasha Levin

    Jiri Olsa
     

17 Dec, 2018

2 commits

  • [ Upstream commit dde7011a824cfa815b03f853ec985ff46b740939 ]

    This patch fixes a possible null pointer dereference in
    do_load, detected by the semantic patch deref_null.cocci,
    with the following warning:

    ./tools/bpf/bpftool/prog.c:1021:23-25: ERROR: map_replace is NULL but dereferenced.

    The following code has potential null pointer references:
    881 map_replace = reallocarray(map_replace, old_map_fds + 1,
    882 sizeof(*map_replace));
    883 if (!map_replace) {
    884 p_err("mem alloc failed");
    885 goto err_free_reuse_maps;
    886 }

    ...
    1019 err_free_reuse_maps:
    1020 for (i = 0; i < old_map_fds; i++)
    1021 close(map_replace[i].fd);
    1022 free(map_replace);

    Fixes: 3ff5a4dc5d89 ("tools: bpftool: allow reuse of maps with bpftool prog load")
    Co-developed-by: Wen Yang
    Signed-off-by: Wen Yang
    Signed-off-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Sasha Levin

    Jakub Kicinski
     
  • [ Upstream commit 53909030aa29bffe1f8490df62176c2375135652 ]

    Function getline() returns -1 on failure to read a line, thus creating
    an infinite loop in get_fdinfo() if the key is not found. Fix it by
    calling the function only as long as we get a strictly positive return
    value.

    Found by copying the code for a key which is not always present...

    Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
    Signed-off-by: Quentin Monnet
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Sasha Levin

    Quentin Monnet
     

03 Sep, 2018

1 commit


24 Aug, 2018

1 commit

  • When command line parsing fails in the while loop in do_event_pipe()
    because the number of arguments is incorrect or because the keyword is
    unknown, an error message is displayed, but bpftool remains stuck in
    the loop. Make sure we exit the loop upon failure.

    Fixes: f412eed9dfde ("tools: bpftool: add simple perf event output reader")
    Signed-off-by: Quentin Monnet
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Quentin Monnet
     

08 Aug, 2018

1 commit

  • Daniel Borkmann says:

    ====================
    pull-request: bpf-next 2018-08-07

    The following pull-request contains BPF updates for your *net-next* tree.

    The main changes are:

    1) Add cgroup local storage for BPF programs, which provides a fast
    accessible memory for storing various per-cgroup data like number
    of transmitted packets, etc, from Roman.

    2) Support bpf_get_socket_cookie() BPF helper in several more program
    types that have a full socket available, from Andrey.

    3) Significantly improve the performance of perf events which are
    reported from BPF offload. Also convert a couple of BPF AF_XDP
    samples overto use libbpf, both from Jakub.

    4) seg6local LWT provides the End.DT6 action, which allows to
    decapsulate an outer IPv6 header containing a Segment Routing Header.
    Adds this action now to the seg6local BPF interface, from Mathieu.

    5) Do not mark dst register as unbounded in MOV64 instruction when
    both src and dst register are the same, from Arthur.

    6) Define u_smp_rmb() and u_smp_wmb() to their respective barrier
    instructions on arm64 for the AF_XDP sample code, from Brian.

    7) Convert the tcp_client.py and tcp_server.py BPF selftest scripts
    over from Python 2 to Python 3, from Jeremy.

    8) Enable BTF build flags to the BPF sample code Makefile, from Taeung.

    9) Remove an unnecessary rcu_read_lock() in run_lwt_bpf(), from Taehee.

    10) Several improvements to the README.rst from the BPF documentation
    to make it more consistent with RST format, from Tobin.

    11) Replace all occurrences of strerror() by calls to strerror_r()
    in libbpf and fix a FORTIFY_SOURCE build error along with it,
    from Thomas.

    12) Fix a bug in bpftool's get_btf() function to correctly propagate
    an error via PTR_ERR(), from Yue.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

06 Aug, 2018

1 commit


03 Aug, 2018

1 commit


31 Jul, 2018

1 commit

  • I hit the following problem when I tried to use bpftool
    to dump a percpu array.

    $ sudo ./bpftool map show
    61: percpu_array name stub flags 0x0
    key 4B value 4B max_entries 1 memlock 4096B
    ...
    $ sudo ./bpftool map dump id 61
    bpftool: malloc.c:2406: sysmalloc: Assertion
    `(old_top == initial_top (av) && old_size == 0) || \
    ((unsigned long) (old_size) >= MINSIZE && \
    prev_inuse (old_top) && \
    ((unsigned long) old_end & (pagesize - 1)) == 0)'
    failed.
    Aborted

    Further debugging revealed that this is due to
    miscommunication between bpftool and kernel.
    For example, for the above percpu_array with value size of 4B.
    The map info returned to user space has value size of 4B.

    In bpftool, the values array for lookup is allocated like:
    info->value_size * get_possible_cpus() = 4 * get_possible_cpus()
    In kernel (kernel/bpf/syscall.c), the values array size is
    rounded up to multiple of 8.
    round_up(map->value_size, 8) * num_possible_cpus()
    = 8 * num_possible_cpus()
    So when kernel copies the values to user buffer, the kernel will
    overwrite beyond user buffer boundary.

    This patch fixed the issue by allocating and stepping through
    percpu map value array properly in bpftool.

    Fixes: 71bb428fe2c19 ("tools: bpf: add bpftool")
    Signed-off-by: Yonghong Song
    Signed-off-by: Daniel Borkmann

    Yonghong Song
     

26 Jul, 2018

1 commit


25 Jul, 2018

2 commits


20 Jul, 2018

1 commit

  • Arguments of 'pin' subcommand should be checked
    at the very beginning of do_pin_any().
    Otherwise segfault errors can occur when using
    'map pin' or 'prog pin' commands, so fix it.

    # bpftool prog pin id
    Segmentation fault

    Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
    Reviewed-by: Jakub Kicinski
    Reported-by: Taehee Yoo
    Signed-off-by: Taeung Song
    Signed-off-by: Daniel Borkmann

    Taeung Song
     

17 Jul, 2018

1 commit


14 Jul, 2018

2 commits

  • This patch augments the output of bpftool's map dump and map lookup
    commands to print data along side btf info, if the correspondin btf
    info is available. The outputs for each of map dump and map lookup
    commands are augmented in two ways:

    1. when neither of -j and -p are supplied, btf-ful map data is printed
    whose aim is human readability. This means no commitments for json- or
    backward- compatibility.

    2. when either -j or -p are supplied, a new json object named
    "formatted" is added for each key-value pair. This object contains the
    same data as the key-value pair, but with btf info. "formatted" object
    promises json- and backward- compatibility. Below is a sample output.

    $ bpftool map dump -p id 8
    [{
    "key": ["0x0f","0x00","0x00","0x00"
    ],
    "value": ["0x03", "0x00", "0x00", "0x00", ...
    ],
    "formatted": {
    "key": 15,
    "value": {
    "int_field": 3,
    ...
    }
    }
    }
    ]

    This patch calls btf_dumper introduced in previous patch to accomplish
    the above. Indeed, btf-ful info is only displayed if btf data for the
    given map is available. Otherwise existing output is displayed as-is.

    Signed-off-by: Okash Khawaja
    Acked-by: Martin KaFai Lau
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Okash Khawaja
     
  • This consumes functionality exported in the previous patch. It does the
    main job of printing with BTF data. This is used in the following patch
    to provide a more readable output of a map's dump. It relies on
    json_writer to do json printing. Below is sample output where map keys
    are ints and values are of type struct A:

    typedef int int_type;
    enum E {
    E0,
    E1,
    };

    struct B {
    int x;
    int y;
    };

    struct A {
    int m;
    unsigned long long n;
    char o;
    int p[8];
    int q[4][8];
    enum E r;
    void *s;
    struct B t;
    const int u;
    int_type v;
    unsigned int w1: 3;
    unsigned int w2: 3;
    };

    $ sudo bpftool map dump id 14
    [{
    "key": 0,
    "value": {
    "m": 1,
    "n": 2,
    "o": "c",
    "p": [15,16,17,18,15,16,17,18
    ],
    "q": [[25,26,27,28,25,26,27,28
    ],[35,36,37,38,35,36,37,38
    ],[45,46,47,48,45,46,47,48
    ],[55,56,57,58,55,56,57,58
    ]
    ],
    "r": 1,
    "s": 0x7ffd80531cf8,
    "t": {
    "x": 5,
    "y": 10
    },
    "u": 100,
    "v": 20,
    "w1": 0x7,
    "w2": 0x3
    }
    }
    ]

    This patch uses json's {} and [] to imply struct/union and array. More
    explicit information can be added later. For example, a command line
    option can be introduced to print whether a key or value is struct
    or union, name of a struct etc. This will however come at the expense
    of duplicating info when, for example, printing an array of structs.
    enums are printed as ints without their names.

    Signed-off-by: Okash Khawaja
    Acked-by: Martin KaFai Lau
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Okash Khawaja
     

13 Jul, 2018

1 commit

  • Provide a new Makefile.helpers in tools/bpf, in order to build and
    install the man page for eBPF helpers. This Makefile is also included in
    the one used to build bpftool documentation, so that it can be called
    either on its own (cd tools/bpf && make -f Makefile.helpers) or from
    bpftool directory (cd tools/bpf/bpftool && make doc, or
    cd tools/bpf/bpftool/Documentation && make helpers).

    Makefile.helpers is not added directly to bpftool to avoid changing its
    Makefile too much (helpers are not 100% directly related with bpftool).
    But the possibility to build the page from bpftool directory makes us
    able to package the helpers man page with bpftool, and to install it
    along with bpftool documentation, so that the doc for helpers becomes
    easily available to developers through the "man" program.

    Cc: linux-man@vger.kernel.org
    Suggested-by: Daniel Borkmann
    Signed-off-by: Quentin Monnet
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Quentin Monnet
     

12 Jul, 2018

6 commits

  • Add map parameter to prog load which will allow reuse of existing
    maps instead of creating new ones.

    We need feature detection and compat code for reallocarray, since
    it's not available in many libc versions.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Acked-by: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • reallocarray() is a safer variant of realloc which checks for
    multiplication overflow in case of array allocation. Since it's
    not available in Glibc < 2.26 import kernel's overflow.h and
    add a static inline implementation when needed. Use feature
    detection to probe for existence of reallocarray.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Reviewed-by: Jiong Wang
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • bpf_prog_load() is a very useful helper but it doesn't give us full
    flexibility of modifying the BPF objects before loading. Open code
    bpf_prog_load() in bpftool so we can add extra logic in following
    commits.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Acked-by: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • Sometimes program section names don't match with libbpf's expectation.
    In particular XDP's default section names differ between libbpf and
    iproute2. Allow users to pass program type on command line. Name
    the types like the libbpf expected section names.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • Extend the bpftool prog load command to also accept "dev"
    parameter, which will allow us to load programs onto devices.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • Add a new macro for printing more informative message than straight
    usage() when parameters are missing, and use it for prog do_load().
    Save the object and pin path argument to variables for clarity.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     

07 Jul, 2018

3 commits

  • This commit adds a bash completion to the bpftool cgroup tree
    command.

    Signed-off-by: Roman Gushchin
    Cc: Jakub Kicinski
    Cc: Quentin Monnet
    Cc: Daniel Borkmann
    Cc: Alexei Starovoitov
    Acked-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Roman Gushchin
     
  • Describe cgroup tree command in the corresponding bpftool man page.

    Signed-off-by: Roman Gushchin
    Acked-by: Jakub Kicinski
    Cc: Quentin Monnet
    Cc: Daniel Borkmann
    Cc: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann

    Roman Gushchin
     
  • This commit introduces a new bpftool command: cgroup tree.
    The idea is to iterate over the whole cgroup tree and print
    all attached programs.

    I was debugging a bpf/systemd issue, and found, that there is
    no simple way to listen all bpf programs attached to cgroups.
    I did master something in bash, but after some time got tired of it,
    and decided, that adding a dedicated bpftool command could be
    a better idea.

    So, here it is:
    $ sudo ./bpftool cgroup tree
    CgroupPath
    ID AttachType AttachFlags Name
    /sys/fs/cgroup/system.slice/systemd-machined.service
    18 ingress
    17 egress
    /sys/fs/cgroup/system.slice/systemd-logind.service
    20 ingress
    19 egress
    /sys/fs/cgroup/system.slice/systemd-udevd.service
    16 ingress
    15 egress
    /sys/fs/cgroup/system.slice/systemd-journald.service
    14 ingress
    13 egress

    Signed-off-by: Roman Gushchin
    Acked-by: Jakub Kicinski
    Cc: Quentin Monnet
    Cc: Daniel Borkmann
    Cc: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann

    Roman Gushchin
     

04 Jul, 2018

1 commit

  • Daniel Borkmann says:

    ====================
    pull-request: bpf-next 2018-07-03

    The following pull-request contains BPF updates for your *net-next* tree.

    The main changes are:

    1) Various improvements to bpftool and libbpf, that is, bpftool build
    speed improvements, missing BPF program types added for detection
    by section name, ability to load programs from '.text' section is
    made to work again, and better bash completion handling, from Jakub.

    2) Improvements to nfp JIT's map read handling which allows for optimizing
    memcpy from map to packet, from Jiong.

    3) New BPF sample is added which demonstrates XDP in combination with
    bpf_perf_event_output() helper to sample packets on all CPUs, from Toke.

    4) Add a new BPF kselftest case for tracking connect(2) BPF hooks
    infrastructure in combination with TFO, from Andrey.

    5) Extend the XDP/BPF xdp_rxq_info sample code with a cmdline option to
    read payload from packet data in order to use it for benchmarking.
    Also for '--action XDP_TX' option implement swapping of MAC addresses
    to avoid drops on some hardware seen during testing, from Jesper.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

01 Jul, 2018

4 commits

  • Remove options (in getopt() sense, i.e. starting with a dash like
    -n or --NAME) while parsing arguments for bash completions. This
    allows us to refer to position-dependent parameters better, and
    complete options at any point.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • --bpffs is not suggested by bash completions.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • Drop my author comments, those are from the early days of
    bpftool and make little sense in tree, where we have quite
    a few people contributing and git to attribute the work.

    While at it bump some copyrights.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • Commit 4bfe3bd3cc35 ("tools/bpftool: use version from the kernel
    source tree") added version to bpftool. The version used is
    equal to the kernel version and obtained by running make kernelversion
    against kernel source tree. Version is then communicated
    to the sources with a command line define set in CFLAGS.

    Use a simply expanded variable for the version, otherwise the
    recursive make will run every time CFLAGS are used.

    This brings the single-job compilation time for me from almost
    16 sec down to less than 4 sec.

    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     

22 Jun, 2018

2 commits

  • Remembering to close all descriptors and free memory may not seem
    important in a user space tool like bpftool, but if we were to run
    in batch mode the consumed resources start to add up quickly. Make
    sure program load closes the libbpf object (which unloads and frees
    it).

    Fixes: 49a086c201a9 ("bpftool: implement prog load command")
    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Acked-by: Song Liu
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     
  • do_pin_fd() will already print out an error message if something
    goes wrong. Printing another error is unnecessary and will break
    JSON output, since error messages are full objects:

    $ bpftool -jp prog load tracex1_kern.o /sys/fs/bpf/a
    {
    "error": "can't pin the object (/sys/fs/bpf/a): File exists"
    },{
    "error": "failed to pin program"
    }

    Fixes: 49a086c201a9 ("bpftool: implement prog load command")
    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Acked-by: Song Liu
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     

15 Jun, 2018

1 commit

  • BPF program load time is reported from the kernel relative to boot time.
    If conversion to wall clock does not take nanosecond parts into account,
    the load time reported by bpftool may differ by one second from run to
    run. This means JSON object reported by bpftool for a program will
    randomly change.

    Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
    Signed-off-by: Jakub Kicinski
    Reviewed-by: Quentin Monnet
    Signed-off-by: Daniel Borkmann

    Jakub Kicinski
     

13 Jun, 2018

1 commit

  • Commit b04df400c302 ("tools/bpftool: add perf subcommand")
    introduced bpftool subcommand perf to query bpf program
    kuprobe and tracepoint attachments.

    The perf subcommand will first test whether bpf subcommand
    BPF_TASK_FD_QUERY is supported in kernel or not. It does it
    by opening a file with argv[0] and feeds the file descriptor
    and current task pid to the kernel for querying.

    Such an approach won't work if the argv[0] cannot be opened
    successfully in the current directory. This is especially
    true when bpftool is accessible through PATH env variable.
    The error below reflects the open failure for file argv[0]
    at home directory.

    [yhs@localhost ~]$ which bpftool
    /usr/local/sbin/bpftool
    [yhs@localhost ~]$ bpftool perf
    Error: perf_query_support: No such file or directory

    To fix the issue, let us open root directory ("/")
    which exists in every linux system. With the fix, the
    error message will correctly reflect the permission issue.

    [yhs@localhost ~]$ which bpftool
    /usr/local/sbin/bpftool
    [yhs@localhost ~]$ bpftool perf
    Error: perf_query_support: Operation not permitted
    HINT: non root or kernel doesn't support TASK_FD_QUERY

    Fixes: b04df400c302 ("tools/bpftool: add perf subcommand")
    Reported-by: Alexei Starovoitov
    Signed-off-by: Yonghong Song
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Yonghong Song
     

30 May, 2018

2 commits


25 May, 2018

1 commit

  • The new command "bpftool perf [show | list]" will traverse
    all processes under /proc, and if any fd is associated
    with a perf event, it will print out related perf event
    information. Documentation is also added.

    Below is an example to show the results using bcc commands.
    Running the following 4 bcc commands:
    kprobe: trace.py '__x64_sys_nanosleep'
    kretprobe: trace.py 'r::__x64_sys_nanosleep'
    tracepoint: trace.py 't:syscalls:sys_enter_nanosleep'
    uprobe: trace.py 'p:/home/yhs/a.out:main'

    The bpftool command line and result:

    $ bpftool perf
    pid 21711 fd 5: prog_id 5 kprobe func __x64_sys_write offset 0
    pid 21765 fd 5: prog_id 7 kretprobe func __x64_sys_nanosleep offset 0
    pid 21767 fd 5: prog_id 8 tracepoint sys_enter_nanosleep
    pid 21800 fd 5: prog_id 9 uprobe filename /home/yhs/a.out offset 1159

    $ bpftool -j perf
    [{"pid":21711,"fd":5,"prog_id":5,"fd_type":"kprobe","func":"__x64_sys_write","offset":0}, \
    {"pid":21765,"fd":5,"prog_id":7,"fd_type":"kretprobe","func":"__x64_sys_nanosleep","offset":0}, \
    {"pid":21767,"fd":5,"prog_id":8,"fd_type":"tracepoint","tracepoint":"sys_enter_nanosleep"}, \
    {"pid":21800,"fd":5,"prog_id":9,"fd_type":"uprobe","filename":"/home/yhs/a.out","offset":1159}]

    $ bpftool prog
    5: kprobe name probe___x64_sys tag e495a0c82f2c7a8d gpl
    loaded_at 2018-05-15T04:46:37-0700 uid 0
    xlated 200B not jited memlock 4096B map_ids 4
    7: kprobe name probe___x64_sys tag f2fdee479a503abf gpl
    loaded_at 2018-05-15T04:48:32-0700 uid 0
    xlated 200B not jited memlock 4096B map_ids 7
    8: tracepoint name tracepoint__sys tag 5390badef2395fcf gpl
    loaded_at 2018-05-15T04:48:48-0700 uid 0
    xlated 200B not jited memlock 4096B map_ids 8
    9: kprobe name probe_main_1 tag 0a87bdc2e2953b6d gpl
    loaded_at 2018-05-15T04:49:52-0700 uid 0
    xlated 200B not jited memlock 4096B map_ids 9

    $ ps ax | grep "python ./trace.py"
    21711 pts/0 T 0:03 python ./trace.py __x64_sys_write
    21765 pts/0 S+ 0:00 python ./trace.py r::__x64_sys_nanosleep
    21767 pts/2 S+ 0:00 python ./trace.py t:syscalls:sys_enter_nanosleep
    21800 pts/3 S+ 0:00 python ./trace.py p:/home/yhs/a.out:main
    22374 pts/1 S+ 0:00 grep --color=auto python ./trace.py

    Reviewed-by: Jakub Kicinski
    Signed-off-by: Yonghong Song
    Signed-off-by: Alexei Starovoitov

    Yonghong Song
     

24 May, 2018

1 commit

  • 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
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Sandipan Das