1. 24 Oct, 2017 1 commit
    • Martin KaFai Lau's avatar
      bpf: Add support for prog_name and map_name · df36816a
      Martin KaFai Lau authored
      This patch adds support for prog_name and map_name.
      
      For libbpf.{h,c}, the new functions, bpf_prog_load_name()
      and bpf_create_map_name() is created to avoid breaking the
      existing libbpf.{a,so} user.
      
      libbcc.py is also modified accordingly to reflect the
      availability of the new functions in libbpf.
      
      clang/b_frontend_action.cc, b/codegen_llvm.cc and BPF.cc are
      modified to take advantage of the prog and map name also.
      
      Run the following tests in new and old kernel (old kernel
      in the sense that it does not support the prog/map name):
      
      1) tools/trace.py -K sys_clone
      2) examples/cpp/HelloWorld
      
      Here is the output of the bpf (BPF Snapshot) that
      will be introduced in the later patch:
      [root@arch-fb-vm1 bcc]# ./tools/biosnoop.py
      
      [root@arch-fb-vm1 bcc]# ./build/introspection/bps
            BID TYPE                 UID  #MAPS LoadTime     NAME
            113 kprobe                 0      1 Oct20/13:11  trace_pid_start
            114 kprobe                 0      1 Oct20/13:11  trace_req_start
            115 kprobe                 0      3 Oct20/13:11  trace_req_compl
      
      [root@arch-fb-vm1 bcc]# ./build/introspection/bps 113
            BID TYPE                 UID  #MAPS LoadTime     NAME
            113 kprobe                 0      1 Oct20/13:11  trace_pid_start
      
           MID TYPE            FLAGS         KeySz  ValueSz  MaxEnts NAME
           186 hash            0x0               8       20    10240 infobyreq
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      df36816a
  2. 20 Oct, 2017 1 commit
  3. 18 Oct, 2017 3 commits
  4. 17 Oct, 2017 1 commit
  5. 16 Oct, 2017 3 commits
    • 4ast's avatar
      Merge pull request #1390 from iovisor/yhs_dev · e6e66272
      4ast authored
      attempt to compile with system bpf.h if default compile failed
      e6e66272
    • Yonghong Song's avatar
      bpf: print out the src debug info to a temporary file · dd3e7eaf
      Yonghong Song authored
      Currently, for C++ API and for each func, the original src
      and the rewritten source has been stored in
      BCC_PROG_TAG_DIR directory. This patch allows the
      source debug info (bytecode embedded by source code)
      also stored in the same BCC_PROG_TAG_DIR directory.
      
      This feature is not turned on by default now.
      It requires non-zero (debug_flag & DEBUG_SOURCE).
      The DEBUG_SOURCE enables "-g", with which a lot of more
      llvm insns executed and it may increase application
      RSS overhead by 4M (in my test).
      
      As an example, if you modify examples/cpp/RandomRead.cc
      to enable DEBUG_SOURCE, as below
      -  bpf = new ebpf::BPF();
      +  bpf = new ebpf::BPF(8);
      
      After running the application, you can see:
      -bash-4.3$ ls /var/tmp/bcc/bpf_prog_7f01346289a53cc3/
      on_urandom_read.c  on_urandom_read.dis.txt  on_urandom_read.rewritten.c
      -bash-4.3$ cat /var/tmp/bcc/bpf_prog_7f01346289a53cc3/on_urandom_read.dis.txt
      ; int on_urandom_read(struct urandom_read_args* attr) { // Line  23
         0:	bf 16 00 00 00 00 00 00 	r6 = r1
         1:	b7 01 00 00 00 00 00 00 	r1 = 0
      ; struct event_t event = {}; // Line  24
         2:	63 1a f8 ff 00 00 00 00 	*(u32 *)(r10 - 8) = r1
         3:	63 1a f4 ff 00 00 00 00 	*(u32 *)(r10 - 12) = r1
      .....
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      dd3e7eaf
    • Yonghong Song's avatar
      attempt to compile with system bpf.h if default compile failed · c53d8ae7
      Yonghong Song authored
      Currently, bcc uses its own version of bpf.h which tries to
      sync with upstream header regularly. If the host bpf.h version
      is lower, bcc can still compile as some bcc codes may requires
      a higher version of bpf.h.
      
      Such an approach does have a drawback. Suppose service A,
      statically linked with bcc, runs on kernel version X.
      Now, the kernel upgrades to version Y. After kernel upgrade/reboot,
      service A may not be able to compile since old bcc bpf.h
      may not align with the new kernel headers.
      For such cases, new version of service A needs rollout.
      
      This patch addresses this issue by attempting a second
      compilation using system bpf.h instead. The feature is not on
      by default. To enable it, pass -DBCC_BACKUP_COMPILE=1
      in cmake setup stage.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      c53d8ae7
  6. 12 Oct, 2017 5 commits
  7. 11 Oct, 2017 4 commits
  8. 10 Oct, 2017 3 commits
  9. 08 Oct, 2017 2 commits
    • Paul Chaignon's avatar
      Fix segfault with enumerations · f7f873a2
      Paul Chaignon authored
      When serializing map types to JSON, if it encounters an enumeration,
      the rewriter goes into an infinite loop until it segfaults.  This fix
      properly serializes enumerations in the same way unions and structs
      are.
      
          enum a {
            CHOICE_A,
            CHOICE_B,
          };
          BPF_HASH(m, u32, enum a);
      
      is serialized as:
      
          ["a", ["CHOICE_A","CHOICE_B"], "enum"]
      f7f873a2
    • yonghong-song's avatar
      Merge pull request #1382 from palmtenor/vdso · 54a5b4d1
      yonghong-song authored
      Support resolve vDSO symbols
      54a5b4d1
  10. 07 Oct, 2017 4 commits
  11. 06 Oct, 2017 4 commits
  12. 05 Oct, 2017 4 commits
  13. 04 Oct, 2017 3 commits
    • yonghong-song's avatar
      Merge pull request #1374 from pbhole/dns_matching1 · 782b34f0
      yonghong-song authored
       examples:dns_matching: make it work as a DNS sniffer
      782b34f0
    • Prashant Bhole's avatar
      examples:dns_matching: accept args from user · b2b9133f
      Prashant Bhole authored
      Accepts arguments from user. This change makes it slightly more
      interactive. usage is show with -h option, so no extra documentation
      required for understanding the usage.
      b2b9133f
    • Prashant Bhole's avatar
      examples:dns_matching: make it work as DNS sniffer · af83f6ff
      Prashant Bhole authored
      Reason:
      The intention of initial version of this example was to provide
      a loop-uprolling example and expected functionality was to drop
      DNS packets requesting the DNS name contained in the map.
         But the functionality doesn't work as exepected because the
      BPF program attached to the raw socket only filters the packets
      received by the python program.
      
      With these modifications, it still serves as a loop-unrolling
      example, with slightly different functionality.
      
      Inverted return values of bpf program. It keeps the packet if the
      name in DNS packet is also exists in the map. All other packets
      are dropped.
      Python program is modified to read packets from raw socket.
      DNS data from the packet is parsed and printed using dnslib library.
      af83f6ff
  14. 03 Oct, 2017 2 commits
    • yonghong-song's avatar
      Merge pull request #1365 from sandip4n/add-usdt-ppc64 · 422db709
      yonghong-song authored
      Add basic USDT support for powerpc64
      422db709
    • Yonghong Song's avatar
      add debug option to dump asm insns embedded with source · 91837cac
      Yonghong Song authored
      The patch adds a new debug option "DEBUG_SOURCE = 8" to
      dump insns embedded with source. In C++ API, users
      can change BPF constructor "flag" value to enable debug output.
      In Python API, users can change "debug" value to enable
      debug output. For example, for python test program test_usdt.py,
      the debug output looks like below:
      
      ......
      Disassembly of section .bpf.fn.do_trace1:
      do_trace1:
      ; int do_trace1(struct pt_regs *ctx) { // Line 110
         0:   bf 16 00 00 00 00 00 00         r6 = r1
         1:   b7 01 00 00 00 00 00 00         r1 = 0
      ; struct probe_result_t1 result = {}; // Line 111
         2:   7b 1a f0 ff 00 00 00 00         *(u64 *)(r10 - 16) = r1
      ; switch(ctx->ip) { // Line   5
         3:   79 61 80 00 00 00 00 00         r1 = *(u64 *)(r6 + 128)
         4:   15 01 04 00 d7 06 40 00         if r1 == 4196055 goto 4
         5:   55 01 06 00 ce 06 40 00         if r1 != 4196046 goto 6
      ; case 0x4006ceULL: *((int8_t *)dest) = ctx->ax; __asm__ __volatile__("": : :"memory"); return 0; // Line   6
         6:   79 61 50 00 00 00 00 00         r1 = *(u64 *)(r6 + 80)
      ......
      
      For asm insns, byte code is also dumped out (similar to objdump).
      For source codes, only lines in the module file are printed (as expected).
      The line number is added at the end of source code, which is
      especially helpful for inlined functions.
      
      This functionality is only in llvm 6.x (the trunk version), which
      provides an public interface to create a dwarf context based on
      a set of in-memory debug sections. llvm 5.x also provides
      such a public interface in a different way, and this patch
      does not support it in bcc yet. llvm 4.x and lower do not
      have such a public interface and hence will not be supported
      in bcc.
      
      In this patch, the debug output only goes to stderr.
      A subsequent patch will dump the per-function output into
      <BCC_PROG_TAG_DIR>/bpf_prog_<tag>/ if it is available.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      91837cac