Commit Graph

478 Commits

Author SHA1 Message Date
Andrii Nakryiko
e78a36f4b0 sync: fix non-empty merge detection/handling
Fix how non-empty merge detection is done. Allow to proceed despite
non-empty merges (they will typically will cause conflicts during
applying patches, but if conflicts were handled already, it should be ok
to ignore this problem).

Also ensure that diff's output is in unified diff format.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-14 09:53:04 -07:00
Andrii Nakryiko
c8a7eb06bd sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline bpf-next commit:   b707659213d3c70f2c704ec950df6263b4bffe84
Checkpoint bpf-next commit: b753c5a7f99f390fc100de18647ce0dcacdceafc
Baseline bpf commit:        f1fc7249dddc0e52d9e805e2e661caa118649509
Checkpoint bpf commit:      91b4db5313a2c793aabc2143efb8ed0cf0fdd097

Andrii Nakryiko (2):
  libbpf: fix missing __WORDSIZE definition
  libbpf: attempt to load kernel BTF from sysfs first

Arnaldo Carvalho de Melo (1):
  tools headers UAPI: Sync if_link.h with the kernel

Daniel Borkmann (1):
  bpf: sync bpf.h to tools infrastructure

 include/uapi/linux/bpf.h     |  4 +--
 include/uapi/linux/if_link.h |  5 +++
 src/hashmap.h                |  5 +++
 src/libbpf.c                 | 64 ++++++++++++++++++++++++++++++++----
 4 files changed, 69 insertions(+), 9 deletions(-)

--
2.17.1
2019-08-14 09:52:47 -07:00
Daniel Borkmann
b48c14807b bpf: sync bpf.h to tools infrastructure
Pull in updates in BPF helper function description.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-08-14 09:52:47 -07:00
Andrii Nakryiko
a3b4055ec7 libbpf: attempt to load kernel BTF from sysfs first
Add support for loading kernel BTF from sysfs (/sys/kernel/btf/vmlinux)
as a target BTF. Also extend the list of on disk search paths for
vmlinux ELF image with entries that perf is searching for.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-14 09:52:47 -07:00
Andrii Nakryiko
30603852f4 libbpf: fix missing __WORDSIZE definition
hashmap.h depends on __WORDSIZE being defined. It is defined by
glibc/musl in different headers. It's an explicit goal for musl to be
"non-detectable" at compilation time, so instead include glibc header if
glibc is explicitly detected and fall back to musl header otherwise.

Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Fixes: e3b924224028 ("libbpf: add resizable non-thread safe internal hashmap")
Link: https://lkml.kernel.org/r/20190718173021.2418606-1-andriin@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-14 09:52:47 -07:00
Arnaldo Carvalho de Melo
1a28fa5dac tools headers UAPI: Sync if_link.h with the kernel
To pick the changes in:

  07a4ddec3ce9 ("bonding: add an option to specify a delay between peer notifications")

And silence this build warning:

  Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Vincent Bernat <vincent@bernat.ch>
Link: https://lkml.kernel.org/n/tip-3liw4exxh8goc0rq9xryl2kv@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-14 09:52:47 -07:00
Andrii Nakryiko
def5576b37 sync: pull patches from bpf tree as well
Add patches sync from both bpf and bpf-next trees at the same time.
Baseline checkpoint commits are tracked independently for both.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
3e45a16621 sync: make patch applying interactive, allow to ignore consistency
Give more control over patching process to allow manual intervention and
fix up, after which process will continue. Also allow an option to
ignore consistency check results (when having both bpf and bpf-next
changes).

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
2c0e53cb08 sync: attempt to auto-resolve non-libbpf conflicts
If cherry-picked commit contains non-libbpf files, chances are high that
this will result in conflict, because we are generally skipping commits
that didn't touch libbpf files, which means that our working copy will
not be up-to-date for non-libbpf files. This change checks if conflicts
are only in non-libbpf files and marks them as resolved. This will work
fine as long as we don't cherry-pick some more non-libbpf changes to
same set of files that happen to conflict with not-so-resolved version
of non-libbpf files. But anyways, this should help in a lot of cases.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
6227c6f8dd sync: add manual cherry-picking mode
This is sometimes necessary when we did ad-hoc urgent bug fixes, which
are not identical to the ones in kernel.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
00ad180d07 sync: extract cherry-picking logic for reuse
Extract non-empty merge validation and cherry-picking logic so that it
can be re-used for bpf and bpf-next commits.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
715a58d593 sync: improve and automate already synced patches detection
Make detection more precise and automate skip/sync decision, if
everything looks sane.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
11052fc1be sync: add commit_desc() function and move things around a bit
Just cleaning up a bunch of stuff before the next refactoring.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
97ecda3b25 sync: extract directory changing function
Extract the logic of handling relative paths within the script into
go_to() function.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
342bcfa319 sync: centralize kernel-to-github paths mapping
Use associative array (requires at least bash 4) to centralize mapping
of paths between kernel's libbpf layout and the one on Github. This
minimizes the chance of all those mappings getting out of sync (which
happened twice before).

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-08-09 08:41:26 -07:00
Andrii Nakryiko
c020432531 sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline bpf-next commit:   66b5f1c439843bcbab01cc7f3854ae2742f3d1e3
Checkpoint bpf-next commit: b707659213d3c70f2c704ec950df6263b4bffe84
Baseline bpf commit:        53db1cced401e4c65d49edf198e00daa9fc837e6
Checkpoint bpf commit:      f1fc7249dddc0e52d9e805e2e661caa118649509

Andrii Nakryiko (8):
  libbpf: provide more helpful message on uninitialized global var
  libbpf: return previous print callback from libbpf_set_print
  libbpf: add helpers for working with BTF types
  libbpf: convert libbpf code to use new btf helpers
  libbpf: add .BTF.ext offset relocation section loading
  libbpf: implement BPF CO-RE offset relocation algorithm
  libbpf: fix SIGSEGV when BTF loading fails, but .BTF.ext exists
  libbpf: sanitize VAR to conservative 1-byte INT

Petar Penkov (1):
  bpf: sync bpf.h to tools/

Stanislav Fomichev (2):
  tools/bpf: sync bpf_flow_keys flags
  bpf/flow_dissector: support ipv6 flow_label and
    BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL

Toke Høiland-Jørgensen (2):
  tools/include/uapi: Add devmap_hash BPF map type
  tools/libbpf_probes: Add new devmap_hash type

 include/uapi/linux/bpf.h |  44 +-
 src/btf.c                | 250 +++++-----
 src/btf.h                | 182 ++++++++
 src/btf_dump.c           | 138 ++----
 src/libbpf.c             | 972 ++++++++++++++++++++++++++++++++++++---
 src/libbpf.h             |   3 +-
 src/libbpf_internal.h    | 105 +++++
 src/libbpf_probes.c      |   1 +
 8 files changed, 1405 insertions(+), 290 deletions(-)

--
2.17.1
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
99ce275b52 libbpf: implement BPF CO-RE offset relocation algorithm
This patch implements the core logic for BPF CO-RE offsets relocations.
Every instruction that needs to be relocated has corresponding
bpf_offset_reloc as part of BTF.ext. Relocations are performed by trying
to match recorded "local" relocation spec against potentially many
compatible "target" types, creating corresponding spec. Details of the
algorithm are noted in corresponding comments in the code.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
c0a5f7ee11 libbpf: add .BTF.ext offset relocation section loading
Add support for BPF CO-RE offset relocations. Add section/record
iteration macros for .BTF.ext. These macro are useful for iterating over
each .BTF.ext record, either for dumping out contents or later for BPF
CO-RE relocation handling.

To enable other parts of libbpf to work with .BTF.ext contents, moved
a bunch of type definitions into libbpf_internal.h.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
0da9ba439f libbpf: convert libbpf code to use new btf helpers
Simplify code by relying on newly added BTF helper functions.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
c4735d9e05 libbpf: add helpers for working with BTF types
Add lots of frequently used helpers that simplify working with BTF
types.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Petar Penkov
563f1d3fff bpf: sync bpf.h to tools/
Sync updated documentation for bpf_redirect_map.

Sync the bpf_tcp_gen_syncookie helper function definition with the one
in tools/uapi.

Signed-off-by: Petar Penkov <ppenkov@google.com>
Reviewed-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Toke Høiland-Jørgensen
c5d4295fc5 tools/libbpf_probes: Add new devmap_hash type
This adds the definition for BPF_MAP_TYPE_DEVMAP_HASH to libbpf_probes.c in
tools/lib/bpf.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Toke Høiland-Jørgensen
b606dc725e tools/include/uapi: Add devmap_hash BPF map type
This adds the devmap_hash BPF map type to the uapi headers in tools/.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
f615047aa0 libbpf: return previous print callback from libbpf_set_print
By returning previously set print callback from libbpf_set_print, it's
possible to restore it, eventually. This is useful when running many
independent test with one default print function, but overriding log
verbosity for particular subset of tests.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Stanislav Fomichev
84a508a51f bpf/flow_dissector: support ipv6 flow_label and BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL
Add support for exporting ipv6 flow label via bpf_flow_keys.
Export flow label from bpf_flow.c and also return early when
BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL is passed.

Acked-by: Petar Penkov <ppenkov@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Petar Penkov <ppenkov@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Stanislav Fomichev
c59016e100 tools/bpf: sync bpf_flow_keys flags
Export bpf_flow_keys flags to tools/libbpf/selftests.

Acked-by: Petar Penkov <ppenkov@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Petar Penkov <ppenkov@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
509ef92905 libbpf: provide more helpful message on uninitialized global var
When BPF program defines uninitialized global variable, it's put into
a special COMMON section. Libbpf will reject such programs, but will
provide very unhelpful message with garbage-looking section index.

This patch detects special section cases and gives more explicit error
message.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-09 08:40:44 -07:00
Andrii Nakryiko
2c9394f2a3 libbpf: set BTF FD for prog only when there is supported .BTF.ext data
5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD")
introduced backwards-compatibility issue, manifesting itself as -E2BIG
error returned on program load due to unknown non-zero btf_fd attribute
value for BPF_PROG_LOAD sys_bpf() sub-command.

This patch fixes bug by ensuring that we only ever associate BTF FD with
program if there is a BTF.ext data that was successfully loaded into
kernel, which automatically means kernel supports func_info/line_info
and associated BTF FD for progs (checked and ensured also by BTF
sanitization code).

Fixes: 5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD")
Reported-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-01 11:01:38 -07:00
Takshak Chahande
0f4d83f3ab libbpf : make libbpf_num_possible_cpus function thread safe
Having static variable `cpus` in libbpf_num_possible_cpus function
without guarding it with mutex makes this function thread-unsafe.

If multiple threads accessing this function, in the current form; it
leads to incrementing the static variable value `cpus` in the multiple
of total available CPUs.

Used local stack variable to calculate the number of possible CPUs and
then updated the static variable using WRITE_ONCE().

Changes since v1:
 * added stack variable to calculate cpus
 * serialized static variable update using WRITE_ONCE()
 * fixed Fixes tag

Fixes: 6446b3155521 ("bpf: add a new API libbpf_num_possible_cpus()")
Signed-off-by: Takshak Chahande <ctakshak@fb.com>
Acked-by: Andrey Ignatov <rdna@fb.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-08-01 11:01:38 -07:00
hex
6a7b28b6a1 libbpf: fix extraversion in Makefile
The current LIBBPF_VERSION (0.0.3) doesn't match with ABI version LIBBPF_0.0.4.
Fix the EXTRAVERSION portion.
2019-07-31 21:56:11 -07:00
Andrii Nakryiko
d76d264ac0 libbpf: fix erroneous multi-closing of BTF FD
Libbpf stores associated BTF FD per each instance of bpf_program. When
program is unloaded, that FD is closed. This is wrong, because leads to
a race and possibly closing of unrelated files, if application
simultaneously opens new files while bpf_programs are unloaded.

It's also unnecessary, because struct btf "owns" that FD, and
btf__free(), called from bpf_object__close() will close it. Thus the fix
is to never have per-program BTF FD and fetch it from obj->btf, when
necessary.

Fixes: 2993e0515bb4 ("tools/bpf: add support to read .BTF.ext sections")
Reported-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-29 16:32:58 -07:00
Andrii Nakryiko
63a3bdf23a libbpf: silence GCC8 warning about string truncation
Despite a proper NULL-termination after strncpy(..., ..., IFNAMSIZ - 1),
GCC8 still complains about *expected* string truncation:

  xsk.c:330:2: error: 'strncpy' output may be truncated copying 15 bytes
  from a string of length 15 [-Werror=stringop-truncation]
    strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1);

This patch gets rid of the issue altogether by using memcpy instead.
There is no performance regression, as strncpy will still copy and fill
all of the bytes anyway.

v1->v2:
- rebase against bpf tree.

Cc: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-29 16:32:58 -07:00
Ilya Maximets
12fa15e89a libbpf: fix using uninitialized ioctl results
'channels.max_combined' initialized only on ioctl success and
errno is only valid on ioctl failure.

The code doesn't produce any runtime issues, but makes memory
sanitizers angry:

 Conditional jump or move depends on uninitialised value(s)
    at 0x55C056F: xsk_get_max_queues (xsk.c:336)
    by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354)
    by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447)
    by 0x55C0E57: xsk_socket__create (xsk.c:601)
  Uninitialised value was created by a stack allocation
    at 0x55C04CD: xsk_get_max_queues (xsk.c:318)

Additionally fixed warning on uninitialized bytes in ioctl arguments:

 Syscall param ioctl(SIOCETHTOOL) points to uninitialised byte(s)
    at 0x648D45B: ioctl (in /usr/lib64/libc-2.28.so)
    by 0x55C0546: xsk_get_max_queues (xsk.c:330)
    by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354)
    by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447)
    by 0x55C0E57: xsk_socket__create (xsk.c:601)
  Address 0x1ffefff378 is on thread 1's stack
  in frame #1, created by xsk_get_max_queues (xsk.c:318)
  Uninitialised value was created by a stack allocation
    at 0x55C04CD: xsk_get_max_queues (xsk.c:318)

CC: Magnus Karlsson <magnus.karlsson@intel.com>
Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-29 16:32:58 -07:00
Arnaldo Carvalho de Melo
b987dcfecb libbpf: Avoid designated initializers for unnamed union members
As it fails to build in some systems with:

  libbpf.c: In function 'perf_buffer__new':
  libbpf.c:4515: error: unknown field 'sample_period' specified in initializer
  libbpf.c:4516: error: unknown field 'wakeup_events' specified in initializer

Doing as:

    attr.sample_period = 1;

I.e. not as a designated initializer makes it build everywhere.

Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Fixes: fb84b8224655 ("libbpf: add perf buffer API")
Link: https://lkml.kernel.org/n/tip-hnlmch8qit1ieksfppmr32si@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-29 16:32:58 -07:00
Arnaldo Carvalho de Melo
9c1ab4d070 libbpf: Fix endianness macro usage for some compilers
Using endian.h and its endianness macros makes this code build in a
wider range of compilers, as some don't have those macros
(__BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__),
so use instead endian.h's macros (__BYTE_ORDER, __LITTLE_ENDIAN,
__BIG_ENDIAN) which makes this code even shorter :-)

Acked-by: Andrii Nakryiko <andriin@fb.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Fixes: 12ef5634a855 ("libbpf: simplify endianness check")
Fixes: e6c64855fd7a ("libbpf: add btf__parse_elf API to load .BTF and .BTF.ext")
Link: https://lkml.kernel.org/n/tip-eep5n8vgwcdphw3uc058k03u@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-29 16:32:58 -07:00
Andrii Nakryiko
550aa56dd4 sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline commit:   8fc9f8bedf1bdaea48382ae2e3dd558e2b939cee
Checkpoint commit: 66b5f1c439843bcbab01cc7f3854ae2742f3d1e3

Andrii Nakryiko (2):
  libbpf: fix ptr to u64 conversion warning on 32-bit platforms
  libbpf: fix another GCC8 warning for strncpy

Baruch Siach (1):
  bpf: fix uapi bpf_prog_info fields alignment

Mauro Carvalho Chehab (2):
  docs: cgroup-v1: convert docs to ReST and rename to *.rst
  docs: cgroup-v1: add it to the admin-guide book

Stanislav Fomichev (1):
  bpf: sync bpf.h to tools/

 include/uapi/linux/bpf.h | 7 ++++---
 src/libbpf.c             | 4 ++--
 src/xsk.c                | 3 ++-
 3 files changed, 8 insertions(+), 6 deletions(-)

--
2.17.1
2019-07-23 14:26:50 -07:00
Andrii Nakryiko
54facd3fce libbpf: fix another GCC8 warning for strncpy
Similar issue was fixed in cdfc7f888c2a ("libbpf: fix GCC8 warning for
strncpy") already. This one was missed. Fixing now.

Cc: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-23 14:26:50 -07:00
Stanislav Fomichev
1346b5b538 bpf: sync bpf.h to tools/
Update bpf_sock_addr comments to indicate support for 8-byte reads
from user_ip6 and msg_src_ip6.

Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-23 14:26:50 -07:00
Andrii Nakryiko
78d3666065 libbpf: fix ptr to u64 conversion warning on 32-bit platforms
On 32-bit platforms compiler complains about conversion:

libbpf.c: In function ‘perf_event_open_probe’:
libbpf.c:4112:17: error: cast from pointer to integer of different
size [-Werror=pointer-to-int-cast]
  attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */
                 ^

Reported-by: Matt Hart <matthew.hart@linaro.org>
Fixes: b26500274767 ("libbpf: add kprobe/uprobe attach API")
Tested-by: Matt Hart <matthew.hart@linaro.org>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-23 14:26:50 -07:00
Mauro Carvalho Chehab
ce2eb85588 docs: cgroup-v1: add it to the admin-guide book
Those files belong to the admin guide, so add them.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-07-23 14:26:50 -07:00
Baruch Siach
6d4104b077 bpf: fix uapi bpf_prog_info fields alignment
Merge commit 1c8c5a9d38f60 ("Merge
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next") undid the
fix from commit 36f9814a494 ("bpf: fix uapi hole for 32 bit compat
applications") by taking the gpl_compatible 1-bit field definition from
commit b85fab0e67b162 ("bpf: Add gpl_compatible flag to struct
bpf_prog_info") as is. That breaks architectures with 16-bit alignment
like m68k. Add 31-bit pad after gpl_compatible to restore alignment of
following fields.

Thanks to Dmitry V. Levin his analysis of this bug history.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-23 14:26:50 -07:00
Mauro Carvalho Chehab
43c14e871c docs: cgroup-v1: convert docs to ReST and rename to *.rst
Convert the cgroup-v1 files to ReST format, in order to
allow a later addition to the admin-guide.

The conversion is actually:
  - add blank lines and identation in order to identify paragraphs;
  - fix tables markups;
  - add some lists markups;
  - mark literal blocks;
  - adjust title markups.

At its new index.rst, let's add a :orphan: while this is not linked to
the main index.rst file, in order to avoid build warnings.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
2019-07-23 14:26:50 -07:00
Andrii Nakryiko
e61f4b8269 scripts/sync-kernel.sh: add missing if_xdp.h in one of file lists
if_xdp.h wasn't added to one of few file lists, causing sync content
verification failure.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-07-19 15:12:56 -07:00
Andrii Nakryiko
80a0eca14b libbpf: sanitize VAR to conservative 1-byte INT
If VAR in non-sanitized BTF was size less than 4, converting such VAR
into an INT with size=4 will cause BTF validation failure due to
violationg of STRUCT (into which DATASEC was converted) member size.
Fix by conservatively using size=1.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-07-19 13:01:08 -07:00
Andrii Nakryiko
5a8c675d0a libbpf: fix SIGSEGV when BTF loading fails, but .BTF.ext exists
In case when BTF loading fails despite sanitization, but BPF object has
.BTF.ext loaded as well, we free and null obj->btf, but not
obj->btf_ext. This leads to an attempt to relocate .BTF.ext later on
during bpf_object__load(), which assumes obj->btf is present. This leads
to SIGSEGV on null pointer access. Fix bug by freeing and nulling
obj->btf_ext as well.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
2019-07-19 13:01:08 -07:00
Andrii Nakryiko
45ad862601 sync: latest libbpf changes from kernel
Syncing latest libbpf commits from kernel repository.
Baseline commit:   2c6a577d719e96c89b1aaa631089cce69b4d0045
Checkpoint commit: 8fc9f8bedf1bdaea48382ae2e3dd558e2b939cee

Andrii Nakryiko (19):
  libbpf: add common min/max macro to libbpf_internal.h
  libbpf: extract BTF loading logic
  libbpf: streamline ELF parsing error-handling
  libbpf: refactor map initialization
  libbpf: identify maps by section index in addition to offset
  libbpf: split initialization and loading of BTF
  libbpf: allow specifying map definitions using BTF
  libbpf: constify getter APIs
  libbpf: fix GCC8 warning for strncpy
  libbpf: make libbpf_strerror_r agnostic to sign of error
  libbpf: introduce concept of bpf_link
  libbpf: add ability to attach/detach BPF program to perf event
  libbpf: add kprobe/uprobe attach API
  libbpf: add tracepoint attach API
  libbpf: add raw tracepoint attach API
  libbpf: capture value in BTF type info for BTF-defined map defs
  libbpf: add perf buffer API
  libbpf: auto-set PERF_EVENT_ARRAY size to number of CPUs
  libbpf: add perf_buffer_ prefix to README

Colin Ian King (1):
  libbpf: fix spelling mistake "conflictling" -> "conflicting"

Daniel Borkmann (2):
  bpf: sync tooling uapi header
  bpf, libbpf: enable recvmsg attach types

Ivan Khoronzhuk (1):
  libbpf: fix max() type mismatch for 32bit

Leo Yan (1):
  bpf, libbpf, smatch: Fix potential NULL pointer dereference

Martynas Pumputis (1):
  bpf: sync BPF_FIB_LOOKUP flag changes with BPF uapi

Maxim Mikityanskiy (3):
  xsk: Add getsockopt XDP_OPTIONS
  libbpf: Support getsockopt XDP_OPTIONS
  xsk: Change the default frame size to 4096 and allow controlling it

Michal Rostecki (1):
  libbpf: Return btf_fd for load_sk_storage_btf

Stanislav Fomichev (4):
  bpf: sync bpf.h to tools/
  libbpf: support sockopt hooks
  bpf/tools: sync bpf.h
  bpf: sync bpf.h to tools/

Vincent Bernat (1):
  bonding: add an option to specify a delay between peer notifications

 include/uapi/linux/bpf.h     |   38 +-
 include/uapi/linux/if_link.h |    1 +
 include/uapi/linux/if_xdp.h  |    8 +
 src/README.rst               |    3 +-
 src/bpf.c                    |    7 +-
 src/bpf_prog_linfo.c         |    5 +-
 src/btf.c                    |    3 -
 src/btf.h                    |    1 +
 src/btf_dump.c               |    3 -
 src/libbpf.c                 | 1670 ++++++++++++++++++++++++++++------
 src/libbpf.h                 |  132 ++-
 src/libbpf.map               |   12 +-
 src/libbpf_internal.h        |   11 +-
 src/libbpf_probes.c          |   14 +-
 src/str_error.c              |    2 +-
 src/xsk.c                    |   15 +-
 src/xsk.h                    |    2 +-
 17 files changed, 1601 insertions(+), 326 deletions(-)

--
2.17.1
2019-07-08 12:52:46 -07:00
Stanislav Fomichev
5e4da17d43 bpf: sync bpf.h to tools/
Sync user_ip6 & msg_src_ip6 comments.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-08 12:52:46 -07:00
Andrii Nakryiko
2d8ab5cf2c libbpf: add perf_buffer_ prefix to README
perf_buffer "object" is part of libbpf API now, add it to the list of
libbpf function prefixes.

Suggested-by: Daniel Borkman <daniel@iogearbox.net>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-08 12:52:46 -07:00
Andrii Nakryiko
fe1ce6bd74 libbpf: auto-set PERF_EVENT_ARRAY size to number of CPUs
For BPF_MAP_TYPE_PERF_EVENT_ARRAY typically correct size is number of
possible CPUs. This is impossible to specify at compilation time. This
change adds automatic setting of PERF_EVENT_ARRAY size to number of
system CPUs, unless non-zero size is specified explicitly. This allows
to adjust size for advanced specific cases, while providing convenient
and logical defaults.

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-07-08 12:52:46 -07:00
Andrii Nakryiko
9007494e6c libbpf: add perf buffer API
BPF_MAP_TYPE_PERF_EVENT_ARRAY map is often used to send data from BPF program
to user space for additional processing. libbpf already has very low-level API
to read single CPU perf buffer, bpf_perf_event_read_simple(), but it's hard to
use and requires a lot of code to set everything up. This patch adds
perf_buffer abstraction on top of it, abstracting setting up and polling
per-CPU logic into simple and convenient API, similar to what BCC provides.

perf_buffer__new() sets up per-CPU ring buffers and updates corresponding BPF
map entries. It accepts two user-provided callbacks: one for handling raw
samples and one for get notifications of lost samples due to buffer overflow.

perf_buffer__new_raw() is similar, but provides more control over how
perf events are set up (by accepting user-provided perf_event_attr), how
they are handled (perf_event_header pointer is passed directly to
user-provided callback), and on which CPUs ring buffers are created
(it's possible to provide a list of CPUs and corresponding map keys to
update). This API allows advanced users fuller control.

perf_buffer__poll() is used to fetch ring buffer data across all CPUs,
utilizing epoll instance.

perf_buffer__free() does corresponding clean up and unsets FDs from BPF map.

All APIs are not thread-safe. User should ensure proper locking/coordination if
used in multi-threaded set up.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-08 12:52:46 -07:00