Re: [PATCH net-next v4 2/2] bpf: remove struct bpf_map_type_list

2017-04-11 Thread David Miller
From: Johannes Berg 
Date: Tue, 11 Apr 2017 15:34:58 +0200

> From: Johannes Berg 
> 
> There's no need to have struct bpf_map_type_list since
> it just contains a list_head, the type, and the ops
> pointer. Since the types are densely packed and not
> actually dynamically registered, it's much easier and
> smaller to have an array of type->ops pointer. Also
> initialize this array statically to remove code needed
> to initialize it.
> 
> In order to save duplicating the list, move it to the
> types header file added by the previous patch and
> include it in the same fashion.
> 
> Signed-off-by: Johannes Berg 

Applied.


Re: [PATCH net-next v4 2/2] bpf: remove struct bpf_map_type_list

2017-04-11 Thread Daniel Borkmann

On 04/11/2017 04:43 PM, Alexei Starovoitov wrote:

On Tue, Apr 11, 2017 at 03:34:58PM +0200, Johannes Berg wrote:

From: Johannes Berg 

There's no need to have struct bpf_map_type_list since
it just contains a list_head, the type, and the ops
pointer. Since the types are densely packed and not
actually dynamically registered, it's much easier and
smaller to have an array of type->ops pointer. Also
initialize this array statically to remove code needed
to initialize it.

In order to save duplicating the list, move it to the
types header file added by the previous patch and
include it in the same fashion.

Signed-off-by: Johannes Berg 
---
v4: add ifdef on CONFIG_PERF_EVENTS for stack_map_ops


I'm ok if you keep my ack after minor changes like this.
Acked-by: Alexei Starovoitov 


Me as well, thanks:

Acked-by: Daniel Borkmann 


Re: [PATCH net-next v4 2/2] bpf: remove struct bpf_map_type_list

2017-04-11 Thread Alexei Starovoitov
On Tue, Apr 11, 2017 at 03:34:58PM +0200, Johannes Berg wrote:
> From: Johannes Berg 
> 
> There's no need to have struct bpf_map_type_list since
> it just contains a list_head, the type, and the ops
> pointer. Since the types are densely packed and not
> actually dynamically registered, it's much easier and
> smaller to have an array of type->ops pointer. Also
> initialize this array statically to remove code needed
> to initialize it.
> 
> In order to save duplicating the list, move it to the
> types header file added by the previous patch and
> include it in the same fashion.
> 
> Signed-off-by: Johannes Berg 
> ---
> v4: add ifdef on CONFIG_PERF_EVENTS for stack_map_ops

I'm ok if you keep my ack after minor changes like this.
Acked-by: Alexei Starovoitov 

saves me typing another email and spamming everyone once more..



[PATCH net-next v4 2/2] bpf: remove struct bpf_map_type_list

2017-04-11 Thread Johannes Berg
From: Johannes Berg 

There's no need to have struct bpf_map_type_list since
it just contains a list_head, the type, and the ops
pointer. Since the types are densely packed and not
actually dynamically registered, it's much easier and
smaller to have an array of type->ops pointer. Also
initialize this array statically to remove code needed
to initialize it.

In order to save duplicating the list, move it to the
types header file added by the previous patch and
include it in the same fashion.

Signed-off-by: Johannes Berg 
---
v4: add ifdef on CONFIG_PERF_EVENTS for stack_map_ops
---
 include/linux/bpf.h   | 11 ++-
 include/linux/bpf_types.h | 18 +++
 kernel/bpf/arraymap.c | 78 ---
 kernel/bpf/hashtab.c  | 46 +++-
 kernel/bpf/lpm_trie.c | 14 +
 kernel/bpf/stackmap.c | 14 +
 kernel/bpf/syscall.c  | 37 +++---
 7 files changed, 53 insertions(+), 165 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 07fc02bb38e4..6bb38d76faf4 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -53,12 +53,6 @@ struct bpf_map {
struct bpf_map *inner_map_meta;
 };
 
-struct bpf_map_type_list {
-   struct list_head list_node;
-   const struct bpf_map_ops *ops;
-   enum bpf_map_type type;
-};
-
 /* function argument constraints */
 enum bpf_arg_type {
ARG_DONTCARE = 0,   /* unused argument in helper function */
@@ -239,10 +233,11 @@ DECLARE_PER_CPU(int, bpf_prog_active);
 
 #define BPF_PROG_TYPE(_id, _ops) \
extern const struct bpf_verifier_ops _ops;
+#define BPF_MAP_TYPE(_id, _ops) \
+   extern const struct bpf_map_ops _ops;
 #include 
 #undef BPF_PROG_TYPE
-
-void bpf_register_map_type(struct bpf_map_type_list *tl);
+#undef BPF_MAP_TYPE
 
 struct bpf_prog *bpf_prog_get(u32 ufd);
 struct bpf_prog *bpf_prog_get_type(u32 ufd, enum bpf_prog_type type);
diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h
index 68b0a9811216..03bf223f18be 100644
--- a/include/linux/bpf_types.h
+++ b/include/linux/bpf_types.h
@@ -16,3 +16,21 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_KPROBE, kprobe_prog_ops)
 BPF_PROG_TYPE(BPF_PROG_TYPE_TRACEPOINT, tracepoint_prog_ops)
 BPF_PROG_TYPE(BPF_PROG_TYPE_PERF_EVENT, perf_event_prog_ops)
 #endif
+
+BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_ARRAY, percpu_array_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_PROG_ARRAY, prog_array_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_PERF_EVENT_ARRAY, perf_event_array_map_ops)
+#ifdef CONFIG_CGROUPS
+BPF_MAP_TYPE(BPF_MAP_TYPE_CGROUP_ARRAY, cgroup_array_map_ops)
+#endif
+BPF_MAP_TYPE(BPF_MAP_TYPE_HASH, htab_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_HASH, htab_percpu_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_LRU_HASH, htab_lru_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_LRU_PERCPU_HASH, htab_lru_percpu_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_LPM_TRIE, trie_map_ops)
+#ifdef CONFIG_PERF_EVENTS
+BPF_MAP_TYPE(BPF_MAP_TYPE_STACK_TRACE, stack_map_ops)
+#endif
+BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY_OF_MAPS, array_of_maps_map_ops)
+BPF_MAP_TYPE(BPF_MAP_TYPE_HASH_OF_MAPS, htab_of_maps_map_ops)
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index bc9da93db403..ec621df5a97a 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -287,7 +287,7 @@ static void array_map_free(struct bpf_map *map)
bpf_map_area_free(array);
 }
 
-static const struct bpf_map_ops array_ops = {
+const struct bpf_map_ops array_map_ops = {
.map_alloc = array_map_alloc,
.map_free = array_map_free,
.map_get_next_key = array_map_get_next_key,
@@ -297,12 +297,7 @@ static const struct bpf_map_ops array_ops = {
.map_gen_lookup = array_map_gen_lookup,
 };
 
-static struct bpf_map_type_list array_type __ro_after_init = {
-   .ops = _ops,
-   .type = BPF_MAP_TYPE_ARRAY,
-};
-
-static const struct bpf_map_ops percpu_array_ops = {
+const struct bpf_map_ops percpu_array_map_ops = {
.map_alloc = array_map_alloc,
.map_free = array_map_free,
.map_get_next_key = array_map_get_next_key,
@@ -311,19 +306,6 @@ static const struct bpf_map_ops percpu_array_ops = {
.map_delete_elem = array_map_delete_elem,
 };
 
-static struct bpf_map_type_list percpu_array_type __ro_after_init = {
-   .ops = _array_ops,
-   .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-};
-
-static int __init register_array_map(void)
-{
-   bpf_register_map_type(_type);
-   bpf_register_map_type(_array_type);
-   return 0;
-}
-late_initcall(register_array_map);
-
 static struct bpf_map *fd_array_map_alloc(union bpf_attr *attr)
 {
/* only file descriptors can be stored in this type of map */
@@ -427,7 +409,7 @@ void bpf_fd_array_map_clear(struct bpf_map *map)
fd_array_map_delete_elem(map, );
 }
 
-static const struct bpf_map_ops prog_array_ops = {
+const struct bpf_map_ops