[PATCH bpf-next 0/2] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
. Stanislav Fomichev (2): selftests/bpf: rename flow dissector section to flow_dissector bpftool: support loading flow dissector .../bpftool/Documentation/bpftool-prog.rst| 16 ++- tools/bpf/bpftool/common.c| 32 +++-- tools/bpf/bpftool/main.h | 1

[PATCH bpf-next 1/2] selftests/bpf: rename flow dissector section to flow_dissector

2018-11-07 Thread Stanislav Fomichev
Makes it compatible with the logic that derives program type from section name in libbpf_prog_type_by_name. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/bpf_flow.c | 2 +- tools/testing/selftests/bpf/test_flow_dissector.sh | 2 +- 2 files changed, 2 insertions

[PATCH bpf-next 2/2] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
-by: Stanislav Fomichev --- .../bpftool/Documentation/bpftool-prog.rst| 16 ++- tools/bpf/bpftool/common.c| 32 +++-- tools/bpf/bpftool/main.h | 1 + tools/bpf/bpftool/prog.c | 135 +++--- 4 files changed, 141 insertions

Re: [PATCH bpf-next 2/2] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 11:35:52 -0800, Stanislav Fomichev wrote: > > This commit adds support for loading/attaching/detaching flow > > dissector program. The structure of the flow dissector program is > > assumed to be the sam

[PATCH bpf-next 3/3] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
/0 bpftool prog attach pinned /sys/fs/bpf/flow/flow_dissector/0 flow_dissector Tested by using the above lines to load the prog in the test_flow_dissector.sh selftest. Signed-off-by: Stanislav Fomichev --- .../bpftool/Documentation/bpftool-prog.rst| 26 +++-- tools/bpf/bpftool/bash

[PATCH v2 bpf-next 0/3] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
ails. Stanislav Fomichev (3): selftests/bpf: rename flow dissector section to flow_dissector libbpf: cleanup after partial failure in bpf_object__pin bpftool: support loading flow dissector .../bpftool/Documentation/bpftool-prog.rst| 26 +++-- tools/bpf/bpftool/bash-completion/bpftool

[PATCH bpf-next 2/3] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-07 Thread Stanislav Fomichev
bpftool will use bpf_object__pin in the next commit to pin all programs and maps from the file; in case of a partial failure, we need to get back to the clean state (undo previous program/map pins). Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 58

[PATCH bpf-next 1/3] selftests/bpf: rename flow dissector section to flow_dissector

2018-11-07 Thread Stanislav Fomichev
Makes it compatible with the logic that derives program type from section name in libbpf_prog_type_by_name. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/bpf_flow.c | 2 +- tools/testing/selftests/bpf/test_flow_dissector.sh | 2 +- 2 files changed, 2 insertions

Re: [PATCH bpf-next 3/3] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 15:13:33 -0800, Stanislav Fomichev wrote: > > On 11/07, Jakub Kicinski wrote: > > > On Wed, 7 Nov 2018 14:43:56 -0800, Stanislav Fomichev wrote: > > > > bpftool map update pinned /sys/fs/bpf/flow/jmp_table

Re: [PATCH bpf-next 3/3] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 15:34:48 -0800, Stanislav Fomichev wrote: > > On 11/07, Jakub Kicinski wrote: > > > On Wed, 7 Nov 2018 15:13:33 -0800, Stanislav Fomichev wrote: > > > > On 11/07, Jakub Kicinski wrote: > > > > >

Re: [PATCH bpf-next 2/3] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 14:43:55 -0800, Stanislav Fomichev wrote: > > bpftool will use bpf_object__pin in the next commit to pin all programs > > and maps from the file; in case of a partial failure, we need to get > > back to the clean state (

Re: [PATCH bpf-next 3/3] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 14:43:56 -0800, Stanislav Fomichev wrote: > > bpftool map update pinned /sys/fs/bpf/flow/jmp_table \ > > key 0 0 0 0 \ > > value pinned /sys/fs/bpf/flow/IP/0 > > Where is that /0 coming from ? Is th

Re: [PATCH bpf-next 2/2] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 14:15:06 -0800, Stanislav Fomichev wrote: > > On 11/07, Quentin Monnet wrote: > > > 2018-11-07 12:32 UTC-0800 ~ Jakub Kicinski > > > > > > > On Wed, 7 Nov 2018 20:08:53 +, Quentin Monnet wrote: &g

Re: [PATCH bpf-next 2/2] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Quentin Monnet wrote: > Hi Stanislav, > > 2018-11-07 11:35 UTC-0800 ~ Stanislav Fomichev > > This commit adds support for loading/attaching/detaching flow > > dissector program. The structure of the flow dissector program is > > assumed to be t

Re: [PATCH bpf-next 2/3] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-07 Thread Stanislav Fomichev
On 11/07, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 15:00:21 -0800, Stanislav Fomichev wrote: > > > > +err_unpin_programs: > > > > + bpf_object__for_each_program(prog, obj) { > > > > + char buf[PATH_MAX]; > > > > +

Re: [PATCH bpf-next 2/2] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
On 11/07, Quentin Monnet wrote: > 2018-11-07 12:32 UTC-0800 ~ Jakub Kicinski > > On Wed, 7 Nov 2018 20:08:53 +, Quentin Monnet wrote: > > > > + err = bpf_obj_pin(bpf_program__fd(prog), pinfile); > > > > + if (err) { > > > > + p_err("failed to

[PATCH v3 bpf-next 0/4] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
hich is now being used to attach all flow dissector progs/maps * third patch adds special case in bpf_program__pin for programs with single instances (we don't create /0 pin anymore, just ) * forth patch adds actual support to the bpftool See forth patch for the description/details. Stani

[PATCH v3 bpf-next 4/4] bpftool: support loading flow dissector

2018-11-07 Thread Stanislav Fomichev
prog attach pinned /sys/fs/bpf/flow/flow_dissector flow_dissector Tested by using the above lines to load the prog in the test_flow_dissector.sh selftest. Signed-off-by: Stanislav Fomichev --- .../bpftool/Documentation/bpftool-prog.rst| 36 -- tools/bpf/bpftool/bash-completion/bpftool

[PATCH v3 bpf-next 3/4] libbpf: bpf_program__pin: add special case for instances.nr == 1

2018-11-07 Thread Stanislav Fomichev
on the case where '/0' is always created. However, I couldn't find any serious usage of bpf_program__pin inside the kernel tree and I suppose there should be none outside. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 10 ++ 1 file changed, 10 insertions(+) diff --git

[PATCH v3 bpf-next 2/4] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-07 Thread Stanislav Fomichev
bpftool will use bpf_object__pin in the next commit to pin all programs and maps from the file; in case of a partial failure, we need to get back to the clean state (undo previous program/map pins). Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 248

[PATCH v3 bpf-next 1/4] selftests/bpf: rename flow dissector section to flow_dissector

2018-11-07 Thread Stanislav Fomichev
Makes it compatible with the logic that derives program type from section name in libbpf_prog_type_by_name. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/bpf_flow.c | 2 +- tools/testing/selftests/bpf/test_flow_dissector.sh | 2 +- 2 files changed, 2 insertions

Re: [PATCH v3 bpf-next 4/4] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
On 11/08, Quentin Monnet wrote: > 2018-11-08 10:01 UTC-0800 ~ Stanislav Fomichev > > On 11/08, Quentin Monnet wrote: > >> Hi Stanislav, thanks for the changes! More comments below. > > Thank you for another round of review! > > > >> 2018-11

Re: [PATCH v3 bpf-next 4/4] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
On 11/08, Quentin Monnet wrote: > Hi Stanislav, thanks for the changes! More comments below. Thank you for another round of review! > 2018-11-07 21:39 UTC-0800 ~ Stanislav Fomichev > > This commit adds support for loading/attaching/detaching flow > > dissector program. The str

Re: [PATCH v3 bpf-next 4/4] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
On 11/08, Jakub Kicinski wrote: > On Wed, 7 Nov 2018 21:39:57 -0800, Stanislav Fomichev wrote: > > This commit adds support for loading/attaching/detaching flow > > dissector program. The structure of the flow dissector program is > > assumed to be the sam

Re: [PATCH v3 bpf-next 4/4] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
On 11/08, Jakub Kicinski wrote: > On Thu, 8 Nov 2018 11:16:43 +, Quentin Monnet wrote: > > > - bpf_program__set_ifindex(prog, ifindex); > > > if (attr.prog_type == BPF_PROG_TYPE_UNSPEC) { > > > + if (!prog) { > > > + p_err("can not guess program type when

Re: [PATCH v3 bpf-next 4/4] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
On 11/08, Jakub Kicinski wrote: > On Thu, 8 Nov 2018 18:21:24 +, Quentin Monnet wrote: > > >>> @@ -79,8 +82,11 @@ DESCRIPTION > > >>> contain a dot character ('.'), which is reserved for > > >>> future > > >>> extensions of *bpffs*. > > >>> -

[PATCH v4 bpf-next 1/7] selftests/bpf: rename flow dissector section to flow_dissector

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev Makes it compatible with the logic that derives program type from section name in libbpf_prog_type_by_name. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/bpf_flow.c | 2 +- tools/testing/selftests/bpf/test_flow_dissector.sh | 2 +- 2

[PATCH v4 bpf-next 4/7] libbpf: add internal pin_name

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev pin_name is the same as section_name where '/' is replaced by '_'. bpf_object__pin_programs is converted to use pin_name to avoid the situation where section_name would require creating another subdirectory for a pin (as, for example, when calling

[PATCH v4 bpf-next 3/7] libbpf: bpf_program__pin: add special case for instances.nr == 1

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev When bpf_program has only one instance, don't create a subdirectory with per-instance pin files (/0). Instead, just create a single pin file for that single instance. This simplifies object pinning by not creating unnecessary subdirectories. This can potentially break

[PATCH v4 bpf-next 0/7] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev v4 changes: * addressed another round of comments/style issues from Jakub Kicinski & Quentin Monnet (thanks!) * implemented bpf_object__pin_maps and bpf_object__pin_programs helpers and used them in bpf_program__pin * added new pin_name to bpf_progra

[PATCH v4 bpf-next 5/7] bpftool: add loadall command

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev This patch adds new *loadall* command which slightly differs from the existing *load*. *load* command loads all programs from the obj file, but pins only the first programs. *loadall* pins all programs from the obj file under specified directory. The intended usecase

[PATCH v4 bpf-next 6/7] bpftool: add pinmaps argument to the load/loadall

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev This new additional argument lets users pin all maps from the object at specified path. Signed-off-by: Stanislav Fomichev --- .../bpftool/Documentation/bpftool-prog.rst| 4 +++- tools/bpf/bpftool/bash-completion/bpftool | 3 ++- tools/bpf/bpftool/prog.c

[PATCH v4 bpf-next 2/7] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev bpftool will use bpf_object__pin in the next commits to pin all programs and maps from the file; in case of a partial failure, we need to get back to the clean state (undo previous program/map pins). As part of a cleanup, I've added and exported separate routines to pin

[PATCH v4 bpf-next 7/7] bpftool: support loading flow dissector

2018-11-08 Thread Stanislav Fomichev
From: Stanislav Fomichev This commit adds support for loading/attaching/detaching flow dissector program. The structure of the flow dissector program is assumed to be the same as in the selftests: * flow_dissector section with the main entry point * a bunch of tail call progs * a jmp_table map

Re: [PATCH v5 bpf-next 2/7] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-12 Thread Stanislav Fomichev
On 11/12, Martin Lau wrote: > On Mon, Nov 12, 2018 at 02:10:11PM -0800, Stanislav Fomichev wrote: > > On 11/12, Martin Lau wrote: > > > On Fri, Nov 09, 2018 at 08:21:41AM -0800, Stanislav Fomichev wrote: > > > [ ... ] > > > > @@ -1918,23 +2160,20 @@ void *

Re: [PATCH bpf-next v2] bpftool: make libbfd optional

2018-11-13 Thread Stanislav Fomichev
On 11/13, Quentin Monnet wrote: > 2018-11-12 14:02 UTC-0800 ~ Jakub Kicinski > > On Mon, 12 Nov 2018 13:44:10 -0800, Stanislav Fomichev wrote: > >> Make it possible to build bpftool without libbfd. libbfd and libopcodes are > >> typically provided in dev/dbg packa

Re: [PATCH bpf-next v2] bpftool: make libbfd optional

2018-11-15 Thread Stanislav Fomichev
On 11/13, Quentin Monnet wrote: > 2018-11-12 14:02 UTC-0800 ~ Jakub Kicinski > > On Mon, 12 Nov 2018 13:44:10 -0800, Stanislav Fomichev wrote: > >> Make it possible to build bpftool without libbfd. libbfd and libopcodes are > >> typically provided in dev/dbg packa

Re: [PATCH v4 bpf-next 5/7] bpftool: add loadall command

2018-11-09 Thread Stanislav Fomichev
On 11/09, Quentin Monnet wrote: > 2018-11-08 16:22 UTC-0800 ~ Stanislav Fomichev > > From: Stanislav Fomichev > > > > This patch adds new *loadall* command which slightly differs from the > > existing *load*. *load* command loads all programs from the obj file,

Re: [PATCH v4 bpf-next 2/7] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-09 Thread Stanislav Fomichev
On 11/08, Jakub Kicinski wrote: > On Thu, 8 Nov 2018 16:22:08 -0800, Stanislav Fomichev wrote: > > + for (map = bpf_map__prev(map, obj); > > +map != NULL; > > +map = bpf_map__prev(map, obj)) { > > nit pick: if you need to respin all these for

[PATCH v5 bpf-next 0/7] bpftool: support loading flow dissector

2018-11-09 Thread Stanislav Fomichev
ad/loadall to let users pin all maps of the obj file * seventh patch adds actual flow_dissector support to the bpftool and an example Stanislav Fomichev (7): selftests/bpf: rename flow dissector section to flow_dissector libbpf: cleanup after partial failure in bpf_object__pin libbpf:

[PATCH v5 bpf-next 2/7] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-09 Thread Stanislav Fomichev
(bpf_object__pin_maps) and progs (bpf_object__pin_programs) of an object. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 324 ++--- tools/lib/bpf/libbpf.h | 18 +++ 2 files changed, 319 insertions(+), 23 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools

[PATCH v5 bpf-next 7/7] bpftool: support loading flow dissector

2018-11-09 Thread Stanislav Fomichev
0 0 0 \ value pinned /sys/fs/bpf/flow/VLAN bpftool prog attach pinned /sys/fs/bpf/flow/flow_dissector flow_dissector Tested by using the above lines to load the prog in the test_flow_dissector.sh selftest. Signed-off-by: Stanislav Fomichev Acked-by: Jakub Kicinski --- .../bpftool

[PATCH v5 bpf-next 6/7] bpftool: add pinmaps argument to the load/loadall

2018-11-09 Thread Stanislav Fomichev
This new additional argument lets users pin all maps from the object at specified path. Signed-off-by: Stanislav Fomichev Acked-by: Jakub Kicinski --- .../bpftool/Documentation/bpftool-prog.rst| 4 +++- tools/bpf/bpftool/bash-completion/bpftool | 3 ++- tools/bpf/bpftool/prog.c

[PATCH v5 bpf-next 5/7] bpftool: add loadall command

2018-11-09 Thread Stanislav Fomichev
want to load a bunch of progs, pin them all and after that construct a jump table. Signed-off-by: Stanislav Fomichev Acked-by: Jakub Kicinski --- .../bpftool/Documentation/bpftool-prog.rst| 14 ++-- tools/bpf/bpftool/bash-completion/bpftool | 4 +- tools/bpf/bpftool/common.c

[PATCH v5 bpf-next 3/7] libbpf: bpf_program__pin: add special case for instances.nr == 1

2018-11-09 Thread Stanislav Fomichev
on the case where '/0' is always created. However, I couldn't find any serious usage of bpf_program__pin inside the kernel tree and I suppose there should be none outside. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 10 ++ 1 file changed, 10 insertions(+) diff --git

[PATCH v5 bpf-next 1/7] selftests/bpf: rename flow dissector section to flow_dissector

2018-11-09 Thread Stanislav Fomichev
Makes it compatible with the logic that derives program type from section name in libbpf_prog_type_by_name. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/bpf_flow.c | 2 +- tools/testing/selftests/bpf/test_flow_dissector.sh | 2 +- 2 files changed, 2 insertions

[PATCH v5 bpf-next 4/7] libbpf: add internal pin_name

2018-11-09 Thread Stanislav Fomichev
like "cgroup/connect6"). Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 29 ++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 97ce9f214002..e827542ffa3a 100644 --- a/too

[PATCH bpf-next] bpftool: make libbfd optional

2018-11-12 Thread Stanislav Fomichev
Make it possible to build bpftool without libbfd. This excludes support for disassembling jit-ted code and prints an error if the user tries to use these features. Tested by: cat > FEATURES_DUMP.bpftool < --- tools/bpf/bpftool/Makefile | 13 +++-- tools/bpf/bpftool/jit_disasm.c | 7

[PATCH bpf-next v2] bpftool: make libbfd optional

2018-11-12 Thread Stanislav Fomichev
Make it possible to build bpftool without libbfd. libbfd and libopcodes are typically provided in dev/dbg packages (binutils-dev in debian) which we usually don't have installed on the fleet machines and we'd like a way to have bpftool version that works without installing any additional packages.

Re: [PATCH v5 bpf-next 2/7] libbpf: cleanup after partial failure in bpf_object__pin

2018-11-12 Thread Stanislav Fomichev
On 11/12, Martin Lau wrote: > On Fri, Nov 09, 2018 at 08:21:41AM -0800, Stanislav Fomichev wrote: > [ ... ] > > @@ -1918,23 +2160,20 @@ void *bpf_object__priv(struct bpf_object *obj) > > } > > > > static struct bpf_program * > > -__bpf_program__next(struct

Re: [PATCH bpf-next] bpftool: make libbfd optional

2018-11-12 Thread Stanislav Fomichev
On 11/12, Jakub Kicinski wrote: > On Mon, 12 Nov 2018 10:53:28 -0800, Stanislav Fomichev wrote: > > Make it possible to build bpftool without libbfd. This excludes support for > > disassembling jit-ted code and prints an error if the user tries to use > > these feat

Re: [PATCH bpf-next] bpftool: make libbfd optional

2018-11-12 Thread Stanislav Fomichev
On 11/12, Jakub Kicinski wrote: > On Mon, 12 Nov 2018 11:58:27 -0800, Stanislav Fomichev wrote: > > On 11/12, Jakub Kicinski wrote: > > > On Mon, 12 Nov 2018 10:53:28 -0800, Stanislav Fomichev wrote: > > > > diff --git a/tools/bpf/bpftool/main.h b/tools/bp

Re: [PATCH bpf-next v2] bpftool: make libbfd optional

2018-11-16 Thread Stanislav Fomichev
On 11/16, Alexei Starovoitov wrote: > On Fri, Nov 16, 2018 at 08:52:23PM -0800, Stanislav Fomichev wrote: > > I actually wanted to follow up with a v2 when > > https://lkml.org/lkml/2018/11/16/243 reaches bpf-next (I got an ack > > already). > > it will go via pe

[PATCH bpf-next v2 5/5] selftests/bpf: add simple BPF_PROG_TEST_RUN examples for flow dissector

2018-12-03 Thread Stanislav Fomichev
Use existing pkt_v4 and pkt_v6 to make sure flow_keys are what we want. Also, add new bpf_flow_load routine (and flow_dissector_load.h header) that loads bpf_flow.o program and does all required setup. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/Makefile | 3

[PATCH bpf-next v2 0/5] support flow dissector in BPF_PROG_TEST_RUN

2018-12-03 Thread Stanislav Fomichev
, ...) to __skb_flow_bpf_dissect * set test iterations to 10 Stanislav Fomichev (5): net/flow_dissector: move bpf case into __skb_flow_bpf_dissect bpf: add BPF_PROG_TEST_RUN support for flow dissector selftests/bpf: use thoff instead of nhoff in BPF flow dissector net/flow_dissector: correctly cap nhoff and thoff

[PATCH bpf-next v2 4/5] net/flow_dissector: correctly cap nhoff and thoff in case of BPF

2018-12-03 Thread Stanislav Fomichev
We want to make sure that the following condition holds: 0 <= nhoff <= thoff <= skb->len BPF program can set out-of-bounds nhoff and thoff, which is dangerous, see recent commit d0c081b49137 ("flow_dissector: properly cap thoff field")'. Signed-off-by: Stanislav F

[PATCH bpf-next v2 3/5] selftests/bpf: use thoff instead of nhoff in BPF flow dissector

2018-12-03 Thread Stanislav Fomichev
much sense (this is relevant in the context of the next patch, where I add simple selftest and manually construct expected flow_keys). Signed-off-by: Stanislav Fomichev --- net/core/flow_dissector.c | 1 + tools/testing/selftests/bpf/bpf_flow.c | 36 -- 2 files

[PATCH bpf-next v2 2/5] bpf: add BPF_PROG_TEST_RUN support for flow dissector

2018-12-03 Thread Stanislav Fomichev
The input is packet data, the output is struct bpf_flow_key. This should make it easy to test flow dissector programs without elaborate setup. Signed-off-by: Stanislav Fomichev --- include/linux/bpf.h | 3 ++ net/bpf/test_run.c | 71 - net/core

[PATCH bpf-next v2 1/5] net/flow_dissector: move bpf case into __skb_flow_bpf_dissect

2018-12-03 Thread Stanislav Fomichev
This way, we can reuse it for flow dissector in BPF_PROG_TEST_RUN. No functional changes. Signed-off-by: Stanislav Fomichev --- include/linux/skbuff.h| 5 +++ net/core/flow_dissector.c | 85 +++ 2 files changed, 56 insertions(+), 34 deletions(-) diff

Re: [PATCH bpf-next 2/3] bpf: add BPF_PROG_TEST_RUN support for flow dissector

2018-12-03 Thread Stanislav Fomichev
On 12/03, Stanislav Fomichev wrote: > On 12/03, Song Liu wrote: > > On Mon, Dec 3, 2018 at 11:00 AM Stanislav Fomichev wrote: > > > > > > The input is packet data, the output is struct bpf_flow_key. This should > > > make it easy to test flow dissector pr

[PATCH bpf-next 3/3] selftests/bpf: add simple BPF_PROG_TEST_RUN examples for flow dissector

2018-12-03 Thread Stanislav Fomichev
Use existing pkt_v4 and pkt_v6 to make sure flow_keys are what we want. Also, add new bpf_flow_load routine (and flow_dissector_load.h header) that loads bpf_flow.o program and does all required setup. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/Makefile | 3

[PATCH bpf-next 1/3] net/flow_dissector: move bpf case into __skb_flow_bpf_dissect

2018-12-03 Thread Stanislav Fomichev
This way, we can reuse it for flow dissector in BPF_PROG_TEST_RUN. No functional changes. Signed-off-by: Stanislav Fomichev --- include/linux/skbuff.h| 5 +++ net/core/flow_dissector.c | 83 +++ 2 files changed, 54 insertions(+), 34 deletions(-) diff

[PATCH bpf-next 0/3] support flow dissector in BPF_PROG_TEST_RUN

2018-12-03 Thread Stanislav Fomichev
test_progs.c test to do a simple flow dissector run as well. * first patch introduces new __skb_flow_bpf_dissect to simplify sharing between __skb_flow_bpf_dissect and BPF_PROG_TEST_RUN * second patch adds actual BPF_PROG_TEST_RUN support * third patch adds example usage to the selftests Stanislav

[PATCH bpf-next 2/3] bpf: add BPF_PROG_TEST_RUN support for flow dissector

2018-12-03 Thread Stanislav Fomichev
The input is packet data, the output is struct bpf_flow_key. This should make it easy to test flow dissector programs without elaborate setup. Signed-off-by: Stanislav Fomichev --- include/linux/bpf.h | 3 ++ net/bpf/test_run.c | 76 + net/core

[PATCH bpf 1/2] selftests/bpf: use thoff instead of nhoff in BPF flow dissector

2018-12-05 Thread Stanislav Fomichev
much sense. Signed-off-by: Stanislav Fomichev --- net/core/flow_dissector.c | 1 + tools/testing/selftests/bpf/bpf_flow.c | 36 -- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index

[PATCH bpf 2/2] net/flow_dissector: correctly cap nhoff and thoff in case of BPF

2018-12-05 Thread Stanislav Fomichev
We want to make sure that the following condition holds: 0 <= nhoff <= thoff <= skb->len BPF program can set out-of-bounds nhoff and thoff, which is dangerous, see recent commit d0c081b49137 ("flow_dissector: properly cap thoff field")'. Signed-off-by: Stanislav F

[PATCH bpf] selftests/bpf: skip sockmap tests on kernels without support

2018-12-06 Thread Stanislav Fomichev
Include "autoconf.h" header in the test_maps.c and selectively disable test_sockmap if CONFIG_BPF_STREAM_PARSER is not specified in the kernel config. When building out of tree/without autoconf.h, fall back to 'enabled'. Signed-off-by: Stanislav Fomichev --- tools/testing/sel

[PATCH bpf] selftests/bpf: add missing pointer dereference for map stacktrace fixup

2018-12-06 Thread Stanislav Fomichev
I get a segfault without it, other fixups always do dereference, and without dereference I don't understand how it can ever work. Fixes: 7c85c448e7d74 ("selftests/bpf: test_verifier, check bpf_map_lookup_elem access in bpf prog") Signed-off-by: Stanislav Fomichev --- tools/testing

Re: [PATCH bpf-next v2 3/5] selftests/bpf: use thoff instead of nhoff in BPF flow dissector

2018-12-04 Thread Stanislav Fomichev
On 12/04, Song Liu wrote: > On Mon, Dec 3, 2018 at 8:01 PM Stanislav Fomichev wrote: > > > > We are returning thoff from the flow dissector, not the nhoff. Pass > > thoff along with nhoff to the bpf program (initially thoff == nhoff) > > and expect flow dissector am

Re: [PATCH bpf-next v2 4/5] net/flow_dissector: correctly cap nhoff and thoff in case of BPF

2018-12-04 Thread Stanislav Fomichev
On 12/04, Song Liu wrote: > On Mon, Dec 3, 2018 at 8:01 PM Stanislav Fomichev wrote: > > > > We want to make sure that the following condition holds: > > 0 <= nhoff <= thoff <= skb->len > > > > BPF program can set out-of-bounds nhoff and tho

Re: [PATCH bpf-next 2/3] bpf: add BPF_PROG_TEST_RUN support for flow dissector

2018-12-04 Thread Stanislav Fomichev
On 12/04, Song Liu wrote: > On Mon, Dec 3, 2018 at 3:08 PM Stanislav Fomichev wrote: > > > > On 12/03, Song Liu wrote: > > > On Mon, Dec 3, 2018 at 11:00 AM Stanislav Fomichev > > > wrote: > > > > > > > > The input is packet data, th

Re: [PATCH bpf-next 2/3] bpf: add BPF_PROG_TEST_RUN support for flow dissector

2018-12-03 Thread Stanislav Fomichev
On 12/03, Song Liu wrote: > On Mon, Dec 3, 2018 at 11:00 AM Stanislav Fomichev wrote: > > > > The input is packet data, the output is struct bpf_flow_key. This should > > make it easy to test flow dissector programs without elaborate > > setup. > > >

Re: [PATCH bpf-next v2 0/5] support flow dissector in BPF_PROG_TEST_RUN

2018-12-05 Thread Stanislav Fomichev
On 12/05, Song Liu wrote: > On Mon, Dec 3, 2018 at 8:01 PM Stanislav Fomichev wrote: > > > > This patch series adds support for testing flow dissector BPF programs by > > extending already existing BPF_PROG_TEST_RUN. The goal is to have a > > packet as an inp

[PATCH bpf-next v2 2/2] bpf: libbpf: move map name retry into libbpf.c

2018-11-20 Thread Stanislav Fomichev
To be in line with the previous commit ("bpf: libbpf: retry program creation without the name"), do the retry at the higher level, not the syscall level. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf.c| 11 +-- tools/lib/bpf/libbpf.c | 11 +++ 2 files c

[PATCH bpf-next v2 1/2] bpf: libbpf: retry program creation without the name

2018-11-20 Thread Stanislav Fomichev
;name for programs. Pre v4.14 kernels don't know about programs names and return an error about unexpected non-zero data. Retry bpf_load_program_xattr without a program name to cover older kernels. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 12 1 file changed, 12 in

Re: [PATCH bpf-next] bpf: libbpf: retry program creation without the name

2018-11-20 Thread Stanislav Fomichev
On 11/20, Alexei Starovoitov wrote: > On Mon, Nov 19, 2018 at 04:46:25PM -0800, Stanislav Fomichev wrote: > > [Recent commit 23499442c319 ("bpf: libbpf: retry map creation without > > the name") fixed this issue for maps, let's do the same for programs.] > > >

Re: [PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able

2018-11-20 Thread Stanislav Fomichev
On 11/20, Y Song wrote: > On Tue, Nov 20, 2018 at 10:19 AM Stanislav Fomichev wrote: > > > > Wrap headers in extern "C", to turn off C++ mangling. > > This simplifies including libbpf in c++ and linking against it. > > > > Signed-off-by: Stanislav Fomich

[PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able

2018-11-20 Thread Stanislav Fomichev
Wrap headers in extern "C", to turn off C++ mangling. This simplifies including libbpf in c++ and linking against it. v2 changes: * do the same for btf.h Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf.h| 9 + tools/lib/bpf/btf.h| 8 tools/lib/bpf/li

Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able

2018-11-20 Thread Stanislav Fomichev
On 11/20, Alexei Starovoitov wrote: > On Tue, Nov 20, 2018 at 04:05:55PM -0800, Stanislav Fomichev wrote: > > On 11/20, Alexei Starovoitov wrote: > > > On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote: > > > > Wrap headers in extern

Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able

2018-11-20 Thread Stanislav Fomichev
On 11/20, Alexei Starovoitov wrote: > On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote: > > Wrap headers in extern "C", to turn off C++ mangling. > > This simplifies including libbpf in c++ and linking against it. > > > > v2 changes: > &

[PATCH bpf-next v3 1/3] bpf, libbpf: introduce bpf_object__probe_caps to test BPF capabilities

2018-11-20 Thread Stanislav Fomichev
It currently only checks whether kernel supports map/prog names. This capability check will be used in the next two commits to skip setting prog/map names. Suggested-by: Daniel Borkmann Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 58

[PATCH bpf-next v3 3/3] bpf: libbpf: don't specify prog name if kernel doesn't support it

2018-11-20 Thread Stanislav Fomichev
Use recently added capability check. See commit 23499442c319 ("bpf: libbpf: retry map creation without the name") for rationale. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b

[PATCH bpf-next v3 2/3] bpf: libbpf: remove map name retry from bpf_create_map_xattr

2018-11-20 Thread Stanislav Fomichev
Instead, check for a newly created caps.name bpf_object capability. If kernel doesn't support names, don't specify the attribute. See commit 23499442c319 ("bpf: libbpf: retry map creation without the name") for rationale. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf

Re: [PATCH bpf-next] bpf: libbpf: retry program creation without the name

2018-11-20 Thread Stanislav Fomichev
On 11/20, Alexei Starovoitov wrote: > On Wed, Nov 21, 2018 at 12:18:57AM +0100, Daniel Borkmann wrote: > > On 11/21/2018 12:04 AM, Alexei Starovoitov wrote: > > > On Tue, Nov 20, 2018 at 01:19:05PM -0800, Stanislav Fomichev wrote: > > >> On 11/20, Alexei Starovoitov

[PATCH bpf-next] bpf: libbpf: retry program creation without the name

2018-11-19 Thread Stanislav Fomichev
;name for programs. Pre v4.14 kernels don't know about programs names and return an error about unexpected non-zero data. Retry sys_bpf without a program name to cover older kernels. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf.c | 10 ++ 1 file changed, 10 insertions(+) dif

[PATCH bpf-next] bpf: libbpf: retry map creation without the name

2018-11-19 Thread Stanislav Fomichev
o cover older kernels. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 03f9bcc4ef50..673175bc06ee 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -69,6

[PATCH bpf-next v2] bpf: libbpf: retry map creation without the name

2018-11-19 Thread Stanislav Fomichev
o cover older kernels. v2 changes: * check for errno == EINVAL as suggested by Daniel Borkmann Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 03f9bcc4ef50..961e1b

Re: [PATCH bpf-next v2] bpf: libbpf: retry map creation without the name

2018-11-19 Thread Stanislav Fomichev
On 11/20, Daniel Borkmann wrote: > On 11/19/2018 11:49 PM, Stanislav Fomichev wrote: > > Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support > > to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name > > for maps. Pre v4.14

Re: [PATCH bpf-next] bpf: libbpf: retry program creation without the name

2018-11-21 Thread Stanislav Fomichev
On 11/21, Quentin Monnet wrote: > 2018-11-20 15:26 UTC-0800 ~ Stanislav Fomichev > > On 11/20, Alexei Starovoitov wrote: > >> On Wed, Nov 21, 2018 at 12:18:57AM +0100, Daniel Borkmann wrote: > >>> On 11/21/2018 12:04 AM, Alexei Starovoitov wrote: > >>>

[PATCH bpf-next v3] libbpf: make sure bpf headers are c++ include-able

2018-11-21 Thread Stanislav Fomichev
Wrap headers in extern "C", to turn off C++ mangling. This simplifies including libbpf in c++ and linking against it. v2 changes: * do the same for btf.h v3 changes: * test_libbpf.cpp to test for possible future c++ breakages Signed-off-by: Stanislav Fomichev --- tools/lib/bp

[PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able

2018-11-20 Thread Stanislav Fomichev
Wrap headers in extern "C", to turn off C++ mangling. This simplifies including libbpf in c++ and linking against it. Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/bpf.h| 9 + tools/lib/bpf/libbpf.h | 9 + 2 files changed, 18 insertions(+) diff --git a/too