Commit Graph

459 Commits

Author SHA1 Message Date
Andrey Ignatov
8c091e4ffd Enable version script for DSO building
Version script was synced from kernel tree but not enabled in Makefile.
Enable it same way it's done in kernel tree.

  % readelf -s --wide src/libbpf.so | grep -Eo '[^ ]+@LIBBPF_.*' | \
      cut -d@ -f 3 | sort | uniq -c
    121 LIBBPF_0.0.1
     29 LIBBPF_0.0.2

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-04-02 16:36:46 -07:00
Andrey Ignatov
2dd2a2d701 Fix libbpf.pc target
OBJDIR was not specified for libbpf.pc. It works by default since
default value of OBJDIR is current directory, but breaks as soon as
OBJDIR is set to some other directory:

  % OBJDIR=build DESTDIR=root make install
  ...
  ar rcs build/libbpf.a build/bpf.o build/btf.o build/libbpf.o
  build/libbpf_errno.o build/netlink.o build/nlattr.o build/str_error.o
  build/libbpf_probes.o build/bpf_prog_linfo.o build/xsk.o
  cc -shared  -lelf   build/bpf.o build/btf.o build/libbpf.o build/libbpf_errno.o
  build/netlink.o build/nlattr.o build/str_error.o build/libbpf_probes.o
  build/bpf_prog_linfo.o build/xsk.o -o build/libbpf.so
  make: *** No rule to make target `libbpf.pc', needed by `all'.  Stop.

Fix it.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-03-29 14:52:01 -07:00
4ast
46936194ed
Merge pull request #23 from bluca/pkgconfig-elf
build shared library by default and use pkg-config to get libelf flags
2019-03-29 11:05:02 -07:00
Luca Boccassi
438584bfc2 Makefile: use pkg-config to get libelf flags
libbpf uses libelf symbols internally, so it depends on it and needs to
link against it.

Upstream this was fixed by linking directory to libelf:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=89dedaef49d36adc2bb5e7e4c38b52fa3013c7c8

For this project, intended to be used as a general library, try first
to use pkg-config instead, and only fallback to just passing -lelf.
This will be useful for cross compiling, among other cases.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 17:37:54 +00:00
Luca Boccassi
3e403451c7 Build shared lib by default, add options to turn it off
The vast majority of use cases want a shared library, so to be more
user and packager friendly invert the makefile logic and always build
both static and shared libraries by default.
Add BUILD_STATIC_ONLY variable for the corner cases where only a static
library is needed

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 16:44:25 +00:00
Luca Boccassi
e31e1a5a3f Makefile: pass CPPFLAGS to the compiler
Distro tools like dpkg-buildpackage use the preprocessor flags to pass
important flags, like hardening features. Pass CPPFLAGS to CC.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 09:11:11 -07:00
Luca Boccassi
93bc1d03f4 makefile: sync generate pkg-config file for libbpf
Generate a libbpf.pc file at build time so that users can rely
on pkg-config to find the library, its CFLAGS and LDFLAGS.

This has been applied on bpf-next, so the corresponding change is
backported here:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=dd399ac9e343c7573c47d6820e4a23013c54749d

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2019-03-29 09:11:11 -07:00
Andrii Nakryiko
27a5f60a8b sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline commit:   f01a7dbe98ae4265023fa5d3af0f076f0b18a647
Checkpoint commit: dd399ac9e343c7573c47d6820e4a23013c54749d

Arnaldo Carvalho de Melo (1):
  tools lib bpf: Fix the build by adding a missing stdarg.h include

Changbin Du (1):
  perf tools: Fix errors under optimization level '-Og'

Daniel Borkmann (1):
  bpf, libbpf: clarify bump in libbpf version info

Lorenz Bauer (1):
  tools: update include/uapi/linux/bpf.h

Luca Boccassi (1):
  tools/bpf: generate pkg-config file for libbpf

Song Liu (1):
  tools lib bpf: Introduce bpf_program__get_prog_info_linear()

Willem de Bruijn (1):
  bpf: Sync bpf.h to tools

 include/uapi/linux/bpf.h |  65 +++++++++-
 src/README.rst           |   1 +
 src/libbpf.c             | 253 ++++++++++++++++++++++++++++++++++++++-
 src/libbpf.h             |  64 ++++++++++
 src/libbpf.map           |   3 +
 src/libbpf.pc.template   |  12 ++
 6 files changed, 393 insertions(+), 5 deletions(-)
 create mode 100644 src/libbpf.pc.template

--
2.17.1
2019-03-28 19:51:55 -07:00
Luca Boccassi
9d60bfdfa6 tools/bpf: generate pkg-config file for libbpf
Generate a libbpf.pc file at build time so that users can rely
on pkg-config to find the library, its CFLAGS and LDFLAGS.

Signed-off-by: Luca Boccassi <bluca@debian.org>
Acked-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-28 19:51:55 -07:00
Song Liu
413703c8cb tools lib bpf: Introduce bpf_program__get_prog_info_linear()
Currently, bpf_prog_info includes 9 arrays. The user has the option to
fetch any combination of these arrays. However, this requires a lot of
handling.

This work becomes more tricky when we need to store bpf_prog_info to a
file, because these arrays are allocated independently.

This patch introduces 'struct bpf_prog_info_linear', which stores arrays
of bpf_prog_info in continuous memory.

Helper functions are introduced to unify the work to get different sets
of bpf_prog_info.  Specifically, bpf_program__get_prog_info_linear()
allows the user to select which arrays to fetch, and handles details for
the user.

Please see the comments right before 'enum bpf_prog_info_array' for more
details and examples.

Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lkml.kernel.org/r/ce92c091-e80d-a0c1-4aa0-987706c42b20@iogearbox.net
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: kernel-team@fb.com
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stanislav Fomichev <sdf@google.com>
Link: http://lkml.kernel.org/r/20190312053051.2690567-3-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-03-28 19:51:55 -07:00
Changbin Du
556285a37a perf tools: Fix errors under optimization level '-Og'
Optimization level '-Og' offers a reasonable level of optimization while
maintaining fast compilation and a good debugging experience. This patch
tries to make it work.

  $ make DEBUG=1 EXTRA_CFLAGS='-Og'
  bench/epoll-ctl.c: In function ‘do_threads’:
  bench/epoll-ctl.c:274:9: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    return ret;
           ^~~
  ...

Signed-off-by: Changbin Du <changbin.du@gmail.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20190316080556.3075-4-changbin.du@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-03-28 19:51:55 -07:00
Arnaldo Carvalho de Melo
7183d5132f tools lib bpf: Fix the build by adding a missing stdarg.h include
The libbpf_print_fn_t typedef uses va_list without including the header
where that type is defined, stdarg.h, breaking in places where we're
unlucky for that type not to be already defined by some previously
included header.

Noticed while building on fedora 24 cross building tools/perf to the ARC
architecture using the uClibc C library:

  28 fedora:24-x-ARC-uClibc   : FAIL arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710

    CC       /tmp/build/perf/tests/llvm.o
  In file included from tests/llvm.c:3:0:
  /git/linux/tools/lib/bpf/libbpf.h:57:20: error: unknown type name 'va_list'
        const char *, va_list ap);
                      ^~~~~~~
  /git/linux/tools/lib/bpf/libbpf.h:59:34: error: unknown type name 'libbpf_print_fn_t'
   LIBBPF_API void libbpf_set_print(libbpf_print_fn_t fn);
                                    ^~~~~~~~~~~~~~~~~
  mv: cannot stat '/tmp/build/perf/tests/.llvm.o.tmp': No such file or directory

Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Quentin Monnet <quentin.monnet@netronome.com>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: Yonghong Song <yhs@fb.com>
Fixes: a8a1f7d09cfc ("libbpf: fix libbpf_print")
Link: https://lkml.kernel.org/n/tip-5270n2quu2gqz22o7itfdx00@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-03-28 19:51:55 -07:00
Willem de Bruijn
2b9a24d7ce bpf: Sync bpf.h to tools
Sync include/uapi/linux/bpf.h with tools/

Changes
  v1->v2:
  - BPF_F_ADJ_ROOM_MASK moved, no longer in this commit
  v2->v3:
  - BPF_F_ADJ_ROOM_ENCAP_L3_MASK moved, no longer in this commit

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-28 19:51:55 -07:00
Lorenz Bauer
0c639aae80 tools: update include/uapi/linux/bpf.h
Pull definitions for bpf_skc_lookup_tcp and bpf_sk_check_syncookie.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-28 19:51:55 -07:00
Andrii Nakryiko
5877849633 sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline commit:   f01a7dbe98ae4265023fa5d3af0f076f0b18a647
Checkpoint commit: 8543e437807970166c2b66b79935c9f4b0e6d1f9

Andrii Nakryiko (1):
  libbpf: fix btf_dedup equivalence check handling of different kinds

Daniel Borkmann (1):
  bpf, libbpf: clarify bump in libbpf version info

 src/README.rst | 1 +
 src/btf.c      | 3 +++
 2 files changed, 4 insertions(+)

--
2.17.1
2019-03-28 19:51:55 -07:00
Andrii Nakryiko
d5b20f9668 libbpf: fix btf_dedup equivalence check handling of different kinds
btf_dedup_is_equiv() used to compare btf_type->info fields, before doing
kind-specific equivalence check. This comparsion implicitly verified
that candidate and canonical types are of the same kind. With enum fwd
resolution logic this check couldn't be done generically anymore, as for
enums info contains vlen, which differs between enum fwd and
fully-defined enum, so this check was subsumed by kind-specific
equivalence checks.

This change caused btf_dedup_is_equiv() to let through VOID vs other
types check to reach switch, which was never meant to be handing VOID
kind, as VOID kind is always pre-resolved to itself and is only
equivalent to itself, which is checked early in btf_dedup_is_equiv().

This change adds back BTF kind equality check in place of more generic
btf_type->info check, still defering further kind-specific checks to
a per-kind switch.

Fixes: 9768095ba97c ("btf: resolve enum fwds in btf_dedup")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-28 19:51:55 -07:00
Daniel Borkmann
d3a6d054df bpf, libbpf: clarify bump in libbpf version info
The current documentation suggests that we would need to bump the
libbpf version on every change. Lets clarify this a bit more and
reflect what we do today in practice, that is, bumping it once per
development cycle.

Fixes: 76d1b894c515 ("libbpf: Document API and ABI conventions")
Reported-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-28 19:51:55 -07:00
Andrii Nakryiko
7c15babf40 scripts/sync_kernel.sh: skip empty merges, preventing cherry-picking
Merges are common. `git cherry-pick` can't cherry-pick merge commit and
requires specifying which of the parents should be cherry-picked, so
it's a pain. But merges are also commonly empty, so it's safe to skip them.

This change goes through all merges touching libbpf files, checks that
they don't have any conflict resolution diffs. If there are any, abort,
if not, proceed as usual, ignoring merges.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-03-28 19:51:11 -07:00
Andrii Nakryiko
33b0174985 sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline commit:   ea5bade929bf04355aeed58a3c9f5ef2c3afe2ac
Checkpoint commit: f01a7dbe98ae4265023fa5d3af0f076f0b18a647

Andrii Nakryiko (2):
  libbpf: handle BTF parsing and loading properly
  btf: resolve enum fwds in btf_dedup

Magnus Karlsson (1):
  libbpf: fix to reject unknown flags in xsk_socket__create()

Martin KaFai Lau (1):
  bpf: Sync bpf.h to tools/

Nikita V. Shirokov (1):
  bpf, libbpf: fixing leak when kernel does not support btf

Quentin Monnet (1):
  tools: bpf: synchronise BPF UAPI header with tools

 include/uapi/linux/bpf.h | 188 ++++++++++++++++++++++++++-------------
 src/btf.c                |  51 ++++++++---
 src/libbpf.c             |  11 ++-
 src/xsk.c                |  15 +++-
 4 files changed, 186 insertions(+), 79 deletions(-)

--
2.17.1
2019-03-19 12:17:19 -07:00
Quentin Monnet
80a0a2df47 tools: bpf: synchronise BPF UAPI header with tools
Synchronise the bpf.h header under tools, to report the latest fixes and
additions to the documentation for the BPF helpers.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-19 12:17:19 -07:00
Andrii Nakryiko
1fdfd30921 btf: resolve enum fwds in btf_dedup
GCC and clang support enum forward declarations as an extension. Such
forward-declared enums will be represented as normal BTF_KIND_ENUM types with
vlen=0. This patch adds ability to resolve such enums to their corresponding
fully defined enums. This helps to avoid duplicated BTF type graphs which only
differ by some types referencing forward-declared enum vs full enum.

One such example in kernel is enum irqchip_irq_state, defined in
include/linux/interrupt.h and forward-declared in include/linux/irq.h. This
causes entire struct task_struct and all referenced types to be duplicated in
btf_dedup output. This patch eliminates such duplication cases.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-19 12:17:19 -07:00
Martin KaFai Lau
c09210b2a2 bpf: Sync bpf.h to tools/
This patch sync the uapi bpf.h to tools/.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-19 12:17:19 -07:00
Magnus Karlsson
6215836a08 libbpf: fix to reject unknown flags in xsk_socket__create()
In xsk_socket__create(), the libbpf_flags field was not checked for
setting currently unused/unknown flags. This patch fixes that by
returning -EINVAL if the user has set any flag that is not in use at
this point in time.

Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets")
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Reviewed-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-19 12:17:19 -07:00
Andrii Nakryiko
c4af4fcac5 libbpf: handle BTF parsing and loading properly
This patch splits and cleans up error handling logic for loading BTF data.
Previously, if BTF data was parsed successfully, but failed to load into
kernel, we'd report nonsensical error code, instead of error returned from
btf__load(). Now btf__new() and btf__load() are handled separately with proper
cleanup and warning reporting.

Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
Reported-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-19 12:17:19 -07:00
Nikita V. Shirokov
a5831bef6d bpf, libbpf: fixing leak when kernel does not support btf
We could end up in situation when we have object file w/ all btf
info, but kernel does not support btf yet. In this situation
currently libbpf just set obj->btf to NULL w/o freeing it first.
This patch is fixing it by making sure to run btf__free first.

Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-19 12:17:19 -07:00
Andrii Nakryiko
74efbe5b91 scripts: update sync script to do if_xdp.h syncing
With xsk.{o,h} changes we started including Linux UAPI's if_xdp.h
header. We need to sync it along the other UAPI headers.

Also updated README to reflect this.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-03-19 12:16:59 -07:00
Andrii Nakryiko
cb658e9724 AF_XDP: add xsk.{c,h} to Makefile and fix build
This patch makes sure we build AF_XDP-related code as part of libbpf. This
also required copying few uapi/linux headers and adding few used definitions
in include headers.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-03-05 09:22:54 -08:00
Andrii Nakryiko
7a431904c8 sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline commit:   5aab392c55c96f9bb26d9294f965f156a87ee81c
Checkpoint commit: ea5bade929bf04355aeed58a3c9f5ef2c3afe2ac

Alexei Starovoitov (1):
  tools/bpf: sync bpf.h into tools

Andrii Nakryiko (3):
  libbpf: fix formatting for btf_ext__get_raw_data
  btf: allow to customize dedup hash table size
  btf: fix bug with resolving STRUCT/UNION into corresponding FWD

Dan Carpenter (1):
  tools/libbpf: signedness bug in btf_dedup_ref_type()

Jakub Kicinski (1):
  tools: libbpf: add a correctly named define for map iteration

Magnus Karlsson (1):
  libbpf: add support for using AF_XDP sockets

brakmo (1):
  bpf: sync bpf.h to tools and update bpf_helpers.h

 include/uapi/linux/bpf.h |  12 +-
 src/README.rst           |  15 +-
 src/btf.c                |  76 ++--
 src/btf.h                |   3 +-
 src/libbpf.c             |   8 +-
 src/libbpf.h             |   3 +-
 src/libbpf.map           |   6 +
 src/xsk.c                | 723 +++++++++++++++++++++++++++++++++++++++
 src/xsk.h                | 203 +++++++++++
 9 files changed, 1020 insertions(+), 29 deletions(-)
 create mode 100644 src/xsk.c
 create mode 100644 src/xsk.h

--
2.17.1
2019-03-02 21:31:13 -08:00
brakmo
68cafb4cf7 bpf: sync bpf.h to tools and update bpf_helpers.h
This patch syncs the uapi bpf.h to tools/ and also updates
bpf_herlpers.h in tools/

Signed-off-by: Lawrence Brakmo <brakmo@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-02 21:31:13 -08:00
Andrii Nakryiko
cba1a119cf btf: fix bug with resolving STRUCT/UNION into corresponding FWD
When checking available canonical candidates for struct/union algorithm
utilizes btf_dedup_is_equiv to determine if candidate is suitable. This
check is not enough when candidate is corresponding FWD for that
struct/union, because according to equivalence logic they are
equivalent. When it so happens that FWD and STRUCT/UNION end in hashing
to the same bucket, it's possible to create remapping loop from FWD to
STRUCT and STRUCT to same FWD, which will cause btf_dedup() to loop
forever.

This patch fixes the issue by additionally checking that type and
canonical candidate are strictly equal (utilizing btf_equal_struct).

Fixes: d5caef5b5655 ("btf: add BTF types deduplication algorithm")
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Andrii Nakryiko
6c11809cc8 btf: allow to customize dedup hash table size
Default size of dedup table (16k) is good enough for most binaries, even
typical vmlinux images. But there are cases of binaries with huge amount
of BTF types (e.g., allyesconfig variants of kernel), which benefit from
having bigger dedup table size to lower amount of unnecessary hash
collisions. Tools like pahole, thus, can tune this parameter to reach
optimal performance.

This change also serves double purpose of allowing tests to force hash
collisions to test some corner cases, used in follow up patch.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Andrii Nakryiko
d58dcd8c6e libbpf: fix formatting for btf_ext__get_raw_data
Fix invalid formatting of pointer arg.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Dan Carpenter
6f14d7fbe7 tools/libbpf: signedness bug in btf_dedup_ref_type()
The "ref_type_id" variable needs to be signed for the error handling
to work.

Fixes: d5caef5b5655 ("btf: add BTF types deduplication algorithm")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Jakub Kicinski
14fc408f9d tools: libbpf: add a correctly named define for map iteration
For historical reasons the helper to loop over maps in an object
is called bpf_map__for_each while it really should be called
bpf_object__for_each_map.  Rename and add a correctly named
define for backward compatibility.

Switch all in-tree users to the correct name (Quentin).

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Alexei Starovoitov
7e447c35b7 tools/bpf: sync bpf.h into tools
sync bpf.h into tools directory

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Magnus Karlsson
b23ab17fd3 libbpf: add support for using AF_XDP sockets
This commit adds AF_XDP support to libbpf. The main reason for this is
to facilitate writing applications that use AF_XDP by offering
higher-level APIs that hide many of the details of the AF_XDP
uapi. This is in the same vein as libbpf facilitates XDP adoption by
offering easy-to-use higher level interfaces of XDP
functionality. Hopefully this will facilitate adoption of AF_XDP, make
applications using it simpler and smaller, and finally also make it
possible for applications to benefit from optimizations in the AF_XDP
user space access code. Previously, people just copied and pasted the
code from the sample application into their application, which is not
desirable.

The interface is composed of two parts:

* Low-level access interface to the four rings and the packet
* High-level control plane interface for creating and setting
  up umems and af_xdp sockets as well as a simple XDP program.

Tested-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-03-02 21:31:13 -08:00
Andrii Nakryiko
947e40e1fd sync_kernel.sh: revamp sync script to work in the presence of merges (#15)
Previous version of script relied on squashing baseline commit and
rebasing rest of commits on top of it. This doesn't work well with git
histories containing merges. This patch changes approach by cherry-picking
commits that have libbpf-related changes and then rewriting history since
last checkpoint.

This still might fail if there were manually resolved merge conflicts for
libbpf, but it's the best we can get as far as I can tell.

Script now also verifies that state of libbpf in Linux's repository exactly
matches the state of libbpf in github repo.

If everything goes smoothing (including verification step), we clean up after
ourselves and only leave libbpf-sync-XXX branch in github's libbpf repo to
push to remote.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-03-02 21:19:17 -08:00
Andrii Nakryiko
d5fa4150f0 libbpf sync 2019-02-17T06:35:29.358Z (#14)
* tools/libbpf: support bigger BTF data sizes

While it's understandable why kernel limits number of BTF types to 65535
and size of string section to 64KB, in libbpf as user-space library it's
too restrictive. E.g., pahole converting DWARF to BTF type information
for Linux kernel generates more than 3 million BTF types and more than
3MB of strings, before deduplication. So to allow btf__dedup() to do its
work, we need to be able to load bigger BTF sections using btf__new().

Singed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

* sync: latest libbpf changes from kernel

Syncing latest libbpf commits from kernel repository.
Baseline commit:   789f6bab849e04ea029c09b81dc8401dc0268cf9
Checkpoint commit: 5aab392c55c96f9bb26d9294f965f156a87ee81c

Andrii Nakryiko (1):
  tools/libbpf: support bigger BTF data sizes

 src/btf.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

--
2.17.1
2019-02-16 22:41:31 -08:00
Andrii Nakryiko
8e42f42533 scripts: add script to sync kernel changes (#13)
This script automates the process of applying libbpf-relevant changes
from kernel repository on top of current state of libbpf repository.

It uses CHECKPOINT-COMMIT file to keep track of last commit in kernel
repo up to which libbpf is in sync with. If there are any new libbpf
changes in kernel repository, script extracts them, preserving original
commit metadata. It also creates a "sync commit" using cover letter as
a template, which nicely summarizes changes since last sync with kernel.

Usage: ./scripts/sync-kernel.sh <linux-repo> <libbpf-repo>

If it succeeds, script will create a bunch of local commits in
<libbpf-repo> in separate branch, which can be easily pushed into github
to create a pull request.

Script tries to clean up after itself, except in case of failure. But it
doesn't clean up timestamped branches it creates in both kernel and
libbpf repositories for now. We can add that later.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-02-16 22:22:30 -08:00
Andrey Ignatov
8008be5657 Install bpf_common.h in install_uapi_headers (#12)
bpf_common.h is hardly ever changed so it was not installed together
with other uapi headers. Some environments are still prefer to be
consistent and install all relevant uapi headers so add bpf_common.h to
uapi headers.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2019-02-15 14:43:41 -08:00
Yonghong Song
5beb8a2ebf sync with latest bpf-next
Signed-off-by: Yonghong Song <yhs@fb.com>
2019-02-15 08:50:10 -08:00
Andrii Nakryiko
6f9a833985 sync with latest bpf-next (#11)
Sync latest libbpf sources. Tested against pahole.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-02-15 07:38:45 -08:00
yonghong-song
f0bcba631d
sync with latest bpf-next (#10)
sync with latest bpf-next. tested with fb internal testcase and bcc.

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-02-07 21:58:07 -08:00
Yonghong Song
b19c6dcf62 sync with bpf-next
Sync with the following bug fix:
  commit a8a1f7d09cfc7e18874786c7634c9e71384fcd4e (HEAD -> bpf-next2, bpf-next/master)
  Author: Stanislav Fomichev <sdf@google.com>
  Date:   Mon Feb 4 16:20:55 2019 -0800

    libbpf: fix libbpf_print

    With the recent print rework we now have the following problem:
    pr_{warning,info,debug} expand to __pr which calls libbpf_print.
    libbpf_print does va_start and calls __libbpf_pr with va_list argument.
    In __base_pr we again do va_start. Because the next argument is a
    va_list, we don't get correct pointer to the argument (and print noting
    in my case, I don't know why it doesn't crash tbh).

    ......

    Signed-off-by: Stanislav Fomichev <sdf@google.com>

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-02-04 19:42:31 -08:00
Yonghong Song
30388a7afd add BPF_EMIT_CALL macro for libbpf_probes.c
libbpf_probes.c accessed BPF_EMIT_CALL. Added the
definition in include/linux/filter.h.

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-02-04 14:39:30 -08:00
Yonghong Song
1dc0296fce sync with latest bpf-next
The following three files are added:
  libbpf_probes.c
  libbpf_util.h
  libbpf.map

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-02-04 13:29:57 -08:00
yonghong-song
d5b146fec5
add asm/errno.h to linux/err.h (#8)
Otherwise, we will have the following compilation error:

  /home/yhs/work/bcc-new/src/cc/libbpf/src/bpf_prog_linfo.c:
      In function ‘dissect_jited_func’:
  /home/yhs/work/bcc-new/src/cc/libbpf/src/bpf_prog_linfo.c:88:10:
      error: ‘EINVAL’ undeclared (first use in this function)
    return -EINVAL;

The original linux/err.h at linux:tools/include directory
does include "asm/errno.h" as well.

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-01-16 17:16:50 -08:00
David Ahern
29eca541b8 Fix redirect in check-reallocarray (#7)
Builds on debian stretch are failing due to:

../scripts/check-reallocarray.sh: 17: ../scripts/check-reallocarray.sh: Syntax error: Bad fd number

Fix the redirect of stdout and stderr.

Signed-off-by: David Ahern <dsahern@gmail.com>
2019-01-07 20:34:42 -08:00
yonghong-song
07a48dcda2
sync with latest bpf-next (#6)
The following two new files are added:
  README.rst
  bpf_prog_linfo.c

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-01-03 12:44:33 -08:00
yonghong-song
556e0a0def
bpf: sync with latest bpf-next tree (#5)
sync with latest bpf-next tree.
the include/linux/filter.h is created as libbpf.c tries
to use various insn define macros.

Signed-off-by: Yonghong Song <yhs@fb.com>
2018-11-26 14:32:21 -08:00