Skip to content
Snippets Groups Projects
  1. Feb 22, 2021
  2. Aug 03, 2020
  3. May 25, 2020
  4. Apr 29, 2020
    • Sumanth Korikkar's avatar
      bcc: Support bpf_probe_read_user in trace.py · 7cbd074c
      Sumanth Korikkar authored
      
      Arguments of a probe point can be either user pointer or kernel
      pointer.
      
      Previously:
      - tools/trace.py 'do_sys_open "%s", arg2'
        When reading arg2 as char *, it would resolve to bpf_probe_read.
      
      Now:
      - tools/trace.py 'do_sys_open "%s", arg2@user'
        - When reading arg2 as char *, it is resolved to bpf_probe_read_user.
      - tools/trace.py 'do_sys_open (STRCMP("test.txt", arg2@user)) "%s", arg2'
        - For arg2 char * read, bpf_probe_read_user is utilized
      
      To distinguish this, add arg@user.
      - All userspace probes char *read converted to bpf_probe_read_user
      - Syscall/kprobes with arg[1-6]@user attribute are converted to
        bpf_probe_read_user.
      
      Signed-off-by: default avatarSumanth Korikkar <sumanthk@linux.ibm.com>
      Acked-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      7cbd074c
  5. Mar 09, 2020
  6. Dec 21, 2019
  7. Dec 06, 2019
  8. Nov 27, 2019
  9. Oct 20, 2019
    • yonghong-song's avatar
      support cgroup level tracing in trace.py (#2562) · c2a530b3
      yonghong-song authored
      
      This patch added cgroup based filtering in trace.py.
      
      If a cgroup path is specified by the user, one cgroup
      array map will be added to the program:
        BPF_CGROUP_ARRAY(__cgroup, 1);
      
      Each probe will have a filter like below:
        if (__cgroup.check_current_task(0) <= 0) { return 0; }
      to filter out any events not happening in the cgroup
      hierarchy as specified by the user.
      
      The trace.py updated the `__cgroup` map with user provided
      cgroup path information before attaching bpf functions
      to events for probe function(s).
      
      An example like below:
        $ trace.py -v -c /sys/fs/cgroup/system.slice/workload.service \
          '__x64_sys_nanosleep' '__x64_sys_clone'
           PID     TID     COMM            FUNC
           3191578 3191583 BaseAgentEvents __x64_sys_nanosleep
           3191578 3191579 FutureTimekeepr __x64_sys_clone
           3191578 3191583 BaseAgentEvents __x64_sys_nanosleep
           3191578 3191583 BaseAgentEvents __x64_sys_nanosleep
      since workload.service only contains one process 3191578.
      
      Going up the hierarchy to system.slice will have more processes
      and hence more results:
        $ trace.py -v -c /sys/fs/cgroup/system.slice \
          '__x64_sys_nanosleep' '__x64_sys_clone'
           PID     TID     COMM            FUNC
           591542  591677  dynoScribe      __x64_sys_nanosleep
           591610  591613  mcreplay2       __x64_sys_nanosleep
           553252  553252  sleeperagent    __x64_sys_nanosleep
           591610  591613  mcreplay2       __x64_sys_nanosleep
           553252  553252  sleeperagent    __x64_sys_nanosleep
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      c2a530b3
  10. Jun 26, 2019
  11. Jan 23, 2019
    • vijunag's avatar
      support symbol resolution of short-lived process. (#2144) · 9924e64e
      vijunag authored
      New command line options have been added to tools/trace.py to support the 
      new BUILD_ID stackmap. List of symbol files can be added to the script to 
      resolve symbols from build id as reported by the kernel in the stack trace
      Updated man page and added an example usage
      9924e64e
  12. Jan 16, 2019
  13. Jan 14, 2019
  14. Dec 27, 2018
    • Prashant Bhole's avatar
      trace.py: fix compiler warning (#2094) · 05765eee
      Prashant Bhole authored
      Compiler shows warning "incompatible integer to pointer conversion
      initializing" while compiling bpf program.
      This patch adds necessary typecast when assigning PT_REGS_PARAM vaules
      to struct pt_regs pointer
      05765eee
  15. Oct 09, 2018
    • jeromemarchand's avatar
      Bytes/string encoding (#2004) · b96ebcd2
      jeromemarchand authored
      * tools: uses 'replace' error handler by default in decode()
      
      Tools might encouter characters from non utf-8 charset (e.g. a file
      name). When this happen, it's better to replace the unexpected
      character by a question mark than crash the tool when all we do is
      to print the string.
      
      * tools: fix a bytes/string issue in attach_perf_event()
      b96ebcd2
  16. Sep 19, 2018
    • yonghong-song's avatar
      support "long" and "unsigned long" type in trace.py (#1977) · f720257c
      yonghong-song authored
      
      Currently, trace.py does not support "long" and "unsigned long"
      types and it often caught users with a surprise and they are
      not sure what is the problem. For example, for kernel function:
        void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs)
      The following
        $ sudo ./trace.py 'blk_mq_delay_kick_requeue_list(void *notused, unsigned long msecs) "msecs = %lu", msecs'
        list index out of range
      
      With this patch,
        $ sudo ./trace.py 'blk_mq_delay_kick_requeue_list(void *notused, unsigned long msecs) "msecs = %lu", msecs'
        PID     TID     COMM            FUNC             -
        ^C
        $ sudo ./trace.py 'blk_mq_delay_kick_requeue_list(void *notused, unsigned long msecs) "msecs = %ld", msecs'
        PID     TID     COMM            FUNC             -
        ^C
        $ sudo ./trace.py 'blk_mq_delay_kick_requeue_list(void *notused, unsigned long msecs) "msecs = %lx", msecs'
        PID     TID     COMM            FUNC             -
        ^C
        $
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      f720257c
  17. Sep 18, 2018
    • yonghong-song's avatar
      fix a trace.py problem (#1973) · 61484e17
      yonghong-song authored
      
      Currently, trace.py failed for the following command:
        $ sudo ./trace.py 'filename_lookup(int dfd, struct filename *name) "%s", name->name'
        ...
        0: (bf) r6 = r1
        1: (79) r7 = *(u64 *)(r6 +104)
        ...
        32: (15) if r1 == 0x0 goto pc+5
        R0=inv(id=0) R1=inv(id=0) R6=ctx(id=0,off=0,imm=0) R7=inv(id=0)
        R8=inv0 R10=fp0,call_-1 fp-8=0 fp-16=0 fp-24=0 fp-32=0 fp-40=0 fp-48=0 fp-56=0 fp-64=0 fp-72=0 fp-80=0
        33: (79) r3 = *(u64 *)(r7 +0)
        R7 invalid mem access 'inv'
      
      For string format argument, the trace.py generates the below code:
              if (name->name != 0) {
                      bpf_probe_read(&__data.v0, sizeof(__data.v0), (void *)name->name);
              }
      Right now, bcc skips the rewriter for the third argument of bpf_probe_read to avoid
      unnecessary nested bpf_probe_read and other potential issues.
      This causes name->name memory access not transformed with bpf_probe_read and hence
      the verifier complains.
      
      To fix the issue, this patch did the following transformation using an
      temporary variable to hold the src address:
              if (name->name != 0) {
                      void *__tmp = (void *)name->name;
                      bpf_probe_read(&__data.v0, sizeof(__data.v0), __tmp);
              }
      This way, rewriter can do the work properly.
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      61484e17
  18. Jul 27, 2018
    • Nikita V. Shirokov's avatar
      [trace.py]: allow to use STRCMP helper with binary values (#1900) · 3953c708
      Nikita V. Shirokov authored
      * [trace.py]: allow to use STRCMP helper with binary values
      
      Summary:
      sometimes in probe you want to compare char* w/ some predefined value
      which is not a string. e.g. setsockopt syscall has signature like this:
      sys_setsockopt(int fd, int level, int optname, char* optval, int optlen)
      and if you want to catch where/who is setting up specific value you are
      forced to compare optval against some predefined array. it's not
      possible today w/ trace.py and in this diff i'm adding such ability
      
      Test Plan:
      as example: we want to catch setsockopt when someone is setting up
      IP_TOS equal to 108
      trace.py 'sys_setsockopt(int fd, int level, int optname, char* optval,
      int optlen)(level==0 && optname == 1 && STRCMP("{0x6C,0x00, 0x00,
      0x00}", optval))' -U -M 1 --bin_cmp -v
      
      without this new modifier:
      static inline bool streq_0(char const *ignored, uintptr_t str) {
              char needle[] = "{0x6C,0x00, 0x00, 0x00}";
              char haystack[sizeof(needle)];
              bpf_probe_read(&haystack, sizeof(haystack), (void *)str);
              for (int i = 0; i < sizeof(needle) - 1; ++i) {
                      if (needle[i] != haystack[i]) {
                              return false;
                      }
              }
              return true;
      }
      
      // see needle is qouted above
      
      with:
      
      tatic inline bool streq_0(char const *ignored, uintptr_t str) {
              char needle[] = {0x6C,0x00, 0x00, 0x00};
              char haystack[sizeof(needle)];
              bpf_probe_read(&haystack, sizeof(haystack), (void *)str);
              for (int i = 0; i < sizeof(needle) - 1; ++i) {
                      if (needle[i] != haystack[i]) {
                              return false;
                      }
              }
              return true;
      }
      
      ...
      PID     TID     COMM            FUNC             -
      1855611 1863183 worker          sys_setsockopt   found
      
      * adding example of --bin_cmp flag usage
      3953c708
  19. Jun 13, 2018
    • yonghong-song's avatar
      generate indirect parameter assignment if arch uses syscall wrapper (#1816) · 2da34267
      yonghong-song authored
      
      Fix issue #1802.
      
      On x64, the following commit (in 4.17) changed the raw parameter passed to
      the syscall entry function from a list of parameters supplied in user space
      to a single `pt_regs *` parameter. Also in 4.17, x64 syscall entry function
      is changed from `sys_<name>` to `__x64_sys_<name>`.
      
      ```
      commit fa697140f9a20119a9ec8fd7460cc4314fbdaff3
      Author: Dominik Brodowski <linux@dominikbrodowski.net>
      Date:   Thu Apr 5 11:53:02 2018 +0200
      
          syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls
      
          Let's make use of ARCH_HAS_SYSCALL_WRAPPER=y on pure 64-bit x86-64 systems:
      
          Each syscall defines a stub which takes struct pt_regs as its only
          argument. It decodes just those parameters it needs, e.g:
      
                  asmlinkage long sys_xyzzy(const struct pt_regs *regs)
                  {
                          return SyS_xyzzy(regs->di, regs->si, regs->dx);
                  }
      
          This approach avoids leaking random user-provided register content down
          the call chain.
      
          ...
      ```
      
      In bcc, we support kprobe function signatures in the bpf program.
      The rewriter will automatically generate proper assignment to
      these parameters. With the above function signature change, the
      original method does not work any more.
      
      This patch enhanced rewriter to generate two version codes guarded
      with CONFIG_ARCH_HAS_SYSCALL_WRAPPER. But we need to identify
      whether a function will be attached to syscall entry function
      or not during prog load time at which time the program has not
      attached to any event.
      
      The prefix `kprobe__` is used for kprobe autoload, we can use
      `kprobe____x64_sys_` as the prefix to identify x64 syscall entry
      functions. To support other architecture or not-autoloading program,
      the prefix `syscall__` is introduced to signal it is a syscall
      entry function.
      
      trace.py and other tools which uses kprobe syscall entry functions
      are also modified with the new interface so that they can
      work properly with 4.17.
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      2da34267
  20. Apr 19, 2018
  21. Mar 02, 2018
  22. Feb 02, 2018
  23. Jan 31, 2018
  24. Jan 25, 2018
    • Yonghong Song's avatar
      add a probe alias $task in trace.py · f92fef26
      Yonghong Song authored
      
      The $task refers to the current task. In my particular case, I need
      to trace the number of users for file system associated with the current
      task. With the probe alias $task, trace.py can easily trace this event
      
        ......
        trace.py -I 'linux/fs_struct.h' 'mntns_install "users = %d", $task->fs->users'
        PID     TID     COMM            FUNC             -
        176566  176566  python2.7       mntns_install    users = 2
        176566  176566  python2.7       mntns_install    users = 2
        ......
      
      With $task probe alias, kernel tast_struct fields can be used in trace.py
      filter or output easily even if they cannot be accessed through input
      parameters.
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      f92fef26
  25. Jan 24, 2018
  26. Dec 16, 2017
  27. Dec 14, 2017
  28. Oct 07, 2017
  29. Jul 14, 2017
  30. Mar 26, 2017
    • Rafael F's avatar
      Python 3 compatibility fixes around string handling (#986) · 78948e4a
      Rafael F authored
      This fixes the bcc module and all the affected tools for issues related to string handling in Python 3. Specifically, when passing Python strings to C libraries they are encoded as ASCII, and when constructing Python strings from C strings, they are decoded first.
      78948e4a
  31. Mar 11, 2017
  32. Mar 04, 2017
    • Paul Chaignon's avatar
      Travis CI build to check compliance with PEP8 (#987) · 956ca1c8
      Paul Chaignon authored
      * Travis CI build to check compliance with PEP8
      
      * argdist: linter cleanup
      
      * dbslower: linter cleanup
      
      * dbstat: linter cleanup
      
      * memleak: linter cleanup
      
      * syscount: linter cleanup
      
      * tplist: linter cleanup
      
      * trace: linter cleanup
      
      * ucalls: linter cleanup
      
      * uflow: linter cleanup
      
      * ugc: linter cleanup
      
      * uobjnew: linter cleanup
      
      * ustat: linter cleanup
      956ca1c8
  33. Feb 27, 2017
    • Mark Drayton's avatar
      Make perf ring buffer size configurable · 5f5687e4
      Mark Drayton authored
      As discussed in #966, this PR makes the size of the ring buffer used to send
      data to userspace configurable. It changes the Python, Lua and C++ APIs to
      expose this knob.
      
      It also defaults the buffer size to a larger value (64 pages per CPU, an 8x
      increase) for several tools which produce a lot of output, as well as making it
      configurable in `trace` via a `-b` flag.
      5f5687e4
  34. Feb 21, 2017
  35. Feb 20, 2017
    • Sasha Goldshtein's avatar
      trace, argdist: Treat small USDT arguments correctly · 3a5256f1
      Sasha Goldshtein authored
      trace and argdist currently only work correctly for USDT arguments
      whose size is exactly 8 bytes. Smaller types, such as chars, shorts,
      ints (signed or unsigned) are not treated correctly. The reason is
      that the produced program would invoke the `bpf_usdt_readarg` helper
      with the address of a u64 local variable, and then cast that variable
      to the user-specified type derived from the format string. However,
      the `bpf_usdt_readarg` rewriting then passes `sizeof(u64)` to the
      generated `bpf_..._readarg` macro, which then fails to read anything
      because the provided size doesn't match the argument size it knows
      about.
      
      The fix is fairly easy: instead of declaring a u64 unconditionally
      and reading into that variable with `bpf_usdt_readarg`, declare a
      variable that has the correct type according to what we know about
      the USDT probe.
      3a5256f1
  36. Feb 13, 2017
  37. Feb 09, 2017
Loading