OSDN Git Service

bpf: pass struct btf pointer to the map_check_btf() callback
authorRoman Gushchin <guroan@gmail.com>
Mon, 10 Dec 2018 23:43:00 +0000 (15:43 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 12 Dec 2018 23:33:33 +0000 (15:33 -0800)
If key_type or value_type are of non-trivial data types
(e.g. structure or typedef), it's not possible to check them without
the additional information, which can't be obtained without a pointer
to the btf structure.

So, let's pass btf pointer to the map_check_btf() callbacks.

Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/arraymap.c
kernel/bpf/lpm_trie.c
kernel/bpf/syscall.c

index 0c992b8..e734f16 100644 (file)
@@ -23,6 +23,7 @@ struct bpf_prog;
 struct bpf_map;
 struct sock;
 struct seq_file;
+struct btf;
 struct btf_type;
 
 /* map is generic key/value storage optionally accesible by eBPF programs */
@@ -52,6 +53,7 @@ struct bpf_map_ops {
        void (*map_seq_show_elem)(struct bpf_map *map, void *key,
                                  struct seq_file *m);
        int (*map_check_btf)(const struct bpf_map *map,
+                            const struct btf *btf,
                             const struct btf_type *key_type,
                             const struct btf_type *value_type);
 };
@@ -126,6 +128,7 @@ static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
 }
 
 int map_check_no_btf(const struct bpf_map *map,
+                    const struct btf *btf,
                     const struct btf_type *key_type,
                     const struct btf_type *value_type);
 
index 24583da..25632a7 100644 (file)
@@ -382,6 +382,7 @@ static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key,
 }
 
 static int array_map_check_btf(const struct bpf_map *map,
+                              const struct btf *btf,
                               const struct btf_type *key_type,
                               const struct btf_type *value_type)
 {
index bfd4882..abf1002 100644 (file)
@@ -728,6 +728,7 @@ free_stack:
 }
 
 static int trie_check_btf(const struct bpf_map *map,
+                         const struct btf *btf,
                          const struct btf_type *key_type,
                          const struct btf_type *value_type)
 {
index 5745c78..70fb111 100644 (file)
@@ -456,6 +456,7 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
 }
 
 int map_check_no_btf(const struct bpf_map *map,
+                    const struct btf *btf,
                     const struct btf_type *key_type,
                     const struct btf_type *value_type)
 {
@@ -478,7 +479,7 @@ static int map_check_btf(const struct bpf_map *map, const struct btf *btf,
                return -EINVAL;
 
        if (map->ops->map_check_btf)
-               ret = map->ops->map_check_btf(map, key_type, value_type);
+               ret = map->ops->map_check_btf(map, btf, key_type, value_type);
 
        return ret;
 }