bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: Denis Salopek <denis.salopek@sartura.hr>,
	bpf <bpf@vger.kernel.org>,
	Juraj Vijtiuk <juraj.vijtiuk@sartura.hr>,
	Luka Oreskovic <luka.oreskovic@sartura.hr>,
	Luka Perkov <luka.perkov@sartura.hr>,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH v4 bpf-next] bpf: add lookup_and_delete_elem support to hashtab
Date: Mon, 5 Apr 2021 14:08:29 -0700	[thread overview]
Message-ID: <CAEf4BzYeLLQAQKNPorzi4pdMq7DxbDXZVPZ11p+-T8+RTV9myA@mail.gmail.com> (raw)
In-Reply-To: <ce69af50-3667-c52d-1f1a-b924bbe0fc58@fb.com>

On Sun, Apr 4, 2021 at 9:47 PM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 3/29/21 5:57 AM, Denis Salopek wrote:
> > Extend the existing bpf_map_lookup_and_delete_elem() functionality to
> > hashtab maps, in addition to stacks and queues.
> > Add bpf_map_lookup_and_delete_elem_flags() libbpf API in order to use
> > the BPF_F_LOCK flag.
> > Create a new hashtab bpf_map_ops function that does lookup and deletion
> > of the element under the same bucket lock and add the created map_ops to
> > bpf.h.
> > Add the appropriate test cases to 'maps' and 'lru_map' selftests
> > accompanied with new test_progs.
> >
> > Cc: Juraj Vijtiuk <juraj.vijtiuk@sartura.hr>
> > Cc: Luka Oreskovic <luka.oreskovic@sartura.hr>
> > Cc: Luka Perkov <luka.perkov@sartura.hr>
> > Signed-off-by: Denis Salopek <denis.salopek@sartura.hr>
> > ---
> > v2: Add functionality for LRU/per-CPU, add test_progs tests.
> > v3: Add bpf_map_lookup_and_delete_elem_flags() and enable BPF_F_LOCK
> > flag, change CHECKs to ASSERT_OKs, initialize variables to 0.
> > v4: Fix the return value for unsupported map types.
> > ---
> >   include/linux/bpf.h                           |   2 +
> >   kernel/bpf/hashtab.c                          |  97 ++++++
> >   kernel/bpf/syscall.c                          |  27 +-
> >   tools/lib/bpf/bpf.c                           |  13 +
> >   tools/lib/bpf/bpf.h                           |   2 +
> >   tools/lib/bpf/libbpf.map                      |   1 +
> >   .../bpf/prog_tests/lookup_and_delete.c        | 279 ++++++++++++++++++
> >   .../bpf/progs/test_lookup_and_delete.c        |  26 ++
> >   tools/testing/selftests/bpf/test_lru_map.c    |   8 +
> >   tools/testing/selftests/bpf/test_maps.c       |  19 +-
> >   10 files changed, 469 insertions(+), 5 deletions(-)
> >   create mode 100644 tools/testing/selftests/bpf/prog_tests/lookup_and_delete.c
> >   create mode 100644 tools/testing/selftests/bpf/progs/test_lookup_and_delete.c
>

[...]

> > +int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key, void *value, __u64 flags)
> > +{
> > +     union bpf_attr attr;
> > +
> > +     memset(&attr, 0, sizeof(attr));
> > +     attr.map_fd = fd;
> > +     attr.key = ptr_to_u64(key);
> > +     attr.value = ptr_to_u64(value);
> > +     attr.flags = flags;
> > +
> > +     return sys_bpf(BPF_MAP_LOOKUP_AND_DELETE_ELEM, &attr, sizeof(attr));
> > +}
>
> This looks okay to me. It mimics bpf_map_lookup_elem_flags().
> Andrii, could you take a look as well?

I think it's fine. Given bpf_map_lookup_elem_flags() didn't get
extended for so long means the API is pretty stable and is unlikely to
require the entire OPTS framework.

>
> > +
> >   int bpf_map_delete_elem(int fd, const void *key)
> >   {
> >       union bpf_attr attr;

[...]

  parent reply	other threads:[~2021-04-05 21:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 12:57 [PATCH v4 bpf-next] bpf: add lookup_and_delete_elem support to hashtab Denis Salopek
2021-04-05  4:47 ` Yonghong Song
2021-04-05  5:42   ` Yonghong Song
2021-04-05 21:08   ` Andrii Nakryiko [this message]
2021-04-12  6:47   ` Denis Salopek
2021-04-12 14:19     ` Yonghong Song

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=CAEf4BzYeLLQAQKNPorzi4pdMq7DxbDXZVPZ11p+-T8+RTV9myA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=denis.salopek@sartura.hr \
    --cc=juraj.vijtiuk@sartura.hr \
    --cc=luka.oreskovic@sartura.hr \
    --cc=luka.perkov@sartura.hr \
    --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;
as well as URLs for NNTP newsgroup(s).