BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <aspsk@isovalent.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v4 bpf-next 6/6] selftests/bpf: check that ->elem_count is non-zero for the hash map
Date: Thu, 6 Jul 2023 17:43:42 +0000	[thread overview]
Message-ID: <ZKb9TjHX3GV35Yol@zh-lab-node-5> (raw)
In-Reply-To: <CAADnVQJ4-j6bD9vicVi245cRMWijbW=jQhK5ioczBC-7FCi06A@mail.gmail.com>

On Thu, Jul 06, 2023 at 10:03:30AM -0700, Alexei Starovoitov wrote:
> On Wed, Jul 5, 2023 at 10:42 PM Anton Protopopov <aspsk@isovalent.com> wrote:
> >
> > On Wed, Jul 05, 2023 at 06:26:25PM -0700, Alexei Starovoitov wrote:
> > > On Wed, Jul 5, 2023 at 9:00 AM Anton Protopopov <aspsk@isovalent.com> wrote:
> > > >
> > > > Previous commits populated the ->elem_count per-cpu pointer for hash maps.
> > > > Check that this pointer is non-NULL in an existing map.
> > > >
> > > > Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> > > > ---
> > > >  tools/testing/selftests/bpf/progs/map_ptr_kern.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> > > > index db388f593d0a..d6e234a37ccb 100644
> > > > --- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> > > > +++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> > > > @@ -33,6 +33,7 @@ struct bpf_map {
> > > >         __u32 value_size;
> > > >         __u32 max_entries;
> > > >         __u32 id;
> > > > +       __s64 *elem_count;
> > > >  } __attribute__((preserve_access_index));
> > > >
> > > >  static inline int check_bpf_map_fields(struct bpf_map *map, __u32 key_size,
> > > > @@ -111,6 +112,8 @@ static inline int check_hash(void)
> > > >
> > > >         VERIFY(check_default_noinline(&hash->map, map));
> > > >
> > > > +       VERIFY(map->elem_count != NULL);
> > > > +
> > >
> > > imo that's worse than no test.
> > > Just use kfunc here and get the real count?
> >
> > Then, as I mentioned in the previous version, I will have to teach kfuncs to
> > recognize const_ptr_to_map args just for the sake of this selftest, while we
> > already testing all functionality in the new selftest for test_maps. So I would
> > just omit this one. Or am I missing something?
> 
> 
> Don't you want to do:
>  val = bpf_map_lookup_elem(map, ...);
>  cnt = bpf_map_sum_elem_count(map);
> 
> and that's the main use case ?

Not sure I understand what this ^ use case is...

Our primary use case is to [periodically] get the number of elements from the
user space. We can do this using an iterator as you've suggested and what is
tested in the added selftest.

> So teaching the verifier to understand that const_ptr_to_map matches
> BTF 'struct bpf_map *' is essential ?

  reply	other threads:[~2023-07-06 17:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 16:01 [PATCH v4 bpf-next 0/6] bpf: add percpu stats for bpf_map Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 1/6] bpf: add percpu stats for bpf_map elements insertions/deletions Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 2/6] bpf: add a new kfunc to return current bpf_map elements count Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 3/6] bpf: populate the per-cpu insertions/deletions counters for hashmaps Anton Protopopov
2023-07-06  1:24   ` Alexei Starovoitov
2023-07-06  5:47     ` Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 4/6] bpf: make preloaded map iterators to display map elements count Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 5/6] selftests/bpf: test map percpu stats Anton Protopopov
2023-07-06 10:49   ` Hou Tao
2023-07-06 11:54     ` Anton Protopopov
2023-07-06 12:21       ` Hou Tao
2023-07-06 12:57         ` Anton Protopopov
2023-07-07  1:41           ` Hou Tao
2023-07-07  7:28             ` Anton Protopopov
2023-07-07  9:40               ` Hou Tao
2023-07-07 11:06                 ` Anton Protopopov
2023-07-05 16:01 ` [PATCH v4 bpf-next 6/6] selftests/bpf: check that ->elem_count is non-zero for the hash map Anton Protopopov
2023-07-06  1:26   ` Alexei Starovoitov
2023-07-06  5:44     ` Anton Protopopov
2023-07-06 17:03       ` Alexei Starovoitov
2023-07-06 17:43         ` Anton Protopopov [this message]
2023-07-06 17:48           ` Alexei Starovoitov
2023-07-06 18:35             ` Anton Protopopov
2023-07-06 20:33               ` Alexei Starovoitov

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=ZKb9TjHX3GV35Yol@zh-lab-node-5 \
    --to=aspsk@isovalent.com \
    --cc=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=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@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
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