1. 23 Jan, 2019 1 commit
    • Quentin Monnet's avatar
      tools: bpftool: add basic probe capability, probe syscall availability · 49eb7ab3
      Quentin Monnet authored
      Add a new component and command for bpftool, in order to probe the
      system to dump a set of eBPF-related parameters so that users can know
      what features are available on the system.
      
      Parameters are dumped in plain or JSON output (with -j/-p options).
      
      The current patch introduces probing of one simple parameter:
      availability of the bpf() system call. Later commits
      will add other probes.
      
      Sample output:
      
          # bpftool feature probe kernel
          Scanning system call availability...
          bpf() syscall is available
      
          # bpftool --json --pretty feature probe kernel
          {
              "syscall_config": {
                  "have_bpf_syscall": true
              }
          }
      
      The optional "kernel" keyword enforces probing of the current system,
      which is the only possible behaviour at this stage. It can be safely
      omitted.
      
      The feature comes with the relevant man page, but bash completion will
      come in a dedicated commit.
      
      v3:
      - Do not probe kernel version. Contrarily to what is written below for
        v2, we can have the kernel version retrieved in libbpf instead of
        bpftool (in the patch adding probing for program types).
      
      v2:
      - Remove C-style macros output from this patch.
      - Even though kernel version is no longer needed for testing kprobes
        availability, note that we still collect it in this patch so that
        bpftool gets able to probe (in next patches) older kernels as well.
      Signed-off-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      49eb7ab3
  2. 17 Jan, 2019 9 commits
    • Peter Oskolkov's avatar
      bpf: fix a (false) compiler warning · d0b2818e
      Peter Oskolkov authored
      An older GCC compiler complains:
      
      kernel/bpf/verifier.c: In function 'bpf_check':
      kernel/bpf/verifier.c:4***:13: error: 'prev_offset' may be used uninitialized
            in this function [-Werror=maybe-uninitialized]
         } else if (krecord[i].insn_offset <= prev_offset) {
                   ^
      kernel/bpf/verifier.c:4***:38: note: 'prev_offset' was declared here
        u32 i, nfuncs, urec_size, min_size, prev_offset;
      
      Although the compiler is wrong here, the patch makes sure
      that prev_offset is always initialized, just to silence the warning.
      
      v2: fix a spelling error in the commit message.
      Signed-off-by: default avatarPeter Oskolkov <posk@google.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      d0b2818e
    • Daniel Borkmann's avatar
      Merge branch 'bpf-bpftool-queue-stack' · 4edc01b8
      Daniel Borkmann authored
      Stanislav Fomichev says:
      
      ====================
      This patch series add support for queue/stack manipulations.
      
      It goes like this:
      
         commands by permitting empty keys.
      
      v2:
      * removed unneeded jsonw_null from patch #6
      * improved bash completions (and moved them into separate patch #7)
      ====================
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      4edc01b8
    • Stanislav Fomichev's avatar
      bpftool: add bash completion for peek/push/enqueue/pop/dequeue · 55c70bff
      Stanislav Fomichev authored
      bpftool map peek id <TAB>      - suggests only queue and stack map ids
      bpftool map pop id <TAB>       - suggests only stack map ids
      bpftool map dequeue id <TAB>   - suggests only queue map ids
      
      bpftool map push id <TAB>      - suggests only stack map ids
      bpftool map enqueue id <TAB>   - suggests only queue map ids
      
      bpftool map push id 1 <TAB>    - suggests 'value', not 'key'
      bpftool map enqueue id 2 <TAB> - suggests 'value', not 'key'
      
      bpftool map update id <stack/queue type> - suggests 'value', not 'key'
      bpftool map lookup id <stack/queue type> - suggests nothing
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      55c70bff
    • Stanislav Fomichev's avatar
      bpftool: add pop and dequeue commands · 74f312ef
      Stanislav Fomichev authored
      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: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      74f312ef
    • Stanislav Fomichev's avatar
      bpftool: add push and enqueue commands · 549d4d3d
      Stanislav Fomichev authored
      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: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      549d4d3d
    • Stanislav Fomichev's avatar
      bpftool: add peek command · 66cf6e0b
      Stanislav Fomichev authored
      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: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      66cf6e0b
    • Stanislav Fomichev's avatar
      bpftool: don't print empty key/value for maps · 04a5d323
      Stanislav Fomichev authored
      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: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      04a5d323
    • Stanislav Fomichev's avatar
      bpftool: make key optional in lookup command · 8a89fff6
      Stanislav Fomichev authored
      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: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      8a89fff6
    • Stanislav Fomichev's avatar
      bpftool: make key and value optional in update command · 7d7209cb
      Stanislav Fomichev authored
      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: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      7d7209cb
  3. 16 Jan, 2019 13 commits
    • Daniel Borkmann's avatar
      Merge branch 'bpf-int128-btf' · e13279e2
      Daniel Borkmann authored
      Yonghong Song says:
      
      ====================
      Previous maximum supported integer bit width is 64. But
      the __int128 type has been supported by most (if not all)
      64bit architectures including bpf for both gcc and clang.
      
      The kernel itself uses __int128 for x64 and arm64. Some bcc
      tools are using __int128 in bpf programs to describe ipv6
      addresses. Without 128bit int support, the vmlinux BTF won't
      work and those bpf programs using __int128 cannot utilize BTF.
      
      This patch set therefore implements BTF __int128 support.
      ====================
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      e13279e2
    • Yonghong Song's avatar
      tools/bpf: support __int128 in bpftool map pretty dumper · e86e5138
      Yonghong Song authored
      For formatted output, currently when json is enabled, the decimal
      number is required. Similar to kernel bpffs printout,
      for int128 numbers, only hex numbers are dumped, which are
      quoted as strings.
      
      The below is an example to show plain and json pretty print
      based on the map in test_btf pretty print test.
      
        $ bpftool m s
        75: hash  name pprint_test_has  flags 0x0
              key 4B  value 112B  max_entries 4  memlock 4096B
        $ bpftool m d id 75
        ......
          {
              "key": 3,
              "value": {
                  "ui32": 3,
                  "ui16": 0,
                  "si32": -3,
                  "unused_bits2a": 0x3,
                  "bits28": 0x3,
                  "unused_bits2b": 0x3,
                  "": {
                      "ui64": 3,
                      "ui8a": [3,0,0,0,0,0,0,0
                      ]
                  },
                  "aenum": 3,
                  "ui32b": 4,
                  "bits2c": 0x1,
                  "si128a": 0x3,
                  "si128b": 0xfffffffd,
                  "bits3": 0x3,
                  "bits80": 0x10000000000000003,
                  "ui128": 0x20000000000000003
              }
          },
        ......
      
        $ bptfool -p -j m d id 75
        ......
        {
              "key": ["0x03","0x00","0x00","0x00"
              ],
              "value": ["0x03","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0xfd","0xff","0xff","0xff","0x0f","0x00","0x00","0xc0",
                        "0x03","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x03","0x00","0x00","0x00","0x04","0x00","0x00","0x00",
                        "0x01","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x03","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0xfd","0xff","0xff","0xff","0x00","0x00","0x00","0x00",
                        "0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x1b","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x08","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x03","0x00","0x00","0x00","0x00","0x00","0x00","0x00",
                        "0x02","0x00","0x00","0x00","0x00","0x00","0x00","0x00"
              ],
              "formatted": {
                  "key": 3,
                  "value": {
                      "ui32": 3,
                      "ui16": 0,
                      "si32": -3,
                      "unused_bits2a": "0x3",
                      "bits28": "0x3",
                      "unused_bits2b": "0x3",
                      "": {
                          "ui64": 3,
                          "ui8a": [3,0,0,0,0,0,0,0
                          ]
                      },
                      "aenum": 3,
                      "ui32b": 4,
                      "bits2c": "0x1",
                      "si128a": "0x3",
                      "si128b": "0xfffffffd",
                      "bits3": "0x3",
                      "bits80": "0x10000000000000003",
                      "ui128": "0x20000000000000003"
                  }
              }
          }
        ......
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      e86e5138
    • Yonghong Song's avatar
      tools/bpf: add bpffs pretty print test for int128 · 4df3a1d0
      Yonghong Song authored
      The bpffs pretty print test is extended to cover int128 types.
      Tested on an x64 machine.
        $ test_btf -p
        ......
        BTF pretty print array(#3)......OK
        PASS:9 SKIP:0 FAIL:0
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      4df3a1d0
    • Yonghong Song's avatar
      tools/bpf: refactor test_btf pretty printing for multiple map value formats · ce6ec47a
      Yonghong Song authored
      The test_btf pretty print is refactored in order to easily
      support multiple map value formats. The next patch will
      add __int128 type tests which needs macro guard __SIZEOF_INT128__.
      There is no functionality change with this patch.
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      ce6ec47a
    • Yonghong Song's avatar
      tools/bpf: add int128 raw test in test_btf · a80eba20
      Yonghong Song authored
      Several int128 raw type tests are added to test_btf.
      Currently these tests are enabled only for x64 and arm64
      for which kernel has CONFIG_ARCH_SUPPORTS_INT128 set.
      
        $ test_btf
        ......
        BTF raw test[106] (128-bit int): OK
        BTF raw test[107] (struct, 128-bit int member): OK
        BTF raw test[108] (struct, 120-bit int member bitfield): OK
        BTF raw test[109] (struct, kind_flag, 128-bit int member): OK
        BTF raw test[110] (struct, kind_flag, 120-bit int member bitfield): OK
        ......
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      a80eba20
    • Yonghong Song's avatar
      bpf: btf: support 128 bit integer type · b1e8818c
      Yonghong Song authored
      Currently, btf only supports up to 64-bit integer.
      On the other hand, 128bit support for gcc and clang
      has existed for a long time. For example, both gcc 4.8
      and llvm 3.7 supports types "__int128" and
      "unsigned __int128" for virtually all 64bit architectures
      including bpf.
      
      The requirement for __int128 support comes from two areas:
        . bpf program may use __int128. For example, some bcc tools
          (https://github.com/iovisor/bcc/tree/master/tools),
          mostly tcp v6 related, tcpstates.py, tcpaccept.py, etc.,
          are using __int128 to represent the ipv6 addresses.
        . linux itself is using __int128 types. Hence supporting
          __int128 type in BTF is required for vmlinux BTF,
          which will be used by "compile once and run everywhere"
          and other projects.
      
      For 128bit integer, instead of base-10, hex numbers are pretty
      printed out as large decimal number is hard to decipher, e.g.,
      for ipv6 addresses.
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      b1e8818c
    • Stanislav Fomichev's avatar
      libbpf: don't define CC and AR · eeedd352
      Stanislav Fomichev authored
      We are already including tools/scripts/Makefile.include which correctly
      handles CROSS_COMPILE, no need to define our own vars.
      
      See related commit 7ed1c190 ("tools: fix cross-compile var clobbering")
      for more details.
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      eeedd352
    • Randy Dunlap's avatar
      networking: Documentation: fix snmp_counters.rst Sphinx warnings · ae5220c6
      Randy Dunlap authored
      Fix over 100 documentation warnings in snmp_counter.rst by
      extending the underline string lengths and inserting a blank line
      after bullet items.
      
      Examples:
      
      Documentation/networking/snmp_counter.rst:1: WARNING: Title overline too short.
      Documentation/networking/snmp_counter.rst:14: WARNING: Bullet list ends without a blank line; unexpected unindent.
      
      Fixes: 2b965472 ("add document for TCP OFO, PAWS and skip ACK counters")
      Fixes: 8e2ea53a ("add snmp counters document")
      Fixes: 712ee16c ("add documents for snmp counters")
      Fixes: 80cc4950 ("net: Add part of TCP counts explanations in snmp_counters.rst")
      Fixes: b08794a9 ("documentation of some IP/ICMP snmp counters")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: yupeng <yupeng0921@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ae5220c6
    • Gustavo A. R. Silva's avatar
      net, decnet: use struct_size() in kzalloc() · bb3e16ad
      Gustavo A. R. Silva authored
      One of the more common cases of allocation size calculations is finding the
      size of a structure that has a zero-sized array at the end, along with memory
      for some number of elements for that array. For example:
      
      struct foo {
          int stuff;
          struct boo entry[];
      };
      
      instance = kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);
      
      Instead of leaving these open-coded and prone to type mistakes, we can now
      use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
      
      This code was detected with the help of Coccinelle.
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      bb3e16ad
    • Gustavo A. R. Silva's avatar
      mlxsw: spectrum_nve: Use struct_size() in kzalloc() · faa311e9
      Gustavo A. R. Silva authored
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct foo {
          int stuff;
          struct boo entry[];
      };
      
      instance = kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
      
      This issue was detected with the help of Coccinelle.
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      faa311e9
    • Gustavo A. R. Silva's avatar
      mlxsw: spectrum_acl_bloom_filter: use struct_size() in kzalloc() · 2285ec87
      Gustavo A. R. Silva authored
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct foo {
          int stuff;
          void *entry[];
      };
      
      instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
      
      This issue was detected with the help of Coccinelle.
      Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2285ec87
    • Sergio Paracuellos's avatar
      dt-bindings: net: dsa: ksz9477: fix indentation for switch spi bindings · 590ce401
      Sergio Paracuellos authored
      Switch bindings for spi managed mode are using spaces instead of tabs.
      Fix them to get a file with a proper kernel indentation style.
      Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarSergio Paracuellos <sergio.paracuellos@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      590ce401
    • Lepton Wu's avatar
      Fix ERROR:do not initialise statics to 0 in af_vsock.c · a22d3251
      Lepton Wu authored
      Found by scripts/checkpatch.pl
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      a22d3251
  4. 15 Jan, 2019 17 commits