Re: [PATCH bpf] bpf: hash_map: decrement counter on error

2018-07-01 Thread Mauricio Vasquez
On 06/30/2018 06:20 PM, Daniel Borkmann wrote: On 06/29/2018 02:48 PM, Mauricio Vasquez B wrote: Decrement the number of elements in the map in case the allocation of a new node fails. Signed-off-by: Mauricio Vasquez B Thanks for the fix, Mauricio! Could you reply with a Fixes: tag

Re: [PATCH bpf-next 1/3] bpf: add bpf queue map

2018-08-08 Thread Mauricio Vasquez
On 08/07/2018 08:40 AM, Daniel Borkmann wrote: On 08/06/2018 03:58 PM, Mauricio Vasquez B wrote: Bpf queue implements a LIFO/FIFO data containers for ebpf programs. It allows to push an element to the queue by using the update operation and to pop an element from the queue by using

Re: [PATCH bpf-next 3/3] bpf: add sample for BPF_MAP_TYPE_QUEUE

2018-08-08 Thread Mauricio Vasquez
On 08/07/2018 08:44 AM, Daniel Borkmann wrote: On 08/06/2018 03:58 PM, Mauricio Vasquez B wrote: The example is made by two parts, a eBPF program that consumes elements from a FIFO queue and prints them in the screen and a user space application that inserts new elements into the queue each

Re: [PATCH bpf-next 1/3] bpf: add bpf queue map

2018-08-08 Thread Mauricio Vasquez
On 08/07/2018 09:42 AM, Alexei Starovoitov wrote: On Mon, Aug 06, 2018 at 03:58:30PM +0200, Mauricio Vasquez B wrote: Bpf queue implements a LIFO/FIFO data containers for ebpf programs. queue/stack datastructure would be a great addition. It allows to push an element to the queue by using

Re: [PATCH bpf-next 1/3] bpf: add bpf queue map

2018-08-08 Thread Mauricio Vasquez
On 08/07/2018 08:52 AM, Daniel Borkmann wrote: On 08/06/2018 03:58 PM, Mauricio Vasquez B wrote: Bpf queue implements a LIFO/FIFO data containers for ebpf programs. It allows to push an element to the queue by using the update operation and to pop an element from the queue by using

Re: [PATCH bpf-next 1/3] bpf: add bpf queue map

2018-08-09 Thread Mauricio Vasquez
On 08/09/2018 04:02 AM, Daniel Borkmann wrote: On 08/09/2018 06:48 AM, Alexei Starovoitov wrote: On Wed, Aug 08, 2018 at 10:08:47PM -0500, Mauricio Vasquez wrote: And how about adding three new helpers: push/pop/peek as well? Reusing lookup/update is neat, but does lookup == pop or does

Re: [PATCH bpf-next 1/3] bpf: add bpf queue map

2018-08-09 Thread Mauricio Vasquez
On 08/09/2018 11:23 AM, Alexei Starovoitov wrote: 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

Re: [RFC PATCH bpf-next v2 0/4] Implement bpf queue/stack maps

2018-09-07 Thread Mauricio Vasquez
On 09/06/2018 07:13 PM, Alexei Starovoitov wrote: On Fri, Aug 31, 2018 at 11:25:48PM +0200, Mauricio Vasquez B wrote: In some applications this is needed have a pool of free elements, like for example the list of free L4 ports in a SNAT. None of the current maps allow to do

Re: [RFC PATCH bpf-next v2 0/4] Implement bpf queue/stack maps

2018-09-11 Thread Mauricio Vasquez
On 09/10/2018 08:04 PM, Alexei Starovoitov wrote: On Fri, Sep 7, 2018 at 1:40 PM, Mauricio Vasquez wrote: I read the Joe's proposal and using that for this problem looks like a nice solution. I think a good trade-off for now would be to go ahead with a queue/stack map without preallocating

Re: [RFC PATCH bpf-next v4 4/7] bpf: add bpf queue and stack maps

2018-10-07 Thread Mauricio Vasquez
On 10/04/2018 10:40 PM, Mauricio Vasquez wrote: On 10/04/2018 06:57 PM, Alexei Starovoitov wrote: On Thu, Oct 04, 2018 at 07:12:44PM +0200, Mauricio Vasquez B wrote: Implement two new kind of maps that support the peek, push and pop operations. A use case for this is to keep track

Re: [PATCH bpf-next v3 7/7] selftests/bpf: add test cases for queue and stack maps

2018-10-18 Thread Mauricio Vasquez
On 10/18/18 11:36 AM, Song Liu wrote: On Thu, Oct 18, 2018 at 6:16 AM Mauricio Vasquez B wrote: test_maps: Tests that queue/stack maps are behaving correctly even in corner cases test_progs: Tests new ebpf helpers Signed-off-by: Mauricio Vasquez B --- tools/lib/bpf/bpf.c

Re: [PATCH bpf-next v2 3/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-16 Thread Mauricio Vasquez
On 10/11/2018 06:51 PM, Alexei Starovoitov wrote: On Wed, Oct 10, 2018 at 05:50:01PM -0500, Mauricio Vasquez wrote: Does it make sense to you? I reread the other patch, and found it does NOT use the following logic for queue and stack: rcu_read_lock(); ptr

Re: [PATCH bpf-next v2 3/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-16 Thread Mauricio Vasquez
On 10/16/2018 06:20 PM, Alexei Starovoitov wrote: On Tue, Oct 16, 2018 at 04:16:39PM -0500, Mauricio Vasquez wrote: On 10/11/2018 06:51 PM, Alexei Starovoitov wrote: On Wed, Oct 10, 2018 at 05:50:01PM -0500, Mauricio Vasquez wrote: Does it make sense to you? I reread the other patch

Re: [PATCH bpf 6/7] bpf: fix leaking uninitialized memory on pop/peek helpers

2018-10-24 Thread Mauricio Vasquez
lets wipe it there on error case, that is, empty stack/queue. Fixes: f1a2e44a3aec ("bpf: add queue and stack maps") Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Cc: Mauricio Vasquez B Thanks for the fix Daniel. Acked-by: Mauricio Vasquez B

Re: [PATCH bpf 5/7] bpf: fix direct packet write into pop/peek helpers

2018-10-24 Thread Mauricio Vasquez
e, disable .pkt_access for the two. Fixes: f1a2e44a3aec ("bpf: add queue and stack maps") Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Cc: Mauricio Vasquez B Thanks for this as well. Acked-by: Mauricio Vasquez B

Re: [RFC PATCH bpf-next v3 4/7] bpf: add bpf queue and stack maps

2018-10-03 Thread Mauricio Vasquez
On 10/01/2018 07:26 PM, Alexei Starovoitov wrote: On Mon, Oct 01, 2018 at 08:11:43AM -0500, Mauricio Vasquez wrote: +BPF_CALL_3(bpf_map_pop_elem, struct bpf_map *, map, void *, value, u32, size) +{ +    void *ptr; + +    if (map->value_size != size) +    return -EINVAL; + +    ptr =

Re: [PATCH bpf-next 1/6] bpf: rename stack trace map operations

2018-10-09 Thread Mauricio Vasquez
things a bit because lookup nor lookup_and_delete have a flag argument. I am asking because mixing stack with stack trace is still confusing after this patch. Thanks, Song On Mon, Oct 8, 2018 at 12:11 PM Mauricio Vasquez B wrote: In the following patches queue and stack maps (FIFO and LIFO

Re: [PATCH bpf-next 3/6] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-09 Thread Mauricio Vasquez
On 10/08/2018 08:13 PM, Song Liu wrote: On Mon, Oct 8, 2018 at 12:12 PM Mauricio Vasquez B wrote: The following patch implements a bpf queue/stack maps that provides the peek/pop/push functions. There is not a direct relationship between those functions and the current maps syscalls, hence

Re: [PATCH bpf-next 4/6] bpf: add queue and stack maps

2018-10-09 Thread Mauricio Vasquez
On 10/08/2018 08:36 PM, Song Liu wrote: On Mon, Oct 8, 2018 at 12:12 PM Mauricio Vasquez B wrote: Queue/stack maps implement a FIFO/LIFO data storage for ebpf programs. These maps support peek, pop and push operations that are exposed to eBPF programs through the new bpf_map[peek/pop/push

Re: [PATCH bpf-next v2 3/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-10 Thread Mauricio Vasquez
On 10/10/2018 11:48 AM, Song Liu wrote: On Wed, Oct 10, 2018 at 7:06 AM Mauricio Vasquez B wrote: The following patch implements a bpf queue/stack maps that provides the peek/pop/push functions. There is not a direct relationship between those functions and the current maps syscalls, hence

Re: [PATCH bpf-next v2 3/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-10 Thread Mauricio Vasquez
On 10/10/2018 05:34 PM, Song Liu wrote: On Wed, Oct 10, 2018 at 10:48 AM Mauricio Vasquez wrote: On 10/10/2018 11:48 AM, Song Liu wrote: On Wed, Oct 10, 2018 at 7:06 AM Mauricio Vasquez B wrote: The following patch implements a bpf queue/stack maps that provides the peek/pop/push

Re: [RFC bpf-next 2/4] bpf: return EOPNOTSUPP when map lookup isn't supported

2018-09-19 Thread Mauricio Vasquez
On 09/19/2018 10:14 AM, Alexei Starovoitov wrote: On Wed, Sep 19, 2018 at 04:51:41PM +0900, Prashant Bhole wrote: Return ERR_PTR(-EOPNOTSUPP) from map_lookup_elem() methods of below map types: - BPF_MAP_TYPE_PROG_ARRAY - BPF_MAP_TYPE_STACK_TRACE - BPF_MAP_TYPE_XSKMAP -

Re: [PATCH bpf 2/2] bpf: test_verifier, test for lookup on queue/stack maps

2018-11-28 Thread Mauricio Vasquez
On 11/28/18 3:45 AM, Daniel Borkmann wrote: On 11/28/2018 08:51 AM, Prashant Bhole wrote: This patch adds tests to check whether bpf verifier prevents lookup on queue/stack maps Signed-off-by: Prashant Bhole --- tools/testing/selftests/bpf/test_verifier.c | 52 + 1

Re: [RFC PATCH bpf-next v3 4/7] bpf: add bpf queue and stack maps

2018-09-18 Thread Mauricio Vasquez
On 09/18/2018 06:27 PM, Alexei Starovoitov wrote: On Tue, Sep 18, 2018 at 06:52:51AM +0200, Mauricio Vasquez B wrote: Implement two new kind of maps that support the peek, push and pop operations. A use case for this is to keep track of a pool of elements, like network ports in a SNAT

Re: [RFC PATCH bpf-next v3 7/7] selftests/bpf: add test cases for queue and stack maps

2018-09-18 Thread Mauricio Vasquez
On 09/18/2018 06:32 PM, Alexei Starovoitov wrote: On Tue, Sep 18, 2018 at 06:53:07AM +0200, Mauricio Vasquez B wrote: Two types of tests are done: - test_maps: only userspace api. - test_progs: userspace api and ebpf helpers. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/helpers.c

Re: [RFC PATCH bpf-next v3 1/7] bpf: rename stack trace map

2018-09-18 Thread Mauricio Vasquez
On 09/18/2018 06:05 PM, Alexei Starovoitov wrote: On Tue, Sep 18, 2018 at 06:52:34AM +0200, Mauricio Vasquez B wrote: In the following patches queue and stack maps (FIFO and LIFO datastructures) will be implemented. In order to avoid confusion and a possible name clash rename stackmap.c

[PATCH bpf-next 1/3] bpf: add bpf queue map

2018-08-06 Thread Mauricio Vasquez B
. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf_types.h |1 include/uapi/linux/bpf.h |5 + kernel/bpf/Makefile |2 kernel/bpf/queuemap.c | 287 + kernel/bpf/syscall.c | 61 +++--- kernel/bpf/verifier.c

[PATCH bpf-next 3/3] bpf: add sample for BPF_MAP_TYPE_QUEUE

2018-08-06 Thread Mauricio Vasquez B
The example is made by two parts, a eBPF program that consumes elements from a FIFO queue and prints them in the screen and a user space application that inserts new elements into the queue each time this is executed. Signed-off-by: Mauricio Vasquez B --- samples/bpf/.gitignore

[PATCH bpf-next 2/3] selftests/bpf: add test cases for BPF_MAP_TYPE_QUEUE

2018-08-06 Thread Mauricio Vasquez B
Signed-off-by: Mauricio Vasquez B --- tools/include/uapi/linux/bpf.h |5 ++ tools/testing/selftests/bpf/test_maps.c | 72 +++ 2 files changed, 77 insertions(+) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index

[PATCH bpf-next 0/3] Implement bpf map queue

2018-08-06 Thread Mauricio Vasquez B
Bpf queue map is a new kind of map that provides a LIFO/FIFO queue implementation. In some applications, like a SNAT, it is necessary to keep track of a pool of free elemenets, network ports in this case, then a queue can be used for that purpose. Signed-off-by: Mauricio Vasquez B --- Mauricio

[RFC PATCH bpf-next v2 1/4] bpf: add bpf queue and stack maps

2018-08-31 Thread Mauricio Vasquez B
Implement two new kind of maps that support the peek, push and pop operations. A use case for this is to keep track of a pool of elements, like network ports in a SNAT. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |8 + include/linux/bpf_types.h |2 include

[RFC PATCH bpf-next v2 2/4] bpf: restrict use of peek/push/pop

2018-08-31 Thread Mauricio Vasquez B
Restrict the use of peek, push and pop helpers only to queue and stack maps. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/verifier.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 5bd67feb2f07..9e177ff4a3b9 100644

[RFC PATCH bpf-next v2 0/4] Implement bpf queue/stack maps

2018-08-31 Thread Mauricio Vasquez B
maps: queue and stack. Those maps provide to eBPF programs the peek, push and pop operations, and for userspace applications a new bpf_map_lookup_and_delete_elem() is added. Signed-off-by: Mauricio Vasquez B --- I am sending this as an RFC because there is still an issue I am not sure how to solve

[RFC PATCH bpf-next v2 3/4] Sync uapi/bpf.h to tools/include

2018-08-31 Thread Mauricio Vasquez B
Sync both files. Signed-off-by: Mauricio Vasquez B --- tools/include/uapi/linux/bpf.h | 36 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 66917a4eba27..0a5b904ba42f

[RFC PATCH bpf-next v2 4/4] selftests/bpf: add test cases for queue and stack maps

2018-08-31 Thread Mauricio Vasquez B
Two types of tests are done: - test_maps: only userspace api. - test_progs: userspace api and ebpf helpers. Signed-off-by: Mauricio Vasquez B --- tools/lib/bpf/bpf.c| 12 ++ tools/lib/bpf/bpf.h|1 tools/testing/selftests/bpf

[PATCH bpf] bpf: hash_map: decrement counter on error

2018-06-29 Thread Mauricio Vasquez B
Decrement the number of elements in the map in case the allocation of a new node fails. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/hashtab.c | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 3ca2198

[PATCH bpf-next v3 1/7] bpf: rename stack trace map operations

2018-10-18 Thread Mauricio Vasquez B
In the following patches queue and stack maps (FIFO and LIFO datastructures) will be implemented. In order to avoid confusion and a possible name clash rename stack_map_ops to stack_trace_map_ops Signed-off-by: Mauricio Vasquez B Acked-by: Song Liu --- include/linux/bpf_types.h |2

[PATCH bpf-next v3 5/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-18 Thread Mauricio Vasquez B
/stack maps and it is still to implement in other kind of maps. Signed-off-by: Mauricio Vasquez B --- include/uapi/linux/bpf.h |1 + kernel/bpf/syscall.c | 66 ++ 2 files changed, 67 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include

[PATCH bpf-next v3 6/7] Sync uapi/bpf.h to tools/include

2018-10-18 Thread Mauricio Vasquez B
Sync both files. Signed-off-by: Mauricio Vasquez B Acked-by: Song Liu --- tools/include/uapi/linux/bpf.h | 30 +- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index f9187b41dff6

[PATCH bpf-next v3 0/7] Implement queue/stack maps

2018-10-18 Thread Mauricio Vasquez B
. Signed-off-by: Mauricio Vasquez B v2 -> v3: - Remove "almost dead code" in syscall.c - Remove unnecessary copy_from_user in bpf_map_lookup_and_delete_elem - Rebase v1 -> v2: - Put ARG_PTR_TO_UNINIT_MAP_VALUE logic into a separated patch - Fix missing __this_cpu_dec &

[PATCH bpf-next v3 3/7] bpf/verifier: add ARG_PTR_TO_UNINIT_MAP_VALUE

2018-10-18 Thread Mauricio Vasquez B
to be filled with a map value. Signed-off-by: Mauricio Vasquez B Acked-by: Song Liu --- include/linux/bpf.h |1 + kernel/bpf/verifier.c |9 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index e60fff48288b..0f8b863e0229

[PATCH bpf-next v3 2/7] bpf/syscall: allow key to be null in map functions

2018-10-18 Thread Mauricio Vasquez B
This commit adds the required logic to allow key being NULL in case the key_size of the map is 0. A new __bpf_copy_key function helper only copies the key from userpsace when key_size != 0, otherwise it enforces that key must be null. Signed-off-by: Mauricio Vasquez B Acked-by: Song Liu

[PATCH bpf-next v3 7/7] selftests/bpf: add test cases for queue and stack maps

2018-10-18 Thread Mauricio Vasquez B
test_maps: Tests that queue/stack maps are behaving correctly even in corner cases test_progs: Tests new ebpf helpers Signed-off-by: Mauricio Vasquez B --- tools/lib/bpf/bpf.c| 12 ++ tools/lib/bpf/bpf.h|2 tools/testing

[PATCH bpf-next v3 4/7] bpf: add queue and stack maps

2018-10-18 Thread Mauricio Vasquez B
otivation for implementing queue/stack maps was to keep track of a pool of elements, like network ports in a SNAT, however we forsee other use cases, like for exampling saving last N kernel events in a map and then analysing from userspace. Signed-off-by: Mauricio Vasquez B --- include/li

[RFC PATCH bpf-next v4 6/7] Sync uapi/bpf.h to tools/include

2018-10-04 Thread Mauricio Vasquez B
Sync both files. Signed-off-by: Mauricio Vasquez B --- tools/include/uapi/linux/bpf.h | 36 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index f9187b41dff6..bfa042273fad

[RFC PATCH bpf-next v4 3/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-04 Thread Mauricio Vasquez B
/stack maps and it is still to implement in other kind of maps. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |1 + include/uapi/linux/bpf.h |1 + kernel/bpf/syscall.c | 82 ++ 3 files changed, 84 insertions(+) diff --git

[RFC PATCH bpf-next v4 4/7] bpf: add bpf queue and stack maps

2018-10-04 Thread Mauricio Vasquez B
Implement two new kind of maps that support the peek, push and pop operations. A use case for this is to keep track of a pool of elements, like network ports in a SNAT. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |7 + include/linux/bpf_types.h |2 include

[RFC PATCH bpf-next v4 5/7] bpf: restrict use of peek/push/pop

2018-10-04 Thread Mauricio Vasquez B
Restrict the use of peek, push and pop helpers only to queue and stack maps. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/verifier.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 489667f93061..8b1f1b348782 100644

[RFC PATCH bpf-next v4 2/7] bpf/syscall: allow key to be null in map functions

2018-10-04 Thread Mauricio Vasquez B
This commit adds the required logic to allow key being NULL in case the key_size of the map is 0. A new __bpf_copy_key function helper only copies the key from userpsace when key_size != 0, otherwise it enforces that key must be null. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/syscall.c

[RFC PATCH bpf-next v4 7/7] selftests/bpf: add test cases for queue and stack maps

2018-10-04 Thread Mauricio Vasquez B
Two types of tests are done: - test_maps: only userspace api. - test_progs: userspace api and ebpf helpers. Signed-off-by: Mauricio Vasquez B --- tools/lib/bpf/bpf.c| 12 ++ tools/lib/bpf/bpf.h|1 tools/testing/selftests/bpf

[RFC PATCH bpf-next v4 1/7] bpf: rename stack trace map operations

2018-10-04 Thread Mauricio Vasquez B
In the following patches queue and stack maps (FIFO and LIFO datastructures) will be implemented. In order to avoid confusion and a possible name clash rename stack_map_ops to stack_trace_map_ops Signed-off-by: Mauricio Vasquez B --- include/linux/bpf_types.h |2 +- kernel/bpf/stackmap.c

[RFC PATCH bpf-next v4 0/7] Implement bpf queue/stack maps

2018-10-04 Thread Mauricio Vasquez B
: queue and stack. Those maps provide to eBPF programs the peek, push and pop operations, and for userspace applications a new bpf_map_lookup_and_delete_elem() is added. Signed-off-by: Mauricio Vasquez B v3 -> v4: - Revert renaming of kernel/bpf/stackmap.c - Remove restriction on value s

[PATCH bpf-next v2 7/7] selftests/bpf: add test cases for queue and stack maps

2018-10-10 Thread Mauricio Vasquez B
test_maps: Tests that queue/stack maps are behaving correctly even in corner cases test_progs: Tests new ebpf helpers Signed-off-by: Mauricio Vasquez B --- tools/lib/bpf/bpf.c| 12 ++ tools/lib/bpf/bpf.h|1 tools/testing

[PATCH bpf-next v2 6/7] Sync uapi/bpf.h to tools/include

2018-10-10 Thread Mauricio Vasquez B
Sync both files. Signed-off-by: Mauricio Vasquez B --- tools/include/uapi/linux/bpf.h | 30 +- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index f9187b41dff6..c8824d5364ff 100644

[PATCH bpf-next v2 5/7] bpf: add queue and stack maps

2018-10-10 Thread Mauricio Vasquez B
otivation for implementing queue/stack maps was to keep track of a pool of elements, like network ports in a SNAT, however we forsee other use cases, like for exampling saving last N kernel events in a map and then analysing from userspace. Signed-off-by: Mauricio Vasquez B --- include/li

[PATCH bpf-next v2 2/7] bpf/syscall: allow key to be null in map functions

2018-10-10 Thread Mauricio Vasquez B
This commit adds the required logic to allow key being NULL in case the key_size of the map is 0. A new __bpf_copy_key function helper only copies the key from userpsace when key_size != 0, otherwise it enforces that key must be null. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/syscall.c

[PATCH bpf-next v2 3/7] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-10 Thread Mauricio Vasquez B
/stack maps and it is still to implement in other kind of maps. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |1 + include/uapi/linux/bpf.h |1 + kernel/bpf/syscall.c | 82 ++ 3 files changed, 84 insertions(+) diff --git

[PATCH bpf-next v2 4/7] bpf/verifier: add ARG_PTR_TO_UNINIT_MAP_VALUE

2018-10-10 Thread Mauricio Vasquez B
to be filled with a map value. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |1 + kernel/bpf/verifier.c |9 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 5793f0c7fbb5..e37b4986bb45 100644

[PATCH bpf-next v2 1/7] bpf: rename stack trace map operations

2018-10-10 Thread Mauricio Vasquez B
In the following patches queue and stack maps (FIFO and LIFO datastructures) will be implemented. In order to avoid confusion and a possible name clash rename stack_map_ops to stack_trace_map_ops Signed-off-by: Mauricio Vasquez B --- include/linux/bpf_types.h |2 +- kernel/bpf/stackmap.c

[PATCH bpf-next v2 0/7] Implement queue/stack maps

2018-10-10 Thread Mauricio Vasquez B
. Signed-off-by: Mauricio Vasquez B v1 -> v2: - Put ARG_PTR_TO_UNINIT_MAP_VALUE logic into a separated patch - Fix missing __this_cpu_dec & preempt_enable calls in kernel/bpf/syscall.c RFC v4 -> v1: - Remove roundup to power of 2 in memory allocation - Remove count and use a free slo

[PATCH bpf-next 4/6] bpf: add queue and stack maps

2018-10-08 Thread Mauricio Vasquez B
otivation for implementing queue/stack maps was to keep track of a pool of elements, like network ports in a SNAT, however we forsee other use cases, like for exampling saving last N kernel events in a map and then analysing from userspace. Signed-off-by: Mauricio Vasquez B --- include/li

[PATCH bpf-next 2/6] bpf/syscall: allow key to be null in map functions

2018-10-08 Thread Mauricio Vasquez B
This commit adds the required logic to allow key being NULL in case the key_size of the map is 0. A new __bpf_copy_key function helper only copies the key from userpsace when key_size != 0, otherwise it enforces that key must be null. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/syscall.c

[PATCH bpf-next 3/6] bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall

2018-10-08 Thread Mauricio Vasquez B
/stack maps and it is still to implement in other kind of maps. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |1 + include/uapi/linux/bpf.h |1 + kernel/bpf/syscall.c | 81 ++ 3 files changed, 83 insertions(+) diff --git

[PATCH bpf-next 5/6] Sync uapi/bpf.h to tools/include

2018-10-08 Thread Mauricio Vasquez B
Sync both files. Signed-off-by: Mauricio Vasquez B --- tools/include/uapi/linux/bpf.h | 36 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index f9187b41dff6..bfa042273fad

[PATCH bpf-next 0/6] Implement queue/stack maps

2018-10-08 Thread Mauricio Vasquez B
. Signed-off-by: Mauricio Vasquez B RFC v4 -> v1: - Remove roundup to power of 2 in memory allocation - Remove count and use a free slot to check if queue/stack is empty - Use if + assigment for wrapping indexes - Fix some minor style issues - Squash two patches together RFC v3 ->

[PATCH bpf-next 1/6] bpf: rename stack trace map operations

2018-10-08 Thread Mauricio Vasquez B
In the following patches queue and stack maps (FIFO and LIFO datastructures) will be implemented. In order to avoid confusion and a possible name clash rename stack_map_ops to stack_trace_map_ops Signed-off-by: Mauricio Vasquez B --- include/linux/bpf_types.h |2 +- kernel/bpf/stackmap.c

[PATCH bpf-next 6/6] selftests/bpf: add test cases for queue and stack maps

2018-10-08 Thread Mauricio Vasquez B
test_maps: Tests that queue/stack maps are behaving correctly even in corner cases test_progs: Tests new ebpf helpers Signed-off-by: Mauricio Vasquez B --- tools/lib/bpf/bpf.c| 12 ++ tools/lib/bpf/bpf.h|1 tools/testing

[RFC PATCH bpf-next v3 1/7] bpf: rename stack trace map

2018-09-17 Thread Mauricio Vasquez B
In the following patches queue and stack maps (FIFO and LIFO datastructures) will be implemented. In order to avoid confusion and a possible name clash rename stackmap.c to stacktracemap.c and stack_map_ops to stack_trace_map_ops Signed-off-by: Mauricio Vasquez B --- include/linux/bpf_types.h

[RFC PATCH bpf-next v3 2/7] bpf/syscall: allow key to be null in map functions

2018-09-17 Thread Mauricio Vasquez B
This commit adds the required logic to allow key being NULL in case the key_size of the map is 0. A new __bpf_copy_key function helper only copies the key from userpsace when key_size != 0, otherwise it enforces that key must be null. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/syscall.c

[RFC PATCH bpf-next v3 3/7] bpf: add lookup_and_delete map operation

2018-09-17 Thread Mauricio Vasquez B
helper. A pop operation is not added because it will too specific to stack/queue maps, instead this new operation could be useful for other maps as well. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |1 + include/uapi/linux/bpf.h |1 + kernel/bpf/syscall.c | 82

[RFC PATCH bpf-next v3 5/7] bpf: restrict use of peek/push/pop

2018-09-17 Thread Mauricio Vasquez B
Restrict the use of peek, push and pop helpers only to queue and stack maps. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/verifier.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index b9e005188f0e..1628ffe48e32 100644

[RFC PATCH bpf-next v3 4/7] bpf: add bpf queue and stack maps

2018-09-17 Thread Mauricio Vasquez B
Implement two new kind of maps that support the peek, push and pop operations. A use case for this is to keep track of a pool of elements, like network ports in a SNAT. Signed-off-by: Mauricio Vasquez B --- include/linux/bpf.h |3 include/linux/bpf_types.h |2 include

[RFC PATCH bpf-next v3 6/7] Sync uapi/bpf.h to tools/include

2018-09-17 Thread Mauricio Vasquez B
Sync both files. Signed-off-by: Mauricio Vasquez B --- tools/include/uapi/linux/bpf.h | 31 ++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 66917a4eba27..c899386dcb2b 100644

[RFC PATCH bpf-next v3 7/7] selftests/bpf: add test cases for queue and stack maps

2018-09-17 Thread Mauricio Vasquez B
Two types of tests are done: - test_maps: only userspace api. - test_progs: userspace api and ebpf helpers. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/helpers.c |2 tools/lib/bpf/bpf.c| 12 ++ tools/lib/bpf/bpf.h

[RFC PATCH bpf-next v3 0/7] Implement bpf queue/stack maps

2018-09-17 Thread Mauricio Vasquez B
maps: queue and stack. Those maps provide to eBPF programs the peek, push and pop operations, and for userspace applications a new bpf_map_lookup_and_delete_elem() is added. Signed-off-by: Mauricio Vasquez B v2 -> v3: - Return elements by value instead that by reference - Implement queue/st