bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/6] Add libbpf-provided extern variables support
@ 2019-11-17  7:08 Andrii Nakryiko
  2019-11-17  7:08 ` [PATCH bpf-next 1/6] selftests/bpf: ensure no DWARF relocations for BPF object files Andrii Nakryiko
                   ` (6 more replies)
  0 siblings, 7 replies; 20+ messages in thread
From: Andrii Nakryiko @ 2019-11-17  7:08 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko

It's often important for BPF program to know kernel version or some specific
config values (e.g., CONFIG_HZ to convert jiffies to seconds) and change or
adjust program logic based on their values. As of today, any such need has to
be resolved by recompiling BPF program for specific kernel and kernel
configuration. In practice this is usually achieved by using BCC and its
embedded LLVM/Clang. With such set up #ifdef CONFIG_XXX and similar
compile-time constructs allow to deal with kernel varieties.

With CO-RE (Compile Once – Run Everywhere) approach, this is not an option,
unfortunately. All such logic variations have to be done as a normal
C language constructs (i.e., if/else, variables, etc), not a preprocessor
directives. This patch series add support for such advanced scenarios through
C extern variables. These extern variables will be recognized by libbpf and
supplied through extra .extern internal map, similarly to global data. This
.extern map is read-only, which allows BPF verifier to track its content
precisely as constants. That gives an opportunity to have pre-compiled BPF
program, which can potentially use BPF functionality (e.g., BPF helpers) or
kernel features (types, fields, etc), that are available only on a subset of
targeted kernels, while effectively eleminating (through verifier's dead code
detection) such unsupported functionality for other kernels (typically, older
versions). Patch #5 contains all the details. Patch #5 explicitly tests
a scenario of using unsupported BPF helper, to validate the approach.

As part of this patch set, libbpf also allows usage of initialized global
(non-static) variables, which provides better Clang semantics, which is closer
and better aligned witht kernel vs userspace BPF map contents sharing.

Outline of the patch set:
- patches #1-#3 do some preliminary refactorings of libbpf relocation logic
  and some more clean ups;
- patch #4 allows non-static variables and converts few tests to use them;
- patch #5 adds support for externs to libbpf;
- patch #6 adds tests for externs.

Andrii Nakryiko (6):
  selftests/bpf: ensure no DWARF relocations for BPF object files
  libbpf: refactor relocation handling
  libbpf: fix various errors and warning reported by checkpatch.pl
  libbpf: support initialized global variables
  libbpf: support libbpf-provided extern variables
  selftests/bpf: add tests for libbpf-provided externs

 tools/lib/bpf/Makefile                        |  17 +-
 tools/lib/bpf/libbpf.c                        | 758 +++++++++++++-----
 tools/lib/bpf/libbpf.h                        |   8 +-
 tools/testing/selftests/bpf/Makefile          |   4 +-
 .../selftests/bpf/prog_tests/core_extern.c    | 186 +++++
 .../selftests/bpf/progs/test_core_extern.c    |  43 +
 .../bpf/progs/test_core_reloc_arrays.c        |   4 +-
 .../progs/test_core_reloc_bitfields_direct.c  |   4 +-
 .../progs/test_core_reloc_bitfields_probed.c  |   4 +-
 .../bpf/progs/test_core_reloc_existence.c     |   4 +-
 .../bpf/progs/test_core_reloc_flavors.c       |   4 +-
 .../bpf/progs/test_core_reloc_ints.c          |   4 +-
 .../bpf/progs/test_core_reloc_kernel.c        |   4 +-
 .../bpf/progs/test_core_reloc_misc.c          |   4 +-
 .../bpf/progs/test_core_reloc_mods.c          |   4 +-
 .../bpf/progs/test_core_reloc_nesting.c       |   4 +-
 .../bpf/progs/test_core_reloc_primitives.c    |   4 +-
 .../bpf/progs/test_core_reloc_ptr_as_arr.c    |   4 +-
 .../bpf/progs/test_core_reloc_size.c          |   4 +-
 19 files changed, 820 insertions(+), 248 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/core_extern.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_core_extern.c

-- 
2.17.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2019-11-21  4:40 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-17  7:08 [PATCH bpf-next 0/6] Add libbpf-provided extern variables support Andrii Nakryiko
2019-11-17  7:08 ` [PATCH bpf-next 1/6] selftests/bpf: ensure no DWARF relocations for BPF object files Andrii Nakryiko
2019-11-17  7:08 ` [PATCH bpf-next 2/6] libbpf: refactor relocation handling Andrii Nakryiko
2019-11-17  7:08 ` [PATCH bpf-next 3/6] libbpf: fix various errors and warning reported by checkpatch.pl Andrii Nakryiko
2019-11-17  7:08 ` [PATCH bpf-next 4/6] libbpf: support initialized global variables Andrii Nakryiko
2019-11-17  7:08 ` [PATCH bpf-next 5/6] libbpf: support libbpf-provided extern variables Andrii Nakryiko
2019-11-19  3:21   ` Alexei Starovoitov
2019-11-19  6:57     ` Andrii Nakryiko
2019-11-19 15:42       ` Andrii Nakryiko
2019-11-19 15:58         ` Alexei Starovoitov
2019-11-19 23:32           ` Daniel Borkmann
2019-11-20  3:17             ` Andrii Nakryiko
2019-11-20  3:44           ` Andrii Nakryiko
2019-11-20 21:39             ` Alexei Starovoitov
2019-11-20 22:47               ` Andrii Nakryiko
2019-11-21  0:18                 ` Alexei Starovoitov
2019-11-21  2:13                   ` Andrii Nakryiko
2019-11-21  4:39                     ` Alexei Starovoitov
2019-11-17  7:08 ` [PATCH bpf-next 6/6] selftests/bpf: add tests for libbpf-provided externs Andrii Nakryiko
2019-11-17  7:12 ` [PATCH bpf-next 0/6] Add libbpf-provided extern variables support Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).