From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Mauricio Vasquez <mauricio.vasquez@polito.it>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Alexei Starovoitov <ast@kernel.org>,
netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/3] bpf: add bpf queue map
Date: Thu, 9 Aug 2018 09:23:30 -0700 [thread overview]
Message-ID: <20180809162328.rnyxihpiim2wz5dk@ast-mbp> (raw)
In-Reply-To: <867e95e1-cb45-54c8-ce66-d3e49161d5e6@polito.it>
On Thu, Aug 09, 2018 at 09:51:49AM -0500, Mauricio Vasquez wrote:
>
> > Agree that existing ops are not the right alias, but deferring to user
> > space as inline function also doesn't really seem like a good fit, imho,
> > so I'd prefer rather to have something native. (Aside from that, the
> > above inline bpf_pop() would also race between CPUs.)
>
> I think we should have push/pop/peek syscalls as well, having a bpf_pop()
> that is race prone would create problems. Users expected maps operations to
> be safe, so having one that is not will confuse them.
agree the races are not acceptable.
How about a mixed solution:
- introduce bpf_push/pop/peak helpers that programs will use, so
they don't need to pass useless key=NULL
- introduce map->ops->lookup_and_delete and map->ops->lookup_or_init
that prog-side helpers can use and syscall has 1-1 mapping for
Native lookup_or_init() helper for programs and syscall is badly missing.
Most of the bcc scripts use it and bcc has a racy workaround.
Similarly lookup_and_delete() syscall is 1-1 to pop() for stack/queue
and useful for regular hash maps.
At the end for stack/queue map the programs will use:
int bpf_push(map, value);
value_or_null = bpf_pop(map); // guaranteed non-racy for multi-cpu
value_or_null = bpf_peak(map); // racy if 2+ cpus doing it
from syscall:
bpf_map_lookup_elem(map, NULL, &value); // returns top of stack
bpf_map_lookup_and_delete_elem(map, NULL, &value); // returns top and deletes top atomically
bpf_map_update_elem(map, NULL, &value); // pushes new value into stack atomically
Eventually hash and other maps will implement bpf_map_lookup_and_delete()
for both bpf progs and syscall.
The main point that prog-side api doesn't have to match 1-1 to syscall-side,
since they're different enough already.
Like lookup_or_init() is badly needed for programs, but unnecessary for syscall.
Thoughts?
next prev parent reply other threads:[~2018-08-09 18:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-06 13:58 [PATCH bpf-next 0/3] Implement bpf map queue Mauricio Vasquez B
2018-08-06 13:58 ` [PATCH bpf-next 1/3] bpf: add bpf queue map Mauricio Vasquez B
2018-08-07 13:40 ` Daniel Borkmann
2018-08-09 2:50 ` Mauricio Vasquez
2018-08-07 13:52 ` Daniel Borkmann
2018-08-09 2:55 ` Mauricio Vasquez
2018-08-07 14:42 ` Alexei Starovoitov
2018-08-09 3:08 ` Mauricio Vasquez
2018-08-09 4:48 ` Alexei Starovoitov
2018-08-09 9:02 ` Daniel Borkmann
2018-08-09 14:51 ` Mauricio Vasquez
2018-08-09 16:23 ` Alexei Starovoitov [this message]
2018-08-09 23:41 ` Mauricio Vasquez
2018-08-10 3:09 ` Alexei Starovoitov
2018-08-06 13:58 ` [PATCH bpf-next 2/3] selftests/bpf: add test cases for BPF_MAP_TYPE_QUEUE Mauricio Vasquez B
2018-08-07 13:42 ` Daniel Borkmann
2018-08-06 13:58 ` [PATCH bpf-next 3/3] bpf: add sample " Mauricio Vasquez B
2018-08-07 13:44 ` Daniel Borkmann
2018-08-09 2:52 ` Mauricio Vasquez
2018-08-07 20:31 ` Jakub Kicinski
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=20180809162328.rnyxihpiim2wz5dk@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=mauricio.vasquez@polito.it \
--cc=netdev@vger.kernel.org \
/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