[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

[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 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 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 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 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 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 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 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 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 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 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

[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 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 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 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

[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 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 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 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

[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 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 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

[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 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

[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

[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 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 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

[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