1. 14 Jul, 2018 3 commits
    • Okash Khawaja's avatar
      bpf: btf: add btf print functionality · b12d6ec0
      Okash Khawaja authored
      This consumes functionality exported in the previous patch. It does the
      main job of printing with BTF data. This is used in the following patch
      to provide a more readable output of a map's dump. It relies on
      json_writer to do json printing. Below is sample output where map keys
      are ints and values are of type struct A:
      
      typedef int int_type;
      enum E {
              E0,
              E1,
      };
      
      struct B {
              int x;
              int y;
      };
      
      struct A {
              int m;
              unsigned long long n;
              char o;
              int p[8];
              int q[4][8];
              enum E r;
              void *s;
              struct B t;
              const int u;
              int_type v;
              unsigned int w1: 3;
              unsigned int w2: 3;
      };
      
      $ sudo bpftool map dump id 14
      [{
              "key": 0,
              "value": {
                  "m": 1,
                  "n": 2,
                  "o": "c",
                  "p": [15,16,17,18,15,16,17,18
                  ],
                  "q": [[25,26,27,28,25,26,27,28
                      ],[35,36,37,38,35,36,37,38
                      ],[45,46,47,48,45,46,47,48
                      ],[55,56,57,58,55,56,57,58
                      ]
                  ],
                  "r": 1,
                  "s": 0x7ffd80531cf8,
                  "t": {
                      "x": 5,
                      "y": 10
                  },
                  "u": 100,
                  "v": 20,
                  "w1": 0x7,
                  "w2": 0x3
              }
          }
      ]
      
      This patch uses json's {} and [] to imply struct/union and array. More
      explicit information can be added later. For example, a command line
      option can be introduced to print whether a key or value is struct
      or union, name of a struct etc. This will however come at the expense
      of duplicating info when, for example, printing an array of structs.
      enums are printed as ints without their names.
      Signed-off-by: default avatarOkash Khawaja <osk@fb.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      b12d6ec0
    • Okash Khawaja's avatar
      bpf: btf: export btf types and name by offset from lib · 92b57121
      Okash Khawaja authored
      This patch introduces btf__resolve_type() function and exports two
      existing functions from libbpf. btf__resolve_type follows modifier
      types like const and typedef until it hits a type which actually takes
      up memory, and then returns it. This function follows similar pattern
      to btf__resolve_size but instead of computing size, it just returns
      the type.
      
      These  functions will be used in the followig patch which parses
      information inside array of `struct btf_type *`. btf_name_by_offset is
      used for printing variable names.
      Signed-off-by: default avatarOkash Khawaja <osk@fb.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Acked-by: default avatarSong Liu <songliubraving@fb.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      92b57121
    • Jakub Kicinski's avatar
      tools: include reallocarray feature test in FEATURE_TESTS_BASIC · db42a21a
      Jakub Kicinski authored
      perf propagates its feature check results to libbpf.  This means
      features for which perf probes must be a superset of libbpf's
      required features.  perf depends on FEATURE_TESTS_BASIC for its list
      of features.
      
      commit 531b014e ("tools: bpf: make use of reallocarray") added
      reallocarray use to libbpf, make perf also perform the reallocarray
      feature check.
      
      Fixes: 531b014e ("tools: bpf: make use of reallocarray")
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      db42a21a
  2. 13 Jul, 2018 14 commits
  3. 12 Jul, 2018 19 commits
  4. 11 Jul, 2018 4 commits
    • Daniel Borkmann's avatar
      Merge branch 'bpf-bpftool-improved-prog-load' · 671dffa7
      Daniel Borkmann authored
      Jakub Kicinski says:
      
      ====================
      This series starts with two minor clean ups to test_offload.py
      selftest script.
      
      The next 11 patches extend the abilities of bpftool prog load
      beyond the simple cgroup use cases.  Three new parameters are
      added:
      
       - type - allows specifying program type, independent of how
         code sections are named;
       - map  - allows reusing existing maps, instead of creating a new
         map on every program load;
       - dev  - offload/binding to a device.
      
      A number of changes to libbpf is required to accomplish the task.
      The section - program type logic mapping is exposed.  We should
      probably aim to use the libbpf program section naming everywhere.
      For reuse of maps we need to allow users to set FD for bpf map
      object in libbpf.
      
      Examples
      
      Load program my_xdp.o and pin it as /sys/fs/bpf/my_xdp, for xdp
      program type:
      
      $ bpftool prog load my_xdp.o /sys/fs/bpf/my_xdp \
        type xdp
      
      As above but for offload:
      
      $ bpftool prog load my_xdp.o /sys/fs/bpf/my_xdp \
        type xdp \
        dev netdevsim0
      
      Load program my_maps.o, but for the first map reuse map id 17,
      and for the map called "other_map" reuse pinned map /sys/fs/bpf/map0:
      
      $ bpftool prog load my_maps.o /sys/fs/bpf/prog \
        map idx 0 id 17 \
        map name other_map pinned /sys/fs/bpf/map0
      
      v3:
       - fix return codes in patch 5;
       - rename libbpf_prog_type_by_string() -> libbpf_prog_type_by_name();
       - fold file path into xattr in patch 8;
       - add patch 10;
       - use dup3() in patch 12;
       - depend on fd value in patch 12;
       - close old fd in patch 12.
      v2:
       - add compat for reallocarray().
      ====================
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      671dffa7
    • Jakub Kicinski's avatar
      tools: bpftool: allow reuse of maps with bpftool prog load · 3ff5a4dc
      Jakub Kicinski authored
      Add map parameter to prog load which will allow reuse of existing
      maps instead of creating new ones.
      
      We need feature detection and compat code for reallocarray, since
      it's not available in many libc versions.
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      3ff5a4dc
    • Jakub Kicinski's avatar
      tools: libbpf: allow map reuse · 26736eb9
      Jakub Kicinski authored
      More advanced applications may want to only replace programs without
      destroying associated maps.  Allow libbpf users to achieve that.
      Instead of always creating all of the maps at load time, expose to
      users an API to reconstruct the map object from already existing
      map.
      
      The map parameters are read from the kernel and replace the parameters
      of the ELF map.  libbpf does not restrict the map replacement, i.e.
      the reused map does not have to be compatible with the ELF map
      definition.  We relay on the verifier for checking the compatibility
      between maps and programs.  The ELF map definition is completely
      overwritten by the information read from the kernel, to make sure
      libbpf's view of map object corresponds to the actual map.
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      26736eb9
    • Jakub Kicinski's avatar
      tools: bpf: make use of reallocarray · 531b014e
      Jakub Kicinski authored
      reallocarray() is a safer variant of realloc which checks for
      multiplication overflow in case of array allocation.  Since it's
      not available in Glibc < 2.26 import kernel's overflow.h and
      add a static inline implementation when needed.  Use feature
      detection to probe for existence of reallocarray.
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: default avatarJiong Wang <jiong.wang@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      531b014e