1. 17 4月, 2019 1 次提交
  2. 16 4月, 2019 2 次提交
  3. 10 4月, 2019 1 次提交
    • D
      bpf: bpftool support for dumping data/bss/rodata sections · 817998af
      Daniel Borkmann 提交于
      Add the ability to bpftool to handle BTF Var and DataSec kinds
      in order to dump them out of btf_dumper_type(). The value has a
      single object with the section name, which itself holds an array
      of variables it dumps. A single variable is an object by itself
      printed along with its name. From there further type information
      is dumped along with corresponding value information.
      
      Example output from .rodata:
      
        # ./bpftool m d i 150
        [{
                "value": {
                    ".rodata": [{
                            "load_static_data.bar": 18446744073709551615
                        },{
                            "num2": 24
                        },{
                            "num5": 43947
                        },{
                            "num6": 171
                        },{
                            "str0": [97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,0,0,0,0,0,0
                            ]
                        },{
                            "struct0": {
                                "a": 42,
                                "b": 4278120431,
                                "c": 1229782938247303441
                            }
                        },{
                            "struct2": {
                                "a": 0,
                                "b": 0,
                                "c": 0
                            }
                        }
                    ]
                }
            }
        ]
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      817998af
  4. 29 1月, 2019 2 次提交
  5. 23 1月, 2019 2 次提交
    • P
      bpftool: fix percpu maps updating · b0ca5ecb
      Paolo Abeni 提交于
      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: 71bb428f ("tools: bpf: add bpftool")
      Signed-off-by: NPaolo Abeni <pabeni@redhat.com>
      Reviewed-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      b0ca5ecb
    • Q
      tools: bpftool: add probes for eBPF map types · f99e1663
      Quentin Monnet 提交于
      Add new probes for eBPF map types, to detect what are the ones available
      on the system. Try creating one map of each type, and see if the kernel
      complains.
      
      Sample output:
      
          # bpftool feature probe kernel
          ...
          Scanning eBPF map types...
          eBPF map_type hash is available
          eBPF map_type array is available
          eBPF map_type prog_array is available
          ...
      
          # bpftool --json --pretty feature probe kernel
          {
              ...
              "map_types": {
                  "have_hash_map_type": true,
                  "have_array_map_type": true,
                  "have_prog_array_map_type": true,
                  ...
              }
          }
      
      v5:
      - In libbpf.map, move global symbol to the new LIBBPF_0.0.2 section.
      
      v3:
      - Use a switch with all enum values for setting specific map parameters,
        so that gcc complains at compile time (-Wswitch-enum) if new map types
        were added to the kernel but libbpf was not updated.
      
      v2:
      - Move probes from bpftool to libbpf.
      - Remove C-style macros output from this patch.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      f99e1663
  6. 17 1月, 2019 6 次提交
    • S
      bpftool: add pop and dequeue commands · 74f312ef
      Stanislav Fomichev 提交于
      This is intended to be used with queues and stacks, it pops and prints
      the last element via bpf_map_lookup_and_delete_elem.
      
      Example:
      
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map push pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map pop pinned /sys/fs/bpf/q
      value: 00 01 02 03
      bpftool map pop pinned /sys/fs/bpf/q
      Error: empty map
      
      bpftool map create /sys/fs/bpf/s type stack value 4 entries 10 name s
      bpftool map enqueue pinned /sys/fs/bpf/s value 0 1 2 3
      bpftool map dequeue pinned /sys/fs/bpf/s
      value: 00 01 02 03
      bpftool map dequeue pinned /sys/fs/bpf/s
      Error: empty map
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      74f312ef
    • S
      bpftool: add push and enqueue commands · 549d4d3d
      Stanislav Fomichev 提交于
      This is intended to be used with queues and stacks and be more
      user-friendly than 'update' without the key.
      
      Example:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map push pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map peek pinned /sys/fs/bpf/q
      value: 00 01 02 03
      
      bpftool map create /sys/fs/bpf/s type stack value 4 entries 10 name s
      bpftool map enqueue pinned /sys/fs/bpf/s value 0 1 2 3
      bpftool map peek pinned /sys/fs/bpf/s
      value: 00 01 02 03
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      549d4d3d
    • S
      bpftool: add peek command · 66cf6e0b
      Stanislav Fomichev 提交于
      This is intended to be used with queues and stacks and be more
      user-friendly than 'lookup' without key/value.
      
      Example:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map peek pinned /sys/fs/bpf/q
      value: 00 01 02 03
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      66cf6e0b
    • S
      bpftool: don't print empty key/value for maps · 04a5d323
      Stanislav Fomichev 提交于
      When doing dump or lookup, don't print key if key_size == 0 or value if
      value_size == 0. The initial usecase is queue and stack, where we have
      only values.
      
      This is for regular output only, json still has all the fields.
      
      Before:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map lookup pinned /sys/fs/bpf/q
      key:   value: 00 01 02 03
      
      After:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map lookup pinned /sys/fs/bpf/q
      value: 00 01 02 03
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      04a5d323
    • S
      bpftool: make key optional in lookup command · 8a89fff6
      Stanislav Fomichev 提交于
      Bpftool expects key for 'lookup' operations. For some map types, key should
      not be specified. Support looking up those map types.
      
      Before:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map lookup pinned /sys/fs/bpf/q
      Error: did not find key
      
      After:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      bpftool map lookup pinned /sys/fs/bpf/q
      key:   value: 00 01 02 03
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      8a89fff6
    • S
      bpftool: make key and value optional in update command · 7d7209cb
      Stanislav Fomichev 提交于
      Bpftool expects both key and value for 'update' operations. For some
      map types, key should not be specified. Support updating those map types.
      
      Before:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      Error: did not find key
      
      After:
      bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
      bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      7d7209cb
  7. 13 12月, 2018 1 次提交
  8. 01 12月, 2018 1 次提交
    • Q
      tools: bpftool: add owner_prog_type and owner_jited to bpftool output · 99a44bef
      Quentin Monnet 提交于
      For prog array maps, the type of the owner program, and the JIT-ed state
      of that program, are available from the file descriptor information
      under /proc. Add them to "bpftool map show" output. Example output:
      
          # bpftool map show
          158225: prog_array  name jmp_table  flags 0x0
              key 4B  value 4B  max_entries 8  memlock 4096B
              owner_prog_type flow_dissector  owner jited
          # bpftool --json --pretty map show
          [{
                  "id": 1337,
                  "type": "prog_array",
                  "name": "jmp_table",
                  "flags": 0,
                  "bytes_key": 4,
                  "bytes_value": 4,
                  "max_entries": 8,
                  "bytes_memlock": 4096,
                  "owner_prog_type": "flow_dissector",
                  "owner_jited": true
              }
          ]
      
      As we move the table used for associating names to program types,
      complete it with the missing types (lwt_seg6local and sk_reuseport).
      Also add missing types to the help message for "bpftool prog"
      (sk_reuseport and flow_dissector).
      Suggested-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      99a44bef
  9. 27 11月, 2018 1 次提交
  10. 26 11月, 2018 1 次提交
  11. 24 11月, 2018 1 次提交
  12. 21 11月, 2018 1 次提交
  13. 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
  14. 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
  15. 16 10月, 2018 1 次提交
  16. 10 10月, 2018 2 次提交
  17. 01 10月, 2018 1 次提交
  18. 25 9月, 2018 1 次提交
  19. 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
  20. 03 9月, 2018 1 次提交
  21. 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
  22. 03 8月, 2018 1 次提交
  23. 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
  24. 25 7月, 2018 1 次提交
  25. 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
  26. 12 7月, 2018 1 次提交
  27. 01 7月, 2018 1 次提交
  28. 17 5月, 2018 1 次提交
  29. 05 5月, 2018 3 次提交