1. 27 11月, 2018 1 次提交
  2. 26 11月, 2018 1 次提交
  3. 24 11月, 2018 1 次提交
  4. 21 11月, 2018 1 次提交
  5. 09 11月, 2018 1 次提交
    • D
      bpftool: Improve handling of ENOENT on map dumps · bf598a8f
      David Ahern 提交于
      bpftool output is not user friendly when dumping a map with only a few
      populated entries:
      
          $ bpftool map
          1: devmap  name tx_devmap  flags 0x0
                  key 4B  value 4B  max_entries 64  memlock 4096B
          2: array  name tx_idxmap  flags 0x0
                  key 4B  value 4B  max_entries 64  memlock 4096B
      
          $ bpftool map dump id 1
          key:
          00 00 00 00
          value:
          No such file or directory
          key:
          01 00 00 00
          value:
          No such file or directory
          key:
          02 00 00 00
          value:
          No such file or directory
          key: 03 00 00 00  value: 03 00 00 00
      
      Handle ENOENT by keeping the line format sane and dumping
      "<no entry>" for the value
      
          $ bpftool map dump id 1
          key: 00 00 00 00  value: <no entry>
          key: 01 00 00 00  value: <no entry>
          key: 02 00 00 00  value: <no entry>
          key: 03 00 00 00  value: 03 00 00 00
          ...
      Signed-off-by: NDavid Ahern <dsahern@gmail.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      bf598a8f
  6. 08 11月, 2018 1 次提交
    • Q
      tools: bpftool: adjust rlimit RLIMIT_MEMLOCK when loading programs, maps · 8302b9bd
      Quentin Monnet 提交于
      The limit for memory locked in the kernel by a process is usually set to
      64 kbytes by default. This can be an issue when creating large BPF maps
      and/or loading many programs. A workaround is to raise this limit for
      the current process before trying to create a new BPF map. Changing the
      hard limit requires the CAP_SYS_RESOURCE and can usually only be done by
      root user (for non-root users, a call to setrlimit fails (and sets
      errno) and the program simply goes on with its rlimit unchanged).
      
      There is no API to get the current amount of memory locked for a user,
      therefore we cannot raise the limit only when required. One solution,
      used by bcc, is to try to create the map, and on getting a EPERM error,
      raising the limit to infinity before giving another try. Another
      approach, used in iproute2, is to raise the limit in all cases, before
      trying to create the map.
      
      Here we do the same as in iproute2: the rlimit is raised to infinity
      before trying to load programs or to create maps with bpftool.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      8302b9bd
  7. 16 10月, 2018 1 次提交
  8. 10 10月, 2018 2 次提交
  9. 01 10月, 2018 1 次提交
  10. 25 9月, 2018 1 次提交
  11. 12 9月, 2018 1 次提交
    • Y
      tools/bpf: bpftool: support prog array map and map of maps · ad3338d2
      Yonghong Song 提交于
      Currently, prog array map and map of maps are not supported
      in bpftool. This patch added the support.
      Different from other map types, for prog array map and
      map of maps, the key returned bpf_get_next_key() may not
      point to a valid value. So for these two map types,
      no error will be printed out when such a scenario happens.
      
      The following is the plain and json dump if btf is not available:
        $ ./bpftool map dump id 10
          key: 08 00 00 00  value: 5c 01 00 00
          Found 1 element
        $ ./bpftool -jp map dump id 10
          [{
              "key": ["0x08","0x00","0x00","0x00"
              ],
              "value": ["0x5c","0x01","0x00","0x00"
              ]
          }]
      
      If the BTF is available, the dump looks below:
        $ ./bpftool map dump id 2
          [{
                  "key": 0,
                  "value": 7
              }
          ]
        $ ./bpftool -jp map dump id 2
          [{
              "key": ["0x00","0x00","0x00","0x00"
              ],
              "value": ["0x07","0x00","0x00","0x00"
              ],
              "formatted": {
                  "key": 0,
                  "value": 7
              }
          }]
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      ad3338d2
  12. 03 9月, 2018 1 次提交
  13. 30 8月, 2018 1 次提交
    • Y
      tools/bpf: bpftool: add btf percpu map formated dump · 1a86ad89
      Yonghong Song 提交于
      The btf pretty print is added to percpu arraymap,
      percpu hashmap and percpu lru hashmap.
      For each <key, value> pair, the following will be
      added to plain/json output:
      
         {
             "key": <pretty_print_key>,
             "values": [{
                   "cpu": 0,
                   "value": <pretty_print_value_on_cpu0>
                },{
                   "cpu": 1,
                   "value": <pretty_print_value_on_cpu1>
                },{
                ....
                },{
                   "cpu": n,
                   "value": <pretty_print_value_on_cpun>
                }
             ]
         }
      
      For example, the following could be part of plain or json formatted
      output:
          {
              "key": 0,
              "values": [{
                      "cpu": 0,
                      "value": {
                          "ui32": 0,
                          "ui16": 0,
                      }
                  },{
                      "cpu": 1,
                      "value": {
                          "ui32": 1,
                          "ui16": 0,
                      }
                  },{
                      "cpu": 2,
                      "value": {
                          "ui32": 2,
                          "ui16": 0,
                      }
                  },{
                      "cpu": 3,
                      "value": {
                          "ui32": 3,
                          "ui16": 0,
                      }
                  }
              ]
          }
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      1a86ad89
  14. 03 8月, 2018 1 次提交
  15. 31 7月, 2018 1 次提交
    • Y
      tools/bpftool: fix a percpu_array map dump problem · 573b3aa6
      Yonghong Song 提交于
      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: 71bb428f ("tools: bpf: add bpftool")
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      573b3aa6
  16. 25 7月, 2018 1 次提交
  17. 14 7月, 2018 1 次提交
    • O
      bpf: btf: print map dump and lookup with btf info · 2d3feca8
      Okash Khawaja 提交于
      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: NOkash Khawaja <osk@fb.com>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      2d3feca8
  18. 12 7月, 2018 1 次提交
  19. 01 7月, 2018 1 次提交
  20. 17 5月, 2018 1 次提交
  21. 05 5月, 2018 3 次提交
  22. 18 4月, 2018 1 次提交
    • Q
      tools: bpftool: make it easier to feed hex bytes to bpftool · 0c90f224
      Quentin Monnet 提交于
      bpftool uses hexadecimal values when it dumps map contents:
      
          # bpftool map dump id 1337
          key: ff 13 37 ff  value: a1 b2 c3 d4 ff ff ff ff
          Found 1 element
      
      In order to lookup or update values with bpftool, the natural reflex is
      then to copy and paste the values to the command line, and to try to run
      something like:
      
          # bpftool map update id 1337 key ff 13 37 ff \
                  value 00 00 00 00 00 00 1a 2b
          Error: error parsing byte: ff
      
      bpftool complains, because it uses strtoul() with a 0 base to parse the
      bytes, and that without a "0x" prefix, the bytes are considered as
      decimal values (or even octal if they start with "0").
      
      To feed hexadecimal values instead, one needs to add "0x" prefixes
      everywhere necessary:
      
          # bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
                  value 0 0 0 0 0 0 0x1a 0x2b
      
      To make it easier to use hexadecimal values, add an optional "hex"
      keyword to put after "key" or "value" to tell bpftool to consider the
      digits as hexadecimal. We can now do:
      
          # bpftool map update id 1337 key hex ff 13 37 ff \
                  value hex 0 0 0 0 0 0 1a 2b
      
      Without the "hex" keyword, the bytes are still parsed according to
      normal integer notation (decimal if no prefix, or hexadecimal or octal
      if "0x" or "0" prefix is used, respectively).
      
      The patch also add related documentation and bash completion for the
      "hex" keyword.
      Suggested-by: NDaniel Borkmann <daniel@iogearbox.net>
      Suggested-by: NDavid Beckett <david.beckett@netronome.com>
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      0c90f224
  23. 25 3月, 2018 1 次提交
  24. 20 1月, 2018 1 次提交
  25. 19 1月, 2018 1 次提交
  26. 04 1月, 2018 1 次提交
  27. 23 12月, 2017 2 次提交
  28. 11 11月, 2017 2 次提交
    • P
      tools: bpftool: optionally show filenames of pinned objects · c541b734
      Prashant Bhole 提交于
      Making it optional to show file names of pinned objects because
      it scans complete bpf-fs filesystem which is costly.
      Added option -f|--bpffs. Documentation updated.
      Signed-off-by: NPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c541b734
    • P
      tools: bpftool: show filenames of pinned objects · 4990f1f4
      Prashant Bhole 提交于
      Added support to show filenames of pinned objects.
      
      For example:
      
      root@test# ./bpftool prog
      3: tracepoint  name tracepoint__irq  tag f677a7dd722299a3
          loaded_at Oct 26/11:39  uid 0
          xlated 160B  not jited  memlock 4096B  map_ids 4
          pinned /sys/fs/bpf/softirq_prog
      
      4: tracepoint  name tracepoint__irq  tag ea5dc530d00b92b6
          loaded_at Oct 26/11:39  uid 0
          xlated 392B  not jited  memlock 4096B  map_ids 4,6
      
      root@test# ./bpftool --json --pretty prog
      [{
              "id": 3,
              "type": "tracepoint",
              "name": "tracepoint__irq",
              "tag": "f677a7dd722299a3",
              "loaded_at": "Oct 26/11:39",
              "uid": 0,
              "bytes_xlated": 160,
              "jited": false,
              "bytes_memlock": 4096,
              "map_ids": [4
              ],
              "pinned": ["/sys/fs/bpf/softirq_prog"
              ]
          },{
              "id": 4,
              "type": "tracepoint",
              "name": "tracepoint__irq",
              "tag": "ea5dc530d00b92b6",
              "loaded_at": "Oct 26/11:39",
              "uid": 0,
              "bytes_xlated": 392,
              "jited": false,
              "bytes_memlock": 4096,
              "map_ids": [4,6
              ],
              "pinned": []
          }
      ]
      
      root@test# ./bpftool map
      4: hash  name start  flags 0x0
          key 4B  value 16B  max_entries 10240  memlock 1003520B
          pinned /sys/fs/bpf/softirq_map1
      5: hash  name iptr  flags 0x0
          key 4B  value 8B  max_entries 10240  memlock 921600B
      
      root@test# ./bpftool --json --pretty map
      [{
              "id": 4,
              "type": "hash",
              "name": "start",
              "flags": 0,
              "bytes_key": 4,
              "bytes_value": 16,
              "max_entries": 10240,
              "bytes_memlock": 1003520,
              "pinned": ["/sys/fs/bpf/softirq_map1"
              ]
          },{
              "id": 5,
              "type": "hash",
              "name": "iptr",
              "flags": 0,
              "bytes_key": 4,
              "bytes_value": 8,
              "max_entries": 10240,
              "bytes_memlock": 921600,
              "pinned": []
          }
      ]
      Signed-off-by: NPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4990f1f4
  29. 24 10月, 2017 4 次提交
  30. 22 10月, 2017 2 次提交
  31. 05 10月, 2017 1 次提交