All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@fb.com>
To: Andrii Nakryiko <andriin@fb.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>
Cc: "andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH v4 bpf-next 6/7] libbpf: add BPF_CORE_READ/BPF_CORE_READ_INTO helpers
Date: Tue, 8 Oct 2019 04:56:25 +0000	[thread overview]
Message-ID: <035617e9-2d0d-4082-8862-45bc4bb210fe@fb.com> (raw)
In-Reply-To: <20191007224712.1984401-7-andriin@fb.com>

On 10/7/19 3:47 PM, Andrii Nakryiko wrote:
> Add few macros simplifying BCC-like multi-level probe reads, while also
> emitting CO-RE relocations for each read.
> 
> Acked-by: John Fastabend <john.fastabend@gmail.com>
> Acked-by: Song Liu <songliubraving@fb.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
...
> +/*
> + * BPF_CORE_READ() is used to simplify BPF CO-RE relocatable read, especially
> + * when there are few pointer chasing steps.
> + * E.g., what in non-BPF world (or in BPF w/ BCC) would be something like:
> + *	int x = s->a.b.c->d.e->f->g;
> + * can be succinctly achieved using BPF_CORE_READ as:
> + *	int x = BPF_CORE_READ(s, a.b.c, d.e, f, g);
> + *
> + * BPF_CORE_READ will decompose above statement into 4 bpf_core_read (BPF
> + * CO-RE relocatable bpf_probe_read() wrapper) calls, logically equivalent to:
> + * 1. const void *__t = s->a.b.c;
> + * 2. __t = __t->d.e;
> + * 3. __t = __t->f;
> + * 4. return __t->g;
> + *
> + * Equivalence is logical, because there is a heavy type casting/preservation
> + * involved, as well as all the reads are happening through bpf_probe_read()
> + * calls using __builtin_preserve_access_index() to emit CO-RE relocations.
> + *
> + * N.B. Only up to 9 "field accessors" are supported, which should be more
> + * than enough for any practical purpose.
> + */
> +#define BPF_CORE_READ(src, a, ...)					    \
> +	({								    \
> +		___type(src, a, ##__VA_ARGS__) __r;			    \
> +		BPF_CORE_READ_INTO(&__r, src, a, ##__VA_ARGS__);	    \
> +		__r;							    \
> +	})
> +

Since we're splitting things into
bpf_{helpers,helper_defs,endian,tracing}.h
how about adding all core macros into bpf_core_read.h ?
#define___concat, ___empty are very generic names.
I'd rather contain the risk of conflicts to progs that are going
to use co-re instead of forcing it on all progs that use bpf_helpers.h.
With my btf vmlinux stuff all these bpf_probe_read*() wrappers
hopefully will be obsolete eventually. So keeping them separate in 
bpf_core_read.h would help the transition too.

  reply	other threads:[~2019-10-08  4:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07 22:47 [PATCH v4 bpf-next 0/7] Move bpf_helpers and add BPF_CORE_READ macros Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 1/7] selftests/bpf: undo GCC-specific bpf_helpers.h changes Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 2/7] selftests/bpf: samples/bpf: split off legacy stuff from bpf_helpers.h Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 3/7] selftests/bpf: adjust CO-RE reloc tests for new bpf_core_read() macro Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 4/7] selftests/bpf: split off tracing-only helpers into bpf_tracing.h Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 5/7] libbpf: move bpf_{helpers,helper_defs,endian,tracing}.h into libbpf Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 6/7] libbpf: add BPF_CORE_READ/BPF_CORE_READ_INTO helpers Andrii Nakryiko
2019-10-08  4:56   ` Alexei Starovoitov [this message]
2019-10-08  6:15     ` Andrii Nakryiko
2019-10-08 15:10       ` Alexei Starovoitov
2019-10-08 16:53         ` Andrii Nakryiko
2019-10-07 22:47 ` [PATCH v4 bpf-next 7/7] selftests/bpf: add BPF_CORE_READ and BPF_CORE_READ_STR_INTO macro tests 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=035617e9-2d0d-4082-8862-45bc4bb210fe@fb.com \
    --to=ast@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.