All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: David Vernet <void@manifault.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
	yhs@meta.com, john.fastabend@gmail.com, kpsingh@kernel.org,
	sdf@google.com, haoluo@google.com, jolsa@kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com,
	tj@kernel.org
Subject: Re: [PATCH bpf-next 5/8] selftests/bpf: Add nested trust selftests suite
Date: Thu, 19 Jan 2023 21:51:49 -0800	[thread overview]
Message-ID: <20230120055149.tfpv3yzbbsm6snqv@MacBook-Pro-6.local.dhcp.thefacebook.com> (raw)
In-Reply-To: <20230119235833.2948341-6-void@manifault.com>

On Thu, Jan 19, 2023 at 05:58:30PM -0600, David Vernet wrote:
> Now that defining trusted fields in a struct is supported, we should add
> selftests to verify the behavior. This patch adds a few such testcases.
> 
> Signed-off-by: David Vernet <void@manifault.com>
> ---
>  tools/testing/selftests/bpf/DENYLIST.s390x    |  1 +
>  .../selftests/bpf/prog_tests/nested_trust.c   | 64 +++++++++++++++++++
>  .../selftests/bpf/progs/nested_trust_common.h | 12 ++++
>  .../bpf/progs/nested_trust_failure.c          | 33 ++++++++++
>  .../bpf/progs/nested_trust_success.c          | 29 +++++++++
>  5 files changed, 139 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/nested_trust.c
>  create mode 100644 tools/testing/selftests/bpf/progs/nested_trust_common.h
>  create mode 100644 tools/testing/selftests/bpf/progs/nested_trust_failure.c
>  create mode 100644 tools/testing/selftests/bpf/progs/nested_trust_success.c
> 
> diff --git a/tools/testing/selftests/bpf/DENYLIST.s390x b/tools/testing/selftests/bpf/DENYLIST.s390x
> index 96e8371f5c2a..1cf5b94cda30 100644
> --- a/tools/testing/selftests/bpf/DENYLIST.s390x
> +++ b/tools/testing/selftests/bpf/DENYLIST.s390x
> @@ -44,6 +44,7 @@ map_kptr                                 # failed to open_and_load program: -524
>  modify_return                            # modify_return attach failed: -524                                           (trampoline)
>  module_attach                            # skel_attach skeleton attach failed: -524                                    (trampoline)
>  mptcp
> +nested_trust                             # JIT does not support calling kernel function
>  netcnt                                   # failed to load BPF skeleton 'netcnt_prog': -7                               (?)
>  probe_user                               # check_kprobe_res wrong kprobe res from probe read                           (?)
>  rcu_read_lock                            # failed to find kernel BTF type ID of '__x64_sys_getpgid': -3                (?)
> diff --git a/tools/testing/selftests/bpf/prog_tests/nested_trust.c b/tools/testing/selftests/bpf/prog_tests/nested_trust.c
> new file mode 100644
> index 000000000000..4d13612f5001
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/nested_trust.c
> @@ -0,0 +1,64 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
> +
> +#include <test_progs.h>
> +#include "nested_trust_failure.skel.h"
> +#include "nested_trust_success.skel.h"
> +
> +static const char * const nested_trust_success_testcases[] = {
> +	"test_read_cpumask",
> +};
> +
> +static void verify_success(const char *prog_name)
> +{
> +	struct nested_trust_success *skel;
> +	struct bpf_program *prog;
> +	struct bpf_link *link = NULL;
> +	int status;
> +	pid_t child_pid;
> +
> +	skel = nested_trust_success__open();
> +	if (!ASSERT_OK_PTR(skel, "nested_trust_success__open"))
> +		return;
> +
> +	skel->bss->pid = getpid();
> +
> +	nested_trust_success__load(skel);
> +	if (!ASSERT_OK_PTR(skel, "nested_trust_success__load"))
> +		goto cleanup;
> +
> +	prog = bpf_object__find_program_by_name(skel->obj, prog_name);
> +	if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
> +		goto cleanup;
> +
> +	link = bpf_program__attach(prog);
> +	if (!ASSERT_OK_PTR(link, "bpf_program__attach"))
> +		goto cleanup;
> +
> +	child_pid = fork();
> +	if (!ASSERT_GT(child_pid, -1, "child_pid"))
> +		goto cleanup;
> +	if (child_pid == 0)
> +		_exit(0);
> +	waitpid(child_pid, &status, 0);
> +	ASSERT_OK(skel->bss->err, "post_wait_err");
> +
> +	bpf_link__destroy(link);
> +
> +cleanup:
> +	nested_trust_success__destroy(skel);
> +}
> +
> +void test_nested_trust(void)
> +{
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(nested_trust_success_testcases); i++) {
> +		if (!test__start_subtest(nested_trust_success_testcases[i]))
> +			continue;
> +
> +		verify_success(nested_trust_success_testcases[i]);
> +	}
> +
> +	RUN_TESTS(nested_trust_failure);
> +}

Hmm. I thought RUN_TESTS() works for successes too.
Looking at test_loader.c:run_subtest() that should be the case.
Could you please double check?
verify_success() above shouldn't be needed.

  reply	other threads:[~2023-01-20  5:52 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19 23:58 [PATCH bpf-next 0/8] Enable cpumasks to be used as kptrs David Vernet
2023-01-19 23:58 ` [PATCH bpf-next 1/8] bpf: Enable annotating trusted nested pointers David Vernet
2023-01-20  1:14   ` kernel test robot
2023-01-20  2:27     ` David Vernet
2023-01-20  6:01   ` kernel test robot
2023-01-19 23:58 ` [PATCH bpf-next 2/8] bpf: Allow trusted args to walk struct when checking BTF IDs David Vernet
2023-01-20  4:58   ` Kumar Kartikeya Dwivedi
2023-01-20  5:23     ` David Vernet
2023-01-20  5:40       ` Alexei Starovoitov
2023-01-20  5:56         ` Kumar Kartikeya Dwivedi
2023-01-20  6:14           ` Alexei Starovoitov
2023-01-20 14:56             ` David Vernet
2023-01-20 15:26               ` David Vernet
2023-01-20 16:17                 ` Alexei Starovoitov
2023-01-19 23:58 ` [PATCH bpf-next 3/8] bpf: Disallow NULL PTR_TO_MEM for trusted kfuncs David Vernet
2023-01-20  5:21   ` Kumar Kartikeya Dwivedi
2023-01-20  5:31     ` David Vernet
2023-01-20  5:44       ` Alexei Starovoitov
2023-01-19 23:58 ` [PATCH bpf-next 4/8] bpf: Enable cpumasks to be queried and used as kptrs David Vernet
2023-01-20  2:36   ` kernel test robot
2023-01-20  3:39     ` David Vernet
2023-01-20  5:48   ` Alexei Starovoitov
2023-01-20  5:50     ` David Vernet
2023-01-20  5:52       ` Alexei Starovoitov
2023-01-20  6:22   ` kernel test robot
2023-01-19 23:58 ` [PATCH bpf-next 5/8] selftests/bpf: Add nested trust selftests suite David Vernet
2023-01-20  5:51   ` Alexei Starovoitov [this message]
2023-01-20  5:56     ` David Vernet
2023-01-19 23:58 ` [PATCH bpf-next 6/8] selftests/bpf: Add selftest suite for cpumask kfuncs David Vernet
2023-01-19 23:58 ` [PATCH bpf-next 7/8] bpf/docs: Document cpumask kfuncs in a new file David Vernet
2023-01-20  5:59   ` Alexei Starovoitov
2023-01-20  6:01     ` David Vernet
2023-01-19 23:58 ` [PATCH bpf-next 8/8] bpf/docs: Document how nested trusted fields may be defined David Vernet

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=20230120055149.tfpv3yzbbsm6snqv@MacBook-Pro-6.local.dhcp.thefacebook.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    --cc=yhs@meta.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
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.