bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@fb.com,
	daniel@iogearbox.net, andrii.nakryiko@gmail.com,
	kernel-team@fb.com
Subject: Re: [PATCH v4 bpf-next 0/4] Add libbpf-provided extern variables support
Date: Sun, 15 Dec 2019 16:52:10 -0800	[thread overview]
Message-ID: <20191216005209.jqb27p7tptauxn45@ast-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20191214014710.3449601-1-andriin@fb.com>

On Fri, Dec 13, 2019 at 05:47:06PM -0800, Andrii Nakryiko wrote:
> 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 #3 explicitly tests a scenario of using unsupported BPF
> helper, to validate the approach.
> 
> This patch set heavily relies on BTF type information emitted by compiler for
> each extern variable declaration. Based on specific types, libbpf does strict
> checks of config data values correctness. See patch #1 for details.
> 
> Outline of the patch set:
> - patch #1 does a small clean up of internal map names contants;
> - patch #2 adds all of the libbpf internal machinery for externs support,
>   including setting up BTF information for .extern data section;
> - patch #3 adds support for .extern into BPF skeleton;
> - patch #4 adds externs selftests, as well as enhances test_skeleton.c test to
>   validate mmap()-ed .extern datasection functionality.

Applied. Thanks.

Looking at the tests that do mkstemp()+write() just to pass a file path
as .kconfig_path option into bpf_object_open_opts() it feels that file only
support for externs is unnecessary limiting. I think it will simplify
tests and will make the whole extern support more flexible if in addition to
kconfig_path bpf_object_open_opts() would support in-memory configuration.

  parent reply	other threads:[~2019-12-16  0:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14  1:47 [PATCH v4 bpf-next 0/4] Add libbpf-provided extern variables support Andrii Nakryiko
2019-12-14  1:47 ` [PATCH v4 bpf-next 1/4] libbpf: extract internal map names into constants Andrii Nakryiko
2019-12-14  1:47 ` [PATCH v4 bpf-next 2/4] libbpf: support libbpf-provided extern variables Andrii Nakryiko
2019-12-14 12:50   ` Toke Høiland-Jørgensen
2019-12-14 20:27     ` Yonghong Song
2019-12-16 11:17   ` Daniel Borkmann
2019-12-16 19:29     ` Andrii Nakryiko
2019-12-17 14:42       ` Daniel Borkmann
2019-12-17 19:03         ` Andrii Nakryiko
2019-12-17 19:50           ` Daniel Borkmann
2019-12-17 20:16             ` Alexei Starovoitov
2019-12-17 23:37               ` Daniel Borkmann
2019-12-18  0:08                 ` Andrii Nakryiko
2019-12-16 12:43   ` Daniel Borkmann
2019-12-16 18:19     ` Andrii Nakryiko
2019-12-14  1:47 ` [PATCH v4 bpf-next 3/4] bpftool: generate externs datasec in BPF skeleton Andrii Nakryiko
2019-12-14  1:47 ` [PATCH v4 bpf-next 4/4] selftests/bpf: add tests for libbpf-provided externs Andrii Nakryiko
2019-12-16  0:52 ` Alexei Starovoitov [this message]
2019-12-16  1:47   ` [PATCH v4 bpf-next 0/4] Add libbpf-provided extern variables support Andrii Nakryiko
2019-12-16  4:42     ` Alexei Starovoitov
2019-12-16 19:34       ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191216005209.jqb27p7tptauxn45@ast-mbp.dhcp.thefacebook.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).