From: Daniel Borkmann <dborkman@redhat.com>
To: Alexei Starovoitov <ast@plumgrid.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Ingo Molnar <mingo@kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
Hannes Frederic Sowa <hannes@stressinduktion.org>,
Eric Dumazet <edumazet@google.com>,
linux-api@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 3/7] bpf: add array type of eBPF maps
Date: Tue, 04 Nov 2014 10:58:33 +0100 [thread overview]
Message-ID: <5458A349.5020401@redhat.com> (raw)
In-Reply-To: <1415069656-14138-4-git-send-email-ast@plumgrid.com>
On 11/04/2014 03:54 AM, Alexei Starovoitov wrote:
> add new map type BPF_MAP_TYPE_ARRAY and its implementation
>
> - optimized for fastest possible lookup()
> . in the future verifier/JIT may recognize lookup() with constant key
> and optimize it into constant pointer. Can optimize non-constant
> key into direct pointer arithmetic as well, since pointers and
> value_size are constant for the life of the eBPF program.
> In other words array_map_lookup_elem() may be 'inlined' by verifier/JIT
> while preserving concurrent access to this map from user space
>
> - two main use cases for array type:
> . 'global' eBPF variables: array of 1 element with key=0 and value is a
> collection of 'global' variables which programs can use to keep the state
> between events
> . aggregation of tracing events into fixed set of buckets
>
> - all array elements pre-allocated and zero initialized at init time
>
> - key as an index in array and can only be 4 byte
>
> - map_delete_elem() returns EINVAL, since elements cannot be deleted
>
> - map_update_elem() replaces elements in an non-atomic way
> (for atomic updates hashtable type should be used instead)
>
> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
...
> +/* Called from syscall or from eBPF program */
> +static int array_map_update_elem(struct bpf_map *map, void *key, void *value,
> + u64 map_flags)
> +{
> + struct bpf_array *array = container_of(map, struct bpf_array, map);
> + u32 index = *(u32 *)key;
> +
> + if (map_flags > BPF_MAP_UPDATE_ONLY)
> + /* unknown flags */
> + return -EINVAL;
> +
> + if (map_flags == BPF_MAP_CREATE_ONLY)
> + return -EINVAL;
> +
> + if (index >= array->map.max_entries)
> + /* all elements were pre-allocated, cannot insert a new one */
> + return -E2BIG;
> +
> + memcpy(array->value + array->elem_size * index, value, array->elem_size);
What would protect this from concurrent updates?
> + return 0;
> +}
next prev parent reply other threads:[~2014-11-04 9:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-04 2:54 [PATCH net-next 0/7] implementation of eBPF maps Alexei Starovoitov
2014-11-04 2:54 ` Alexei Starovoitov
2014-11-04 2:54 ` [PATCH net-next 2/7] bpf: add hashtable type " Alexei Starovoitov
2014-11-04 2:54 ` [PATCH net-next 4/7] bpf: fix BPF_MAP_LOOKUP_ELEM command return code Alexei Starovoitov
[not found] ` <1415069656-14138-1-git-send-email-ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2014-11-04 2:54 ` [PATCH net-next 1/7] bpf: add 'flags' attribute to BPF_MAP_UPDATE_ELEM command Alexei Starovoitov
2014-11-04 2:54 ` Alexei Starovoitov
2014-11-04 9:25 ` Daniel Borkmann
[not found] ` <54589B89.5000309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-11-04 23:04 ` Alexei Starovoitov
2014-11-04 23:04 ` Alexei Starovoitov
2014-11-05 14:57 ` Daniel Borkmann
2014-11-06 17:39 ` Alexei Starovoitov
2014-11-04 2:54 ` [PATCH net-next 3/7] bpf: add array type of eBPF maps Alexei Starovoitov
2014-11-04 2:54 ` Alexei Starovoitov
2014-11-04 9:58 ` Daniel Borkmann [this message]
2014-11-04 23:14 ` Alexei Starovoitov
2014-11-04 2:54 ` [PATCH net-next 5/7] bpf: add a testsuite for " Alexei Starovoitov
2014-11-04 2:54 ` Alexei Starovoitov
2014-11-04 2:54 ` [PATCH net-next 6/7] bpf: allow eBPF programs to use maps Alexei Starovoitov
2014-11-04 2:54 ` Alexei Starovoitov
[not found] ` <1415069656-14138-7-git-send-email-ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2014-11-04 9:50 ` Daniel Borkmann
2014-11-04 9:50 ` Daniel Borkmann
2014-11-04 23:08 ` Alexei Starovoitov
2014-11-04 2:54 ` [PATCH net-next 7/7] bpf: remove test map scaffolding and use proper types Alexei Starovoitov
2014-11-04 2:54 ` 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=5458A349.5020401@redhat.com \
--to=dborkman@redhat.com \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hannes@stressinduktion.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.