BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: John Fastabend <john.fastabend@gmail.com>
Cc: Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [bpf-next PATCH v5 4/5] bpf, selftests: add sk_msg helpers load and attach test
Date: Tue, 26 May 2020 11:07:35 -0700
Message-ID: <CAEf4BzbDnQKUqmD4VL_PHPGpA3WbUS3cr0jimNf7NhRcA4ZPpg@mail.gmail.com> (raw)
In-Reply-To: <159033909665.12355.6166415847337547879.stgit@john-Precision-5820-Tower>

On Sun, May 24, 2020 at 9:51 AM John Fastabend <john.fastabend@gmail.com> wrote:
>
> The test itself is not particularly useful but it encodes a common
> pattern we have.
>
> Namely do a sk storage lookup then depending on data here decide if
> we need to do more work or alternatively allow packet to PASS. Then
> if we need to do more work consult task_struct for more information
> about the running task. Finally based on this additional information
> drop or pass the data. In this case the suspicious check is not so
> realisitic but it encodes the general pattern and uses the helpers
> so we test the workflow.
>
> This is a load test to ensure verifier correctly handles this case.
>
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> ---

Other than perror and CHECK_FAIL nag below, looks good:

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  .../selftests/bpf/prog_tests/sockmap_basic.c       |   35 +++++++++++++++
>  .../selftests/bpf/progs/test_skmsg_load_helpers.c  |   47 ++++++++++++++++++++
>  2 files changed, 82 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/progs/test_skmsg_load_helpers.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> index aa43e0b..96e7b7f 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> @@ -1,7 +1,9 @@
>  // SPDX-License-Identifier: GPL-2.0
>  // Copyright (c) 2020 Cloudflare
> +#include <error.h>
>
>  #include "test_progs.h"
> +#include "test_skmsg_load_helpers.skel.h"
>
>  #define TCP_REPAIR             19      /* TCP sock is under repair right now */
>
> @@ -70,10 +72,43 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type)
>         close(s);
>  }
>
> +static void test_skmsg_helpers(enum bpf_map_type map_type)
> +{
> +       struct test_skmsg_load_helpers *skel;
> +       int err, map, verdict;
> +
> +       skel = test_skmsg_load_helpers__open_and_load();
> +       if (CHECK_FAIL(!skel)) {
> +               perror("test_skmsg_load_helpers__open_and_load");

All test_progs tests use CHECK() macro to test and emit error message
on error, so no need to do silent CHECK_FAIL() and then perror(). Same
below in few places. I don't think you need to send v6 just for this,
but please follow up with a clean up.

> +               return;
> +       }
> +
> +       verdict = bpf_program__fd(skel->progs.prog_msg_verdict);
> +       map = bpf_map__fd(skel->maps.sock_map);
> +
> +       err = bpf_prog_attach(verdict, map, BPF_SK_MSG_VERDICT, 0);
> +       if (CHECK_FAIL(err)) {
> +               perror("bpf_prog_attach");
> +               goto out;
> +       }
> +
> +       err = bpf_prog_detach2(verdict, map, BPF_SK_MSG_VERDICT);
> +       if (CHECK_FAIL(err)) {
> +               perror("bpf_prog_detach2");
> +               goto out;
> +       }
> +out:
> +       test_skmsg_load_helpers__destroy(skel);
> +}
> +

[...]

  reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-24 16:50 [bpf-next PATCH v5 0/5] bpf: Add sk_msg and networking helpers John Fastabend
2020-05-24 16:50 ` [bpf-next PATCH v5 1/5] bpf, sk_msg: add some generic helpers that may be useful from sk_msg John Fastabend
2020-05-25 21:51   ` Daniel Borkmann
2020-05-25 22:57     ` John Fastabend
2020-05-26 18:33       ` Andrii Nakryiko
2020-05-26 20:51         ` John Fastabend
2020-05-26 21:29           ` Andrii Nakryiko
2020-05-26 23:12             ` Daniel Borkmann
2020-05-24 16:50 ` [bpf-next PATCH v5 2/5] bpf: extend bpf_base_func_proto helpers with probe_* and *current_task* John Fastabend
2020-05-25 21:52   ` Daniel Borkmann
2020-05-25 22:58     ` John Fastabend
2020-05-24 16:51 ` [bpf-next PATCH v5 3/5] bpf, sk_msg: add get socket storage helpers John Fastabend
2020-05-24 16:51 ` [bpf-next PATCH v5 4/5] bpf, selftests: add sk_msg helpers load and attach test John Fastabend
2020-05-26 18:07   ` Andrii Nakryiko [this message]
2020-05-24 16:51 ` [bpf-next PATCH v5 5/5] bpf, selftests: test probe_* helpers from SCHED_CLS John Fastabend
2020-05-26 18:09   ` 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=CAEf4BzbDnQKUqmD4VL_PHPGpA3WbUS3cr0jimNf7NhRcA4ZPpg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.com \
    /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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git