diff mbox series

[v3,bpf-next,3/8] bpf: Remember BTF of inner maps.

Message ID 20210624022518.57875-4-alexei.starovoitov@gmail.com
State Superseded
Headers show
Series [v3,bpf-next,1/8] bpf: Introduce bpf timers. | expand

Commit Message

Alexei Starovoitov June 24, 2021, 2:25 a.m. UTC
From: Alexei Starovoitov <ast@kernel.org>

BTF is required for 'struct bpf_timer' to be recognized inside map value.
The bpf timers are supported inside inner maps.
Remember 'struct btf *' in inner_map_meta to make it available
to the verifier in the sequence:

struct bpf_map *inner_map = bpf_map_lookup_elem(&outer_map, ...);
if (inner_map)
    timer = bpf_map_lookup_elem(&inner_map, ...);

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/bpf/map_in_map.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Yonghong Song June 29, 2021, 1:45 a.m. UTC | #1
On 6/23/21 7:25 PM, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>

> 

> BTF is required for 'struct bpf_timer' to be recognized inside map value.

> The bpf timers are supported inside inner maps.

> Remember 'struct btf *' in inner_map_meta to make it available

> to the verifier in the sequence:

> 

> struct bpf_map *inner_map = bpf_map_lookup_elem(&outer_map, ...);

> if (inner_map)

>      timer = bpf_map_lookup_elem(&inner_map, ...);

> 

> Signed-off-by: Alexei Starovoitov <ast@kernel.org>


Acked-by: Yonghong Song <yhs@fb.com>
diff mbox series

Patch

diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
index 2f961b941159..d737cff90922 100644
--- a/kernel/bpf/map_in_map.c
+++ b/kernel/bpf/map_in_map.c
@@ -3,6 +3,7 @@ 
  */
 #include <linux/slab.h>
 #include <linux/bpf.h>
+#include <linux/btf.h>
 
 #include "map_in_map.h"
 
@@ -51,6 +52,10 @@  struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 	inner_map_meta->max_entries = inner_map->max_entries;
 	inner_map_meta->spin_lock_off = inner_map->spin_lock_off;
 	inner_map_meta->timer_off = inner_map->timer_off;
+	if (inner_map->btf) {
+		btf_get(inner_map->btf);
+		inner_map_meta->btf = inner_map->btf;
+	}
 
 	/* Misc members not needed in bpf_map_meta_equal() check. */
 	inner_map_meta->ops = inner_map->ops;
@@ -66,6 +71,7 @@  struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 
 void bpf_map_meta_free(struct bpf_map *map_meta)
 {
+	btf_put(map_meta->btf);
 	kfree(map_meta);
 }