Message ID | 20181120000626.16825-2-tehnerd@tehnerd.com |
---|---|
State | Changes Requested, archived |
Delegated to: | BPF Maintainers |
Headers | show |
Series | bpf: adding support for mapinmap in libbpf | expand |
On Mon, Nov 19, 2018 at 4:13 PM Nikita V. Shirokov <tehnerd@tehnerd.com> wrote: > > idea is pretty simple. for specified map (pointed by struct bpf_map) > we would provide descriptor of already loaded map, which is going to be > used as a prototype for inner map. proposed workflow: > 1) open bpf's object (bpf_object__open) > 2) create bpf's map which is going to be used as a prototype > 3) find (by name) map-in-map which you want to load and update w/ > descriptor of inner map w/ a new helper from this patch > 4) load bpf program w/ bpf_object__load > > inner_map_fd is ignored by any other maps asidef from (hash|array) of > maps > > Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com> > --- > tools/lib/bpf/libbpf.c | 7 +++++++ > tools/lib/bpf/libbpf.h | 2 ++ > 2 files changed, 9 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index a01eb9584e52..a2ee1b1a93b6 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -163,6 +163,7 @@ struct bpf_map { > char *name; > size_t offset; > int map_ifindex; > + int inner_map_fd; > struct bpf_map_def def; > __u32 btf_key_type_id; > __u32 btf_value_type_id; > @@ -1146,6 +1147,7 @@ bpf_object__create_maps(struct bpf_object *obj) > create_attr.btf_fd = 0; > create_attr.btf_key_type_id = 0; > create_attr.btf_value_type_id = 0; > + create_attr.inner_map_fd = map->inner_map_fd; > > if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) { > create_attr.btf_fd = btf__fd(obj->btf); > @@ -2562,6 +2564,11 @@ void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex) > map->map_ifindex = ifindex; > } > > +void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd) Do we need "const" attribute here? > +{ > + map->inner_map_fd = fd; > +} > + > static struct bpf_map * > __bpf_map__iter(struct bpf_map *m, struct bpf_object *obj, int i) > { > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index b1686a787102..7cb00cd41789 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -293,6 +293,8 @@ LIBBPF_API void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); > LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); > LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path); > > +LIBBPF_API void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd); > + > LIBBPF_API long libbpf_get_error(const void *ptr); > > struct bpf_prog_load_attr { > -- > 2.15.1 >
On Mon, Nov 19, 2018 at 05:12:43PM -0800, Y Song wrote: > On Mon, Nov 19, 2018 at 4:13 PM Nikita V. Shirokov <tehnerd@tehnerd.com> wrote: > > > > idea is pretty simple. for specified map (pointed by struct bpf_map) > > we would provide descriptor of already loaded map, which is going to be > > used as a prototype for inner map. proposed workflow: > > 1) open bpf's object (bpf_object__open) > > 2) create bpf's map which is going to be used as a prototype > > 3) find (by name) map-in-map which you want to load and update w/ > > descriptor of inner map w/ a new helper from this patch > > 4) load bpf program w/ bpf_object__load > > > > inner_map_fd is ignored by any other maps asidef from (hash|array) of > > maps > > > > Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com> > > --- > > tools/lib/bpf/libbpf.c | 7 +++++++ > > tools/lib/bpf/libbpf.h | 2 ++ > > 2 files changed, 9 insertions(+) > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > index a01eb9584e52..a2ee1b1a93b6 100644 > > --- a/tools/lib/bpf/libbpf.c > > +++ b/tools/lib/bpf/libbpf.c > > @@ -163,6 +163,7 @@ struct bpf_map { > > char *name; > > size_t offset; > > int map_ifindex; > > + int inner_map_fd; > > struct bpf_map_def def; > > __u32 btf_key_type_id; > > __u32 btf_value_type_id; > > @@ -1146,6 +1147,7 @@ bpf_object__create_maps(struct bpf_object *obj) > > create_attr.btf_fd = 0; > > create_attr.btf_key_type_id = 0; > > create_attr.btf_value_type_id = 0; > > + create_attr.inner_map_fd = map->inner_map_fd; > > > > if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) { > > create_attr.btf_fd = btf__fd(obj->btf); > > @@ -2562,6 +2564,11 @@ void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex) > > map->map_ifindex = ifindex; > > } > > > > +void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd) > > Do we need "const" attribute here? > i can drop it in v2 > > +{ > > + map->inner_map_fd = fd; > > +} > > + > > static struct bpf_map * > > __bpf_map__iter(struct bpf_map *m, struct bpf_object *obj, int i) > > { > > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > > index b1686a787102..7cb00cd41789 100644 > > --- a/tools/lib/bpf/libbpf.h > > +++ b/tools/lib/bpf/libbpf.h > > @@ -293,6 +293,8 @@ LIBBPF_API void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); > > LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); > > LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path); > > > > +LIBBPF_API void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd); > > + > > LIBBPF_API long libbpf_get_error(const void *ptr); > > > > struct bpf_prog_load_attr { > > -- > > 2.15.1 > > -- Nikita
On 20/11/18 00:06, Nikita V. Shirokov wrote: > idea is pretty simple. for specified map (pointed by struct bpf_map) > we would provide descriptor of already loaded map, which is going to be > used as a prototype for inner map. proposed workflow: > 1) open bpf's object (bpf_object__open) > 2) create bpf's map which is going to be used as a prototype > 3) find (by name) map-in-map which you want to load and update w/ > descriptor of inner map w/ a new helper from this patch > 4) load bpf program w/ bpf_object__load > > inner_map_fd is ignored by any other maps asidef from (hash|array) of "asidef" -> "aside"
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index a01eb9584e52..a2ee1b1a93b6 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -163,6 +163,7 @@ struct bpf_map { char *name; size_t offset; int map_ifindex; + int inner_map_fd; struct bpf_map_def def; __u32 btf_key_type_id; __u32 btf_value_type_id; @@ -1146,6 +1147,7 @@ bpf_object__create_maps(struct bpf_object *obj) create_attr.btf_fd = 0; create_attr.btf_key_type_id = 0; create_attr.btf_value_type_id = 0; + create_attr.inner_map_fd = map->inner_map_fd; if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) { create_attr.btf_fd = btf__fd(obj->btf); @@ -2562,6 +2564,11 @@ void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex) map->map_ifindex = ifindex; } +void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd) +{ + map->inner_map_fd = fd; +} + static struct bpf_map * __bpf_map__iter(struct bpf_map *m, struct bpf_object *obj, int i) { diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index b1686a787102..7cb00cd41789 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -293,6 +293,8 @@ LIBBPF_API void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path); +LIBBPF_API void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd); + LIBBPF_API long libbpf_get_error(const void *ptr); struct bpf_prog_load_attr {
idea is pretty simple. for specified map (pointed by struct bpf_map) we would provide descriptor of already loaded map, which is going to be used as a prototype for inner map. proposed workflow: 1) open bpf's object (bpf_object__open) 2) create bpf's map which is going to be used as a prototype 3) find (by name) map-in-map which you want to load and update w/ descriptor of inner map w/ a new helper from this patch 4) load bpf program w/ bpf_object__load inner_map_fd is ignored by any other maps asidef from (hash|array) of maps Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com> --- tools/lib/bpf/libbpf.c | 7 +++++++ tools/lib/bpf/libbpf.h | 2 ++ 2 files changed, 9 insertions(+)