public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Joanne Koong" <joannelkoong@gmail.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>
Subject: Re: [PATCH bpf-next v6 12/13] selftests/bpf: Add verifier tests for kptr
Date: Tue, 10 May 2022 01:33:44 +0530	[thread overview]
Message-ID: <20220509200344.bl7cpvh366fkfzrn@apollo.legion> (raw)
In-Reply-To: <20220426033544.lxxnz6epet6qrzq6@MBP-98dd607d3435.dhcp.thefacebook.com>

On Tue, Apr 26, 2022 at 09:05:44AM IST, Alexei Starovoitov wrote:
> On Mon, Apr 25, 2022 at 03:19:00AM +0530, Kumar Kartikeya Dwivedi wrote:
> > Reuse bpf_prog_test functions to test the support for PTR_TO_BTF_ID in
> > BPF map case, including some tests that verify implementation sanity and
> > corner cases.
> >
> > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> > ---
> >  net/bpf/test_run.c                            |  45 +-
> >  tools/testing/selftests/bpf/test_verifier.c   |  55 +-
> >  .../testing/selftests/bpf/verifier/map_kptr.c | 469 ++++++++++++++++++
> >  3 files changed, 562 insertions(+), 7 deletions(-)
> >  create mode 100644 tools/testing/selftests/bpf/verifier/map_kptr.c
> >
> > diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
> > index e7b9c2636d10..29fe32821e7e 100644
> > --- a/net/bpf/test_run.c
> > +++ b/net/bpf/test_run.c
> > @@ -584,6 +584,12 @@ noinline void bpf_kfunc_call_memb_release(struct prog_test_member *p)
> >  {
> >  }
> >
> > +noinline struct prog_test_ref_kfunc *
> > +bpf_kfunc_call_test_kptr_get(struct prog_test_ref_kfunc **p, int a, int b)
> > +{
> > +	return &prog_test_struct;
> > +}
> > +
> >  struct prog_test_pass1 {
> >  	int x0;
> >  	struct {
> > @@ -669,6 +675,7 @@ BTF_ID(func, bpf_kfunc_call_test3)
> >  BTF_ID(func, bpf_kfunc_call_test_acquire)
> >  BTF_ID(func, bpf_kfunc_call_test_release)
> >  BTF_ID(func, bpf_kfunc_call_memb_release)
> > +BTF_ID(func, bpf_kfunc_call_test_kptr_get)
> >  BTF_ID(func, bpf_kfunc_call_test_pass_ctx)
> >  BTF_ID(func, bpf_kfunc_call_test_pass1)
> >  BTF_ID(func, bpf_kfunc_call_test_pass2)
> > @@ -682,6 +689,7 @@ BTF_SET_END(test_sk_check_kfunc_ids)
> >
> >  BTF_SET_START(test_sk_acquire_kfunc_ids)
> >  BTF_ID(func, bpf_kfunc_call_test_acquire)
> > +BTF_ID(func, bpf_kfunc_call_test_kptr_get)
> >  BTF_SET_END(test_sk_acquire_kfunc_ids)
> >
> >  BTF_SET_START(test_sk_release_kfunc_ids)
> > @@ -691,8 +699,13 @@ BTF_SET_END(test_sk_release_kfunc_ids)
> >
> >  BTF_SET_START(test_sk_ret_null_kfunc_ids)
> >  BTF_ID(func, bpf_kfunc_call_test_acquire)
> > +BTF_ID(func, bpf_kfunc_call_test_kptr_get)
> >  BTF_SET_END(test_sk_ret_null_kfunc_ids)
> >
> > +BTF_SET_START(test_sk_kptr_acquire_kfunc_ids)
> > +BTF_ID(func, bpf_kfunc_call_test_kptr_get)
> > +BTF_SET_END(test_sk_kptr_acquire_kfunc_ids)
> > +
> >  static void *bpf_test_init(const union bpf_attr *kattr, u32 user_size,
> >  			   u32 size, u32 headroom, u32 tailroom)
> >  {
> > @@ -1579,14 +1592,36 @@ int bpf_prog_test_run_syscall(struct bpf_prog *prog,
> >
> >  static const struct btf_kfunc_id_set bpf_prog_test_kfunc_set = {
> >  	.owner        = THIS_MODULE,
> > -	.check_set    = &test_sk_check_kfunc_ids,
> > -	.acquire_set  = &test_sk_acquire_kfunc_ids,
> > -	.release_set  = &test_sk_release_kfunc_ids,
> > -	.ret_null_set = &test_sk_ret_null_kfunc_ids,
> > +	.check_set        = &test_sk_check_kfunc_ids,
> > +	.acquire_set      = &test_sk_acquire_kfunc_ids,
> > +	.release_set      = &test_sk_release_kfunc_ids,
> > +	.ret_null_set     = &test_sk_ret_null_kfunc_ids,
> > +	.kptr_acquire_set = &test_sk_kptr_acquire_kfunc_ids
> >  };
>
> This hunk probably should have been in the previous patch,
> but since it's not affecting bisect I left it as-is.
>
> > +BTF_ID_LIST(bpf_prog_test_dtor_kfunc_ids)
> > +BTF_ID(struct, prog_test_ref_kfunc)
> > +BTF_ID(func, bpf_kfunc_call_test_release)
> > +BTF_ID(struct, prog_test_member)
> > +BTF_ID(func, bpf_kfunc_call_memb_release)
>
> dtor of prog_test_member doesn't seem to be used ?
>

It is necessary to be able to embed prog_test_member struct as a referenced kptr
in a map value, so it is still called by the map implementation's free path. But
since this is just used for verifier tests related to type matching when
non-zero offset is involved, both acquire and release are dummy functions.

> Please improve dtor and kptr_get test methods for
> struct prog_test_ref_kfunc and prog_test_member to do the real refcnting.
> Empty methods are not testing things fully.

I will leave out prog_test_member since it is not meant to be used at runtime,
but I will add refcount_t to prog_test_ref_kfunc, and include tests for it.

--
Kartikeya

  reply	other threads:[~2022-05-09 20:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-24 21:48 [PATCH bpf-next v6 00/13] Introduce typed pointer support in BPF maps Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 01/13] bpf: Allow storing unreferenced kptr in map Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 02/13] bpf: Tag argument to be released in bpf_func_proto Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 03/13] bpf: Allow storing referenced kptr in map Kumar Kartikeya Dwivedi
2022-04-26  3:30   ` Alexei Starovoitov
2022-04-24 21:48 ` [PATCH bpf-next v6 04/13] bpf: Prevent escaping of kptr loaded from maps Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 05/13] bpf: Adapt copy_map_value for multiple offset case Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 06/13] bpf: Populate pairs of btf_id and destructor kfunc in btf Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 07/13] bpf: Wire up freeing of referenced kptr Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 08/13] bpf: Teach verifier about kptr_get kfunc helpers Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 09/13] bpf: Make BTF type match stricter for release arguments Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 10/13] libbpf: Add kptr type tag macros to bpf_helpers.h Kumar Kartikeya Dwivedi
2022-04-24 21:48 ` [PATCH bpf-next v6 11/13] selftests/bpf: Add C tests for kptr Kumar Kartikeya Dwivedi
2022-04-24 21:49 ` [PATCH bpf-next v6 12/13] selftests/bpf: Add verifier " Kumar Kartikeya Dwivedi
2022-04-26  3:35   ` Alexei Starovoitov
2022-05-09 20:03     ` Kumar Kartikeya Dwivedi [this message]
2022-04-24 21:49 ` [PATCH bpf-next v6 13/13] selftests/bpf: Add test for strict BTF type check Kumar Kartikeya Dwivedi
2022-04-26  3:39   ` Alexei Starovoitov
2022-05-08 21:59     ` Alexei Starovoitov
2022-05-09 19:49       ` Kumar Kartikeya Dwivedi
2022-04-26  3:30 ` [PATCH bpf-next v6 00/13] Introduce typed pointer support in BPF maps patchwork-bot+netdevbpf

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=20220509200344.bl7cpvh366fkfzrn@apollo.legion \
    --to=memxor@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=joannelkoong@gmail.com \
    --cc=toke@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox