From: Denis Salopek <denis.salopek@sartura.hr>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, juraj.vijtiuk@sartura.hr,
luka.oreskovic@sartura.hr, luka.perkov@sartura.hr, yhs@fb.com
Subject: Re: [PATCH v3 bpf-next] bpf: add lookup_and_delete_elem support to hashtab
Date: Mon, 22 Mar 2021 19:40:45 +0100 [thread overview]
Message-ID: <YFjkrU4H3t1hVPgz@gmail.com> (raw)
In-Reply-To: <2f5f29ed-354b-b88d-f5cb-535d61aaaf0e@iogearbox.net>
On Fri, Mar 19, 2021 at 09:35:59PM +0100, Daniel Borkmann wrote:
> On 3/16/21 6:44 PM, Denis Salopek wrote:
> [...]
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index c859bc46d06c..36f65b589b82 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -1463,7 +1463,7 @@ int generic_map_lookup_batch(struct bpf_map *map,
> > return err;
> > }
> > -#define BPF_MAP_LOOKUP_AND_DELETE_ELEM_LAST_FIELD value
> > +#define BPF_MAP_LOOKUP_AND_DELETE_ELEM_LAST_FIELD flags
> > static int map_lookup_and_delete_elem(union bpf_attr *attr)
> > {
> > @@ -1479,6 +1479,9 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr)
> > if (CHECK_ATTR(BPF_MAP_LOOKUP_AND_DELETE_ELEM))
> > return -EINVAL;
> > + if (attr->flags & ~BPF_F_LOCK)
> > + return -EINVAL;
> > +
> > f = fdget(ufd);
> > map = __bpf_map_get(f);
> > if (IS_ERR(map))
> > @@ -1489,13 +1492,19 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr)
> > goto err_put;
> > }
> > + if ((attr->flags & BPF_F_LOCK) &&
> > + !map_value_has_spin_lock(map)) {
> > + err = -EINVAL;
> > + goto err_put;
> > + }
> > +
> > key = __bpf_copy_key(ukey, map->key_size);
> > if (IS_ERR(key)) {
> > err = PTR_ERR(key);
> > goto err_put;
> > }
> > - value_size = map->value_size;
> > + value_size = bpf_map_value_size(map);
> > err = -ENOMEM;
> > value = kmalloc(value_size, GFP_USER | __GFP_NOWARN);
> > @@ -1505,6 +1514,17 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr)
> > if (map->map_type == BPF_MAP_TYPE_QUEUE ||
> > map->map_type == BPF_MAP_TYPE_STACK) {
> > err = map->ops->map_pop_elem(map, value);
> > + } else if (map->map_type == BPF_MAP_TYPE_HASH ||
> > + map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
> > + map->map_type == BPF_MAP_TYPE_LRU_HASH ||
> > + map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH) {
> > + if (!bpf_map_is_dev_bound(map)) {
>
> I think you probably rather meant to fold the above !bpf_map_is_dev_bound(map)
> condition into the higher level 'else if', right? Otherwise for dev bound maps
> you'll always end up with -ENOMEM error rather than -ENOTSUPP.
>
Yes, you're right, thank you. How about setting the err to -ENOTSUPP
before the 'if' and just drop the else altogether?
> > + bpf_disable_instrumentation();
> > + rcu_read_lock();
> > + err = map->ops->map_lookup_and_delete_elem(map, key, value, attr->flags);
> > + rcu_read_unlock();
> > + bpf_enable_instrumentation();
> > + }
> > } else {
> > err = -ENOTSUPP;
> > }
prev parent reply other threads:[~2021-03-22 18:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 17:44 [PATCH v3 bpf-next] bpf: add lookup_and_delete_elem support to hashtab Denis Salopek
2021-03-19 20:35 ` Daniel Borkmann
2021-03-22 18:40 ` Denis Salopek [this message]
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=YFjkrU4H3t1hVPgz@gmail.com \
--to=denis.salopek@sartura.hr \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--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).