BTF-defined BPF map definitions
Subsystems (7)
cover BTF-defined BPF map definitions
This patch set implements initial version (as discussed at LSF/MM2019 conference) of a new way to specify BPF maps, relying on BTF type information, which allows for easy extensibility, preserving forward and backward compatibility. See details and examples in description for patch #6.
Patch #1 centralizes commonly used min/max macro in libbpf_internal.h. Patch #2 extracts .BTF and .BTF.ext loading loging from elf_collect(). Patch #3 refactors map initialization logic into user-provided maps and global data maps, in preparation to adding another way (BTF-defined maps). Patch #4 adds support for map definitions in multiple ELF sections and deprecates bpf_object__find_map_by_offset() API which doesn't appear to be used anymore and makes assumption that all map definitions reside in single ELF section.
Patch #5 splits BTF intialization from sanitization/loading into kernel to preserve original BTF at the time of map initialization.
Patch #6 adds support for BTF-defined maps.
Patch #7 adds new test for BTF-defined map definition.
Patch #8 converts test BPF map definitions to use BTF way.
rfc->v1:
- error out on unknown field by default (Stanislav, Jakub, Lorenz);
Andrii Nakryiko (8):
libbpf: add common min/max macro to libbpf_internal.h
libbpf: extract BTF loading and simplify ELF parsing logic
libbpf: refactor map initialization
libbpf: identify maps by section index in addition to offset
libbpf: split initialization and loading of BTF
libbpf: allow specifying map definitions using BTF selftests/bpf: add test for BTF-defined maps selftests/bpf: switch tests to BTF-defined map definitions
tools/lib/bpf/bpf.c | 7 +- tools/lib/bpf/bpf_prog_linfo.c | 5 +- tools/lib/bpf/btf.c | 3 - tools/lib/bpf/btf.h | 1 + tools/lib/bpf/btf_dump.c | 3 - tools/lib/bpf/libbpf.c | 767 +++++++++++++----- tools/lib/bpf/libbpf_internal.h | 7 + tools/testing/selftests/bpf/progs/bpf_flow.c | 18 +- .../selftests/bpf/progs/get_cgroup_id_kern.c | 18 +- .../testing/selftests/bpf/progs/netcnt_prog.c | 22 +- .../selftests/bpf/progs/sample_map_ret0.c | 18 +- .../selftests/bpf/progs/socket_cookie_prog.c | 9 +- .../bpf/progs/sockmap_verdict_prog.c | 36 +- .../selftests/bpf/progs/test_btf_newkv.c | 73 ++ .../bpf/progs/test_get_stack_rawtp.c | 27 +- .../selftests/bpf/progs/test_global_data.c | 27 +- tools/testing/selftests/bpf/progs/test_l4lb.c | 45 +- .../selftests/bpf/progs/test_l4lb_noinline.c | 45 +- .../selftests/bpf/progs/test_map_in_map.c | 20 +- .../selftests/bpf/progs/test_map_lock.c | 22 +- .../testing/selftests/bpf/progs/test_obj_id.c | 9 +- .../bpf/progs/test_select_reuseport_kern.c | 45 +- .../bpf/progs/test_send_signal_kern.c | 22 +- .../bpf/progs/test_skb_cgroup_id_kern.c | 9 +- .../bpf/progs/test_sock_fields_kern.c | 60 +- .../selftests/bpf/progs/test_spin_lock.c | 33 +- .../bpf/progs/test_stacktrace_build_id.c | 44 +- .../selftests/bpf/progs/test_stacktrace_map.c | 40 +- .../testing/selftests/bpf/progs/test_tc_edt.c | 9 +- .../bpf/progs/test_tcp_check_syncookie_kern.c | 9 +- .../selftests/bpf/progs/test_tcp_estats.c | 9 +- .../selftests/bpf/progs/test_tcpbpf_kern.c | 18 +- .../selftests/bpf/progs/test_tcpnotify_kern.c | 18 +- tools/testing/selftests/bpf/progs/test_xdp.c | 18 +- .../selftests/bpf/progs/test_xdp_noinline.c | 60 +- tools/testing/selftests/bpf/test_btf.c | 10 +- .../selftests/bpf/test_queue_stack_map.h | 20 +- .../testing/selftests/bpf/test_sockmap_kern.h | 72 +- 38 files changed, 1187 insertions(+), 491 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_btf_newkv.c
Signature · 1 line
2.17.1
RFC PATCH 1/8 libbpf: add common min/max macro to libbpf_internal.h
Multiple files in libbpf redefine their own definitions for min/max. Let's define them in libbpf_internal.h and use those everywhere.
--- tools/lib/bpf/bpf.c | 7 ++----- tools/lib/bpf/bpf_prog_linfo.c | 5 +---- tools/lib/bpf/btf.c | 3 --- tools/lib/bpf/btf_dump.c | 3 --- tools/lib/bpf/libbpf_internal.h | 7 +++++++ 5 files changed, 10 insertions(+), 15 deletions(-)
tools/lib/bpf/bpf.c +2 -5
@@ -26,10 +26,11 @@#include <memory.h> #include <unistd.h> #include <asm/unistd.h> +#include <errno.h> #include <linux/bpf.h> #include "bpf.h" #include "libbpf.h" -#include <errno.h> +#include "libbpf_internal.h" /* * When building perf, unistd.h is overridden. __NR_bpf is
@@ -53,10 +54,6 @@# endif #endif -#ifndef min -#define min (x, y) ((x) < (y) ? (x) : (y)) -#endif -static inline __u64 ptr_to_u64 (const void *ptr) {return (__u64 ) (unsigned long ) ptr;
tools/lib/bpf/bpf_prog_linfo.c +1 -4
@@ -6,10 +6,7 @@#include <linux/err.h> #include <linux/bpf.h> #include "libbpf.h" - -#ifndef min -#define min (x, y) ((x) < (y) ? (x) : (y)) -#endif +#include "libbpf_internal.h" struct bpf_prog_linfo {void *raw_linfo;
tools/lib/bpf/btf.c +0 -3
@@ -16,9 +16,6 @@#include "libbpf_internal.h" #include "hashmap.h" -#define max (a, b) ((a) > (b) ? (a) : (b)) -#define min (a, b) ((a) < (b) ? (a) : (b)) -#define BTF_MAX_NR_TYPES 0x7fffffff#define BTF_MAX_STR_OFFSET 0x7fffffff
tools/lib/bpf/btf_dump.c +0 -3
@@ -18,9 +18,6 @@#include "libbpf.h" #include "libbpf_internal.h" -#define min (x, y) ((x) < (y) ? (x) : (y)) -#define max (x, y) ((x) < (y) ? (y) : (x)) -static const char PREFIXES [] ="\t\t\t\t\t\t\t\t\t\t\t\t\t" ;static const size_t PREFIX_CNT =sizeof (PREFIXES ) -1 ;
tools/lib/bpf/libbpf_internal.h +7 -0
@@ -23,6 +23,13 @@#define BTF_PARAM_ENC (name, type) (name), (type)#define BTF_VAR_SECINFO_ENC (type, offset, size) (type), (offset), (size) +#ifndef min +# define min (x, y) ((x) < (y) ? (x) : (y)) +#endif +#ifndef max +# define max (x, y) ((x) < (y) ? (y) : (x)) +#endif +extern void libbpf_print (enum libbpf_print_level level,const char *format, ...) __attribute__((format (printf,2 ,3 )));
Signature · 1 line
2.17.1
RFC PATCH 2/8 libbpf: extract BTF loading and simplify ELF parsing logic
In reply to Andrii NakryikoAs a preparation for adding BTF-based BPF map loading, extract .BTF and .BTF.ext loading logic. Also simplify error handling in bpf_object__elf_collect() by returning early, as there is no common clean up to be done.
--- tools/lib/bpf/libbpf.c | 137 ++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 62 deletions(-)
tools/lib/bpf/libbpf.c +75 -62
@@ -1078,6 +1078,58 @@ static void bpf_object__sanitize_btf_ext(struct bpf_object *obj) } } +static int bpf_object__load_btf (struct bpf_object *obj, +Elf_Data *btf_data, +Elf_Data *btf_ext_data) +{ +int err =0 ; + +if (btf_data) { + obj->btf =btf__new (btf_data->d_buf, btf_data->d_size); +if (IS_ERR (obj->btf)) { +pr_warning ("Error loading ELF section %s: %d.\n" , +BTF_ELF_SEC , err); + goto out; + } + err =btf__finalize_data (obj, obj->btf); +if (err) { +pr_warning ("Error finalizing %s: %d.\n" , +BTF_ELF_SEC , err); + goto out; + } +bpf_object__sanitize_btf (obj); + err =btf__load (obj->btf); +if (err) { +pr_warning ("Error loading %s into kernel: %d.\n" , +BTF_ELF_SEC , err); + goto out; + } + } +if (btf_ext_data) { +if (!obj->btf) { +pr_debug ("Ignore ELF section %s because its depending ELF section %s is not found.\n" , +BTF_EXT_ELF_SEC ,BTF_ELF_SEC ); + goto out; + } + obj->btf_ext =btf_ext__new (btf_ext_data->d_buf, + btf_ext_data->d_size); +if (IS_ERR (obj->btf_ext)) { +pr_warning ("Error loading ELF section %s: %ld. Ignored and continue.\n" , +BTF_EXT_ELF_SEC ,PTR_ERR (obj->btf_ext)); + obj->btf_ext =NULL ; + goto out; + } +bpf_object__sanitize_btf_ext (obj); + } +out: +if (err ||IS_ERR (obj->btf)) { +if (!IS_ERR_OR_NULL (obj->btf)) +btf__free (obj->btf); + obj->btf =NULL ; + } +return 0 ; +} +static int bpf_object__elf_collect (struct bpf_object *obj,int flags) {Elf *elf = obj->efile.elf;
@@ -1102,24 +1154,21 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)if (gelf_getshdr (scn, &sh) != &sh) {pr_warning ("failed to get section(%d) header from %s\n" , idx, obj->path); - err = -LIBBPF_ERRNO__FORMAT ; - goto out; +return -LIBBPF_ERRNO__FORMAT ; } name =elf_strptr (elf, ep->e_shstrndx, sh.sh_name);if (!name) {pr_warning ("failed to get section(%d) name from %s\n" , idx, obj->path); - err = -LIBBPF_ERRNO__FORMAT ; - goto out; +return -LIBBPF_ERRNO__FORMAT ; } data =elf_getdata (scn,0 );if (!data) {pr_warning ("failed to get section(%d) data from %s(%s)\n" , idx, name, obj->path); - err = -LIBBPF_ERRNO__FORMAT ; - goto out; +return -LIBBPF_ERRNO__FORMAT ; } pr_debug("section(%d) %s, size %ld, link %d, flags %lx, type=%d\n", idx, name, (unsigned long)data->d_size,
@@ -1130,10 +1179,14 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags) err =bpf_object__init_license (obj, data->d_buf, data->d_size); +if (err) +return err; }else if (strcmp (name,"version" ) ==0 ) { err =bpf_object__init_kversion (obj, data->d_buf, data->d_size); +if (err) +return err; }else if (strcmp (name,"maps" ) ==0 ) { obj->efile.maps_shndx = idx; }else if (strcmp (name,BTF_ELF_SEC ) ==0 ) {
@@ -1144,11 +1197,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)if (obj->efile.symbols) {pr_warning ("bpf: multiple SYMTAB in %s\n" , obj->path); - err = -LIBBPF_ERRNO__FORMAT ; - }else { - obj->efile.symbols = data; - obj->efile.strtabidx = sh.sh_link; +return -LIBBPF_ERRNO__FORMAT ; } + obj->efile.symbols = data; + obj->efile.strtabidx = sh.sh_link; }else if (sh.sh_type ==SHT_PROGBITS && data->d_size >0 ) {if (sh.sh_flags &SHF_EXECINSTR ) {if (strcmp (name,".text" ) ==0 )
@@ -1162,6 +1214,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)pr_warning ("failed to alloc program %s (%s): %s" , name, obj->path, cp); +return err; } }else if (strcmp (name,".data" ) ==0 ) { obj->efile.data = data;
@@ -1173,8 +1226,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)pr_debug ("skip section(%d) %s\n" , idx, name); } }else if (sh.sh_type ==SHT_REL ) { +int nr_reloc = obj->efile.nr_reloc;void *reloc = obj->efile.reloc; -int nr_reloc = obj->efile.nr_reloc +1 ;int sec = sh.sh_info;/* points to other section */ /* Only do relo for section with exec instructions */
@@ -1184,79 +1237,39 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)continue ; } - reloc =reallocarray (reloc, nr_reloc, + reloc =reallocarray (reloc, nr_reloc +1 ,sizeof (*obj->efile.reloc));if (!reloc) {pr_warning ("realloc failed\n" ); - err = -ENOMEM ; - }else { -int n = nr_reloc -1 ; +return -ENOMEM ; + } - obj->efile.reloc = reloc; - obj->efile.nr_reloc = nr_reloc; + obj->efile.reloc = reloc; + obj->efile.nr_reloc++; - obj->efile.reloc[n].shdr = sh; - obj->efile.reloc[n].data = data; - } + obj->efile.reloc[nr_reloc].shdr = sh; + obj->efile.reloc[nr_reloc].data = data; }else if (sh.sh_type ==SHT_NOBITS &&strcmp (name,".bss" ) ==0 ) { obj->efile.bss = data; obj->efile.bss_shndx = idx; }else {pr_debug ("skip section(%d) %s\n" , idx, name); } -if (err) - goto out; }if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) {pr_warning ("Corrupted ELF file: index of strtab invalid\n" );return -LIBBPF_ERRNO__FORMAT ; } -if (btf_data) { - obj->btf =btf__new (btf_data->d_buf, btf_data->d_size); -if (IS_ERR (obj->btf)) { -pr_warning ("Error loading ELF section %s: %ld. Ignored and continue.\n" , -BTF_ELF_SEC ,PTR_ERR (obj->btf)); - obj->btf =NULL ; - }else { - err =btf__finalize_data (obj, obj->btf); -if (!err) { -bpf_object__sanitize_btf (obj); - err =btf__load (obj->btf); - } -if (err) { -pr_warning ("Error finalizing and loading %s into kernel: %d. Ignored and continue.\n" , -BTF_ELF_SEC , err); -btf__free (obj->btf); - obj->btf =NULL ; - err =0 ; - } - } - } -if (btf_ext_data) { -if (!obj->btf) { -pr_debug ("Ignore ELF section %s because its depending ELF section %s is not found.\n" , -BTF_EXT_ELF_SEC ,BTF_ELF_SEC ); - }else { - obj->btf_ext =btf_ext__new (btf_ext_data->d_buf, - btf_ext_data->d_size); -if (IS_ERR (obj->btf_ext)) { -pr_warning ("Error loading ELF section %s: %ld. Ignored and continue.\n" , -BTF_EXT_ELF_SEC , -PTR_ERR (obj->btf_ext)); - obj->btf_ext =NULL ; - }else { -bpf_object__sanitize_btf_ext (obj); - } - } - } + err =bpf_object__load_btf (obj, btf_data, btf_ext_data); +if (err) +return err;if (bpf_object__has_maps (obj)) { err =bpf_object__init_maps (obj, flags);if (err) - goto out; +return err; } err =bpf_object__init_prog_names (obj); -out:return err; }
Signature · 1 line
2.17.1
RFC PATCH 3/8 libbpf: refactor map initialization
In reply to Andrii NakryikoUser and global data maps initialization has gotten pretty complicated and unnecessarily convoluted. This patch splits out the logic for global data map and user-defined map initialization. It also removes the restriction of pre-calculating how many maps will be initialized, instead allowing to keep adding new maps as they are discovered, which will be used later for BTF-defined map definitions.
--- tools/lib/bpf/libbpf.c | 244 ++++++++++++++++++++++------------------- 1 file changed, 134 insertions(+), 110 deletions(-)
tools/lib/bpf/libbpf.c +134 -110
@@ -234,6 +234,7 @@ struct bpf_object {size_t nr_programs;struct bpf_map *maps;size_t nr_maps; +size_t maps_cap;struct bpf_secdata sections;bool loaded;
@@ -763,12 +764,38 @@ int bpf_object__variable_offset(const struct bpf_object *obj, const char *name,return -ENOENT ; } -static bool bpf_object__has_maps (const struct bpf_object *obj) +static struct bpf_map *bpf_object__add_map (struct bpf_object *obj) { -return obj->efile.maps_shndx >=0 || - obj->efile.data_shndx >=0 || - obj->efile.rodata_shndx >=0 || - obj->efile.bss_shndx >=0 ; +struct bpf_map *new_maps; +size_t new_cap; +int i; + +if (obj->nr_maps +1 <= obj->maps_cap) +return &obj->maps[obj->nr_maps++]; + + new_cap =max (4ul , obj->maps_cap *3 /2 ); + new_maps =realloc (obj->maps, new_cap *sizeof (*obj->maps)); +if (!new_maps) { +pr_warning ("alloc maps for object failed\n" ); +return ERR_PTR (-ENOMEM ); + } + + obj->maps_cap = new_cap; + obj->maps = new_maps; + +/* zero out new maps */ +memset (obj->maps + obj->nr_maps,0 , + (obj->maps_cap - obj->nr_maps) *sizeof (*obj->maps)); +/* +* fill all fd with -1 so won't close incorrect fd (fd=0 is stdin) +* when failure (zclose won't close negative fd)). +*/ +for (i = obj->nr_maps; i < obj->maps_cap; i++) { + obj->maps[i].fd =-1 ; + obj->maps[i].inner_map_fd =-1 ; + } + +return &obj->maps[obj->nr_maps++]; } static int
@@ -808,29 +835,68 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,return 0 ; } -static int bpf_object__init_maps (struct bpf_object *obj,int flags) +static int bpf_object__init_global_data_maps (struct bpf_object *obj) +{ +struct bpf_map *map; +int err; + +if (!obj->caps.global_data) +return 0 ; +/* +* Populate obj->maps with libbpf internal maps. +*/ +if (obj->efile.data_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_DATA , + obj->efile.data, + &obj->sections.data); +if (err) +return err; + } +if (obj->efile.rodata_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_RODATA , + obj->efile.rodata, + &obj->sections.rodata); +if (err) +return err; + } +if (obj->efile.bss_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_BSS , + obj->efile.bss,NULL ); +if (err) +return err; + } +return 0 ; +} + +static int bpf_object__init_user_maps (struct bpf_object *obj,bool strict) { -int i, map_idx, map_def_sz =0 , nr_syms, nr_maps =0 , nr_maps_glob =0 ; -bool strict = !(flags &MAPS_RELAX_COMPAT );Elf_Data *symbols = obj->efile.symbols; +int i, map_def_sz =0 , nr_maps =0 , nr_syms;Elf_Data *data =NULL ; -int ret =0 ; +Elf_Scn *scn; + +if (obj->efile.maps_shndx <0 ) +return 0 ;if (!symbols)return -EINVAL ; - nr_syms = symbols->d_size /sizeof (GElf_Sym); - -if (obj->efile.maps_shndx >=0 ) { -Elf_Scn *scn =elf_getscn (obj->efile.elf, - obj->efile.maps_shndx); -if (scn) - data =elf_getdata (scn,NULL ); -if (!scn || !data) { -pr_warning ("failed to get Elf_Data from map section %d\n" , - obj->efile.maps_shndx); -return -EINVAL ; - } + scn =elf_getscn (obj->efile.elf, obj->efile.maps_shndx); +if (scn) + data =elf_getdata (scn,NULL ); +if (!scn || !data) { +pr_warning ("failed to get Elf_Data from map section %d\n" , + obj->efile.maps_shndx); +return -EINVAL ; }/*
@@ -840,16 +906,8 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)* * TODO: Detect array of map and report error. */ -if (obj->caps.global_data) { -if (obj->efile.data_shndx >=0 ) - nr_maps_glob++; -if (obj->efile.rodata_shndx >=0 ) - nr_maps_glob++; -if (obj->efile.bss_shndx >=0 ) - nr_maps_glob++; - } - -for (i =0 ; data && i < nr_syms; i++) { + nr_syms = symbols->d_size /sizeof (GElf_Sym); +for (i =0 ; i < nr_syms; i++) {GElf_Sym sym;if (!gelf_getsym (symbols, i, &sym))
@@ -858,79 +916,56 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)continue ; nr_maps++; } - -if (!nr_maps && !nr_maps_glob) -return 0 ; -/* Assume equally sized map definitions */ -if (data) { -pr_debug ("maps in %s: %d maps in %zd bytes\n" , obj->path, - nr_maps, data->d_size); - - map_def_sz = data->d_size / nr_maps; -if (!data->d_size || (data->d_size % nr_maps) !=0 ) { -pr_warning ("unable to determine map definition size " -"section %s, %d maps in %zd bytes\n" , - obj->path, nr_maps, data->d_size); -return -EINVAL ; - } - } - - nr_maps += nr_maps_glob; - obj->maps =calloc (nr_maps,sizeof (obj->maps[0 ])); -if (!obj->maps) { -pr_warning ("alloc maps for object failed\n" ); -return -ENOMEM ; - } - obj->nr_maps = nr_maps; - -for (i =0 ; i < nr_maps; i++) { -/* -* fill all fd with -1 so won't close incorrect -* fd (fd=0 is stdin) when failure (zclose won't close -* negative fd)). -*/ - obj->maps[i].fd =-1 ; - obj->maps[i].inner_map_fd =-1 ; +pr_debug ("maps in %s: %d maps in %zd bytes\n" , + obj->path, nr_maps, data->d_size); + + map_def_sz = data->d_size / nr_maps; +if (!data->d_size || (data->d_size % nr_maps) !=0 ) { +pr_warning ("unable to determine map definition size " +"section %s, %d maps in %zd bytes\n" , + obj->path, nr_maps, data->d_size); +return -EINVAL ; } -/* -* Fill obj->maps using data in "maps" section. -*/ -for (i =0 , map_idx =0 ; data && i < nr_syms; i++) { +/* Fill obj->maps using data in "maps" section. */ +for (i =0 ; i < nr_syms; i++) {GElf_Sym sym;const char *map_name;struct bpf_map_def *def; +struct bpf_map *map;if (!gelf_getsym (symbols, i, &sym))continue ;if (sym.st_shndx != obj->efile.maps_shndx)continue ; - map_name =elf_strptr (obj->efile.elf, - obj->efile.strtabidx, + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + + map_name =elf_strptr (obj->efile.elf, obj->efile.strtabidx, sym.st_name);if (!map_name) {pr_warning ("failed to get map #%d name sym string for obj %s\n" , - map_idx, obj->path); + i, obj->path);return -LIBBPF_ERRNO__FORMAT ; } - obj->maps[map_idx].libbpf_type =LIBBPF_MAP_UNSPEC ; - obj->maps[map_idx].offset = sym.st_value; + map->libbpf_type =LIBBPF_MAP_UNSPEC ; + map->offset = sym.st_value;if (sym.st_value + map_def_sz > data->d_size) {pr_warning ("corrupted maps section in %s: last map \"%s\" too small\n" , obj->path, map_name);return -EINVAL ; } - obj->maps[map_idx].name =strdup (map_name); -if (!obj->maps[map_idx].name) { + map->name =strdup (map_name); +if (!map->name) {pr_warning ("failed to alloc map name\n" );return -ENOMEM ; } -pr_debug ("map %d is \"%s\"\n" , map_idx, - obj->maps[map_idx].name); +pr_debug ("map %d is \"%s\"\n" , i, map->name); def = (struct bpf_map_def *)(data->d_buf + sym.st_value);/* * If the definition of the map in the object file fits in
@@ -939,7 +974,7 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)* calloc above. */ if (map_def_sz <=sizeof (struct bpf_map_def )) { -memcpy (&obj->maps[map_idx].def, def, map_def_sz); +memcpy (&map->def, def, map_def_sz); }else {/* * Here the map structure being read is bigger than what
@@ -959,37 +994,30 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)return -EINVAL ; } } -memcpy (&obj->maps[map_idx].def, def, -sizeof (struct bpf_map_def )); +memcpy (&map->def, def,sizeof (struct bpf_map_def )); } - map_idx++; } +return 0 ; +} -if (!obj->caps.global_data) - goto finalize; +static int bpf_object__init_maps (struct bpf_object *obj,int flags) +{ +bool strict = !(flags &MAPS_RELAX_COMPAT ); +int err; -/* -* Populate rest of obj->maps with libbpf internal maps. -*/ -if (obj->efile.data_shndx >=0 ) - ret =bpf_object__init_internal_map (obj, &obj->maps[map_idx++], -LIBBPF_MAP_DATA , - obj->efile.data, - &obj->sections.data); -if (!ret && obj->efile.rodata_shndx >=0 ) - ret =bpf_object__init_internal_map (obj, &obj->maps[map_idx++], -LIBBPF_MAP_RODATA , - obj->efile.rodata, - &obj->sections.rodata); -if (!ret && obj->efile.bss_shndx >=0 ) - ret =bpf_object__init_internal_map (obj, &obj->maps[map_idx++], -LIBBPF_MAP_BSS , - obj->efile.bss,NULL ); -finalize: -if (!ret) + err =bpf_object__init_user_maps (obj, strict); +if (err) +return err; + + err =bpf_object__init_global_data_maps (obj); +if (err) +return err; + +if (obj->nr_maps) {qsort (obj->maps, obj->nr_maps,sizeof (obj->maps[0 ]), compare_bpf_map); -return ret; + } +return 0 ; }static bool section_have_execinstr (struct bpf_object *obj,int idx)
@@ -1262,14 +1290,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)return -LIBBPF_ERRNO__FORMAT ; } err =bpf_object__load_btf (obj, btf_data, btf_ext_data); -if (err) -return err; -if (bpf_object__has_maps (obj)) { +if (!err) err =bpf_object__init_maps (obj, flags); -if (err) -return err; - } - err =bpf_object__init_prog_names (obj); +if (!err) + err =bpf_object__init_prog_names (obj);return err; }
Signature · 1 line
2.17.1
Re: [RFC PATCH bpf-next 3/8] libbpf: refactor map initialization
Quoted 31 lines · Andrii Nakryiko
User and global data maps initialization has gotten pretty complicated and unnecessarily convoluted. This patch splits out the logic for global data map and user-defined map initialization. It also removes the restriction of pre-calculating how many maps will be initialized, instead allowing to keep adding new maps as they are discovered, which will be used later for BTF-defined map definitions.
Signed-off-by Andrii Nakryiko <[email protected]>--- tools/lib/bpf/libbpf.c | 244 ++++++++++++++++++++++------------------- 1 file changed, 134 insertions(+), 110 deletions(-)tools/lib/bpf/libbpf.c +2
-1@@ -234,6 +234,7 @@ struct bpf_object {size_t nr_programs;struct bpf_map *maps;size_t nr_maps; +size_t maps_cap;struct bpf_secdata sections;bool loaded;@@ -763,12 +764,38 @@ int bpf_object__variable_offset(const struct bpf_object *obj, const char *name,return -ENOENT ; } -static bool bpf_object__has_maps (const struct bpf_object *obj) +static struct bpf_map *bpf_object__add_map (struct bpf_object *obj)
tools/lib/bpf/libbpf.c int bpf_object__variable_offset(const struct bpf_object *obj, const char *name, · line 773
Quoted 10 lines
tools/lib/bpf/libbpf.c +5
-4{ -return obj->efile.maps_shndx >=0 || - obj->efile.data_shndx >=0 || - obj->efile.rodata_shndx >=0 || - obj->efile.bss_shndx >=0 ; +struct bpf_map *new_maps; +size_t new_cap; +int i; + +if (obj->nr_maps +1 <= obj->maps_cap)
nit: how about if (obj->nr_maps < obj->maps_cap)
Quoted 62 lines
tools/lib/bpf/libbpf.c +54
-1+return &obj->maps[obj->nr_maps++]; + + new_cap =max (4ul , obj->maps_cap *3 /2 ); + new_maps =realloc (obj->maps, new_cap *sizeof (*obj->maps)); +if (!new_maps) { +pr_warning ("alloc maps for object failed\n" ); +return ERR_PTR (-ENOMEM ); + } + + obj->maps_cap = new_cap; + obj->maps = new_maps; + +/* zero out new maps */ +memset (obj->maps + obj->nr_maps,0 , + (obj->maps_cap - obj->nr_maps) *sizeof (*obj->maps)); +/* +* fill all fd with -1 so won't close incorrect fd (fd=0 is stdin) +* when failure (zclose won't close negative fd)). +*/ +for (i = obj->nr_maps; i < obj->maps_cap; i++) { + obj->maps[i].fd =-1 ; + obj->maps[i].inner_map_fd =-1 ; + } + +return &obj->maps[obj->nr_maps++]; } static int@@ -808,29 +835,68 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,return 0 ; } -static int bpf_object__init_maps (struct bpf_object *obj,int flags) +static int bpf_object__init_global_data_maps (struct bpf_object *obj) +{ +struct bpf_map *map; +int err; + +if (!obj->caps.global_data) +return 0 ; +/* +* Populate obj->maps with libbpf internal maps. +*/ +if (obj->efile.data_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_DATA , + obj->efile.data, + &obj->sections.data); +if (err) +return err; + } +if (obj->efile.rodata_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_RODATA , + obj->efile.rodata, + &obj->sections.rodata); +if (err) +return err;
tools/lib/bpf/libbpf.c bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map, · line 876
Quoted 10 lines
tools/lib/bpf/libbpf.c +10
-0+ } +if (obj->efile.bss_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_BSS , + obj->efile.bss,NULL ); +if (err) +return err; + }
These 3 if clause are a little too complicated. How about we call bpf_obj_add_map(obj) within bpf_object__init_internal_map()?
Quoted 249 lines
tools/lib/bpf/libbpf.c +63
-105+return 0 ; +} + +static int bpf_object__init_user_maps (struct bpf_object *obj,bool strict) { -int i, map_idx, map_def_sz =0 , nr_syms, nr_maps =0 , nr_maps_glob =0 ; -bool strict = !(flags &MAPS_RELAX_COMPAT );Elf_Data *symbols = obj->efile.symbols; +int i, map_def_sz =0 , nr_maps =0 , nr_syms;Elf_Data *data =NULL ; -int ret =0 ; +Elf_Scn *scn; + +if (obj->efile.maps_shndx <0 ) +return 0 ;if (!symbols)return -EINVAL ; - nr_syms = symbols->d_size /sizeof (GElf_Sym); - -if (obj->efile.maps_shndx >=0 ) { -Elf_Scn *scn =elf_getscn (obj->efile.elf, - obj->efile.maps_shndx); -if (scn) - data =elf_getdata (scn,NULL ); -if (!scn || !data) { -pr_warning ("failed to get Elf_Data from map section %d\n" , - obj->efile.maps_shndx); -return -EINVAL ; - } + scn =elf_getscn (obj->efile.elf, obj->efile.maps_shndx); +if (scn) + data =elf_getdata (scn,NULL ); +if (!scn || !data) { +pr_warning ("failed to get Elf_Data from map section %d\n" , + obj->efile.maps_shndx); +return -EINVAL ; }/* @@ -840,16 +906,8 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)* * TODO: Detect array of map and report error. */ -if (obj->caps.global_data) { -if (obj->efile.data_shndx >=0 ) - nr_maps_glob++; -if (obj->efile.rodata_shndx >=0 ) - nr_maps_glob++; -if (obj->efile.bss_shndx >=0 ) - nr_maps_glob++; - } - -for (i =0 ; data && i < nr_syms; i++) { + nr_syms = symbols->d_size /sizeof (GElf_Sym); +for (i =0 ; i < nr_syms; i++) {GElf_Sym sym;if (!gelf_getsym (symbols, i, &sym))@@ -858,79 +916,56 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)continue ; nr_maps++; } - -if (!nr_maps && !nr_maps_glob) -return 0 ; -/* Assume equally sized map definitions */ -if (data) { -pr_debug ("maps in %s: %d maps in %zd bytes\n" , obj->path, - nr_maps, data->d_size); - - map_def_sz = data->d_size / nr_maps; -if (!data->d_size || (data->d_size % nr_maps) !=0 ) { -pr_warning ("unable to determine map definition size " -"section %s, %d maps in %zd bytes\n" , - obj->path, nr_maps, data->d_size); -return -EINVAL ; - } - } - - nr_maps += nr_maps_glob; - obj->maps =calloc (nr_maps,sizeof (obj->maps[0 ])); -if (!obj->maps) { -pr_warning ("alloc maps for object failed\n" ); -return -ENOMEM ; - } - obj->nr_maps = nr_maps; - -for (i =0 ; i < nr_maps; i++) { -/* -* fill all fd with -1 so won't close incorrect -* fd (fd=0 is stdin) when failure (zclose won't close -* negative fd)). -*/ - obj->maps[i].fd =-1 ; - obj->maps[i].inner_map_fd =-1 ; +pr_debug ("maps in %s: %d maps in %zd bytes\n" , + obj->path, nr_maps, data->d_size); + + map_def_sz = data->d_size / nr_maps; +if (!data->d_size || (data->d_size % nr_maps) !=0 ) { +pr_warning ("unable to determine map definition size " +"section %s, %d maps in %zd bytes\n" , + obj->path, nr_maps, data->d_size); +return -EINVAL ; } -/* -* Fill obj->maps using data in "maps" section. -*/ -for (i =0 , map_idx =0 ; data && i < nr_syms; i++) { +/* Fill obj->maps using data in "maps" section. */ +for (i =0 ; i < nr_syms; i++) {GElf_Sym sym;const char *map_name;struct bpf_map_def *def; +struct bpf_map *map;if (!gelf_getsym (symbols, i, &sym))continue ;if (sym.st_shndx != obj->efile.maps_shndx)continue ; - map_name =elf_strptr (obj->efile.elf, - obj->efile.strtabidx, + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + + map_name =elf_strptr (obj->efile.elf, obj->efile.strtabidx, sym.st_name);if (!map_name) {pr_warning ("failed to get map #%d name sym string for obj %s\n" , - map_idx, obj->path); + i, obj->path);return -LIBBPF_ERRNO__FORMAT ; } - obj->maps[map_idx].libbpf_type =LIBBPF_MAP_UNSPEC ; - obj->maps[map_idx].offset = sym.st_value; + map->libbpf_type =LIBBPF_MAP_UNSPEC ; + map->offset = sym.st_value;if (sym.st_value + map_def_sz > data->d_size) {pr_warning ("corrupted maps section in %s: last map \"%s\" too small\n" , obj->path, map_name);return -EINVAL ; } - obj->maps[map_idx].name =strdup (map_name); -if (!obj->maps[map_idx].name) { + map->name =strdup (map_name); +if (!map->name) {pr_warning ("failed to alloc map name\n" );return -ENOMEM ; } -pr_debug ("map %d is \"%s\"\n" , map_idx, - obj->maps[map_idx].name); +pr_debug ("map %d is \"%s\"\n" , i, map->name); def = (struct bpf_map_def *)(data->d_buf + sym.st_value);/* * If the definition of the map in the object file fits in @@ -939,7 +974,7 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)* calloc above. */ if (map_def_sz <=sizeof (struct bpf_map_def )) { -memcpy (&obj->maps[map_idx].def, def, map_def_sz); +memcpy (&map->def, def, map_def_sz); }else {/* * Here the map structure being read is bigger than what @@ -959,37 +994,30 @@ static int bpf_object__init_maps(struct bpf_object *obj, int flags)return -EINVAL ; } } -memcpy (&obj->maps[map_idx].def, def, -sizeof (struct bpf_map_def )); +memcpy (&map->def, def,sizeof (struct bpf_map_def )); } - map_idx++; } +return 0 ; +} -if (!obj->caps.global_data) - goto finalize; +static int bpf_object__init_maps (struct bpf_object *obj,int flags) +{ +bool strict = !(flags &MAPS_RELAX_COMPAT ); +int err; -/* -* Populate rest of obj->maps with libbpf internal maps. -*/ -if (obj->efile.data_shndx >=0 ) - ret =bpf_object__init_internal_map (obj, &obj->maps[map_idx++], -LIBBPF_MAP_DATA , - obj->efile.data, - &obj->sections.data); -if (!ret && obj->efile.rodata_shndx >=0 ) - ret =bpf_object__init_internal_map (obj, &obj->maps[map_idx++], -LIBBPF_MAP_RODATA , - obj->efile.rodata, - &obj->sections.rodata); -if (!ret && obj->efile.bss_shndx >=0 ) - ret =bpf_object__init_internal_map (obj, &obj->maps[map_idx++], -LIBBPF_MAP_BSS , - obj->efile.bss,NULL ); -finalize: -if (!ret) + err =bpf_object__init_user_maps (obj, strict); +if (err) +return err; + + err =bpf_object__init_global_data_maps (obj); +if (err) +return err; + +if (obj->nr_maps) {qsort (obj->maps, obj->nr_maps,sizeof (obj->maps[0 ]), compare_bpf_map); -return ret; + } +return 0 ; }static bool section_have_execinstr (struct bpf_object *obj,int idx)@@ -1262,14 +1290,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)return -LIBBPF_ERRNO__FORMAT ; } err =bpf_object__load_btf (obj, btf_data, btf_ext_data); -if (err) -return err; -if (bpf_object__has_maps (obj)) { +if (!err) err =bpf_object__init_maps (obj, flags); -if (err) -return err; - } - err =bpf_object__init_prog_names (obj); +if (!err) + err =bpf_object__init_prog_names (obj);return err; } --2.17.1
Re: [RFC PATCH bpf-next 3/8] libbpf: refactor map initialization
Quoted 11 lines · Song Liu
Quoted 9 lines · Andrii Nakryiko
User and global data maps initialization has gotten pretty complicated and unnecessarily convoluted. This patch splits out the logic for global data map and user-defined map initialization. It also removes the restriction of pre-calculating how many maps will be initialized, instead allowing to keep adding new maps as they are discovered, which will be used later for BTF-defined map definitions.
Signed-off-by Andrii Nakryiko <[email protected]>
Ooops, wrong thread...
Re: [RFC PATCH bpf-next 3/8] libbpf: refactor map initialization
In reply to Song LiuQuoted 31 lines · Song Liu
Quoted 29 lines · Andrii Nakryiko
User and global data maps initialization has gotten pretty complicated and unnecessarily convoluted. This patch splits out the logic for global data map and user-defined map initialization. It also removes the restriction of pre-calculating how many maps will be initialized, instead allowing to keep adding new maps as they are discovered, which will be used later for BTF-defined map definitions.
Signed-off-by Andrii Nakryiko <[email protected]>--- tools/lib/bpf/libbpf.c | 244 ++++++++++++++++++++++------------------- 1 file changed, 134 insertions(+), 110 deletions(-)tools/lib/bpf/libbpf.c +1
-0@@ -234,6 +234,7 @@ struct bpf_object {size_t nr_programs;struct bpf_map *maps;size_t nr_maps; +size_t maps_cap;struct bpf_secdata sections;bool loaded;@@ -763,12 +764,38 @@ int bpf_object__variable_offset(const struct bpf_object *obj, const char *name,return -ENOENT ; }
Quoted 13 lines
tools/lib/bpf/libbpf.c int bpf_object__variable_offset(const struct bpf_object *obj, const char *name, · line 773
Quoted 12 lines
tools/lib/bpf/libbpf.c +6
-5-static bool bpf_object__has_maps (const struct bpf_object *obj) +static struct bpf_map *bpf_object__add_map (struct bpf_object *obj) { -return obj->efile.maps_shndx >=0 || - obj->efile.data_shndx >=0 || - obj->efile.rodata_shndx >=0 || - obj->efile.bss_shndx >=0 ; +struct bpf_map *new_maps; +size_t new_cap; +int i; + +if (obj->nr_maps +1 <= obj->maps_cap)nit: how about if (
obj->nr_maps<obj->maps_cap)
yep, will do
Quoted 68 lines
Quoted 68 lines
tools/lib/bpf/libbpf.c +59
-1+return &obj->maps[obj->nr_maps++]; + + new_cap =max (4ul , obj->maps_cap *3 /2 ); + new_maps =realloc (obj->maps, new_cap *sizeof (*obj->maps)); +if (!new_maps) { +pr_warning ("alloc maps for object failed\n" ); +return ERR_PTR (-ENOMEM ); + } + + obj->maps_cap = new_cap; + obj->maps = new_maps; + +/* zero out new maps */ +memset (obj->maps + obj->nr_maps,0 , + (obj->maps_cap - obj->nr_maps) *sizeof (*obj->maps)); +/* +* fill all fd with -1 so won't close incorrect fd (fd=0 is stdin) +* when failure (zclose won't close negative fd)). +*/ +for (i = obj->nr_maps; i < obj->maps_cap; i++) { + obj->maps[i].fd =-1 ; + obj->maps[i].inner_map_fd =-1 ; + } + +return &obj->maps[obj->nr_maps++]; } static int@@ -808,29 +835,68 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,return 0 ; } -static int bpf_object__init_maps (struct bpf_object *obj,int flags) +static int bpf_object__init_global_data_maps (struct bpf_object *obj) +{ +struct bpf_map *map; +int err; + +if (!obj->caps.global_data) +return 0 ; +/* +* Populate obj->maps with libbpf internal maps. +*/ +if (obj->efile.data_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_DATA , + obj->efile.data, + &obj->sections.data); +if (err) +return err; + } +if (obj->efile.rodata_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map); + err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_RODATA , + obj->efile.rodata, + &obj->sections.rodata); +if (err) +return err; + } +if (obj->efile.bss_shndx >=0 ) { + map =bpf_object__add_map (obj); +if (IS_ERR (map)) +return PTR_ERR (map);
Quoted 8 lines
tools/lib/bpf/libbpf.c bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map, · line 876
Quoted 5 lines
tools/lib/bpf/libbpf.c +5
-0+ err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_BSS , + obj->efile.bss,NULL ); +if (err) +return err; + }These 3 if clause are a little too complicated. How about we call
bpf_obj_add_map(obj)withinbpf_object__init_internal_map()?
Yeah, totally, not sure why I did it this way :)
Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/libbpf.c +4
-0+return 0 ; +} + +static int bpf_object__init_user_maps (struct bpf_object *obj,bool strict) {
<snip>
RFC PATCH 4/8 libbpf: identify maps by section index in addition to offset
In reply to Andrii NakryikoTo support maps to be defined in multiple sections, it's important to identify map not just by offset within its section, but section index as well. This patch adds tracking of section index.
For global data, we record section index of corresponding .data/.bss/.rodata ELF section for uniformity, and thus don't need a special value of offset for those maps.
--- tools/lib/bpf/libbpf.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-)
tools/lib/bpf/libbpf.c +26 -16
@@ -207,7 +207,8 @@ static const char * const libbpf_type_to_btf_name[] = {struct bpf_map {int fd;char *name; -size_t offset; +int sec_idx; +size_t sec_offset;int map_ifindex;int inner_map_fd;struct bpf_map_def def;
@@ -647,7 +648,9 @@ static int compare_bpf_map(const void *_a, const void *_b)const struct bpf_map *a = _a;const struct bpf_map *b = _b; -return a->offset - b->offset; +if (a->sec_idx != b->sec_idx) +return a->sec_idx - b->sec_idx; +return a->sec_offset - b->sec_offset; }static bool bpf_map_type__is_map_in_map (enum bpf_map_type type)
@@ -800,14 +803,15 @@ static struct bpf_map *bpf_object__add_map(struct bpf_object *obj)static int bpf_object__init_internal_map (struct bpf_object *obj,struct bpf_map *map, -enum libbpf_map_type type,Elf_Data *data, -void **data_buff) +enum libbpf_map_type type,int sec_idx, +Elf_Data *data,void **data_buff) {struct bpf_map_def *def = &map->def;char map_name[BPF_OBJ_NAME_LEN ]; map->libbpf_type = type; - map->offset = ~(typeof(map->offset))0; + map->sec_idx = sec_idx; + map->sec_offset =0 ;snprintf (map_name,sizeof (map_name),"%.8s%.7s" , obj->name, libbpf_type_to_btf_name[type]); map->name =strdup (map_name);
@@ -815,6 +819,8 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,pr_warning ("failed to alloc map name\n" );return -ENOMEM ; } +pr_debug ("map '%s' (global data): at sec_idx %d, offset %zu.\n" , + map_name, map->sec_idx, map->sec_offset); def->type =BPF_MAP_TYPE_ARRAY ; def->key_size =sizeof (int );
@@ -850,6 +856,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)if (IS_ERR (map))return PTR_ERR (map); err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_DATA , + obj->efile.data_shndx, obj->efile.data, &obj->sections.data);if (err)
@@ -860,6 +867,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)if (IS_ERR (map))return PTR_ERR (map); err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_RODATA , + obj->efile.rodata_shndx, obj->efile.rodata, &obj->sections.rodata);if (err)
@@ -870,6 +878,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)if (IS_ERR (map))return PTR_ERR (map); err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_BSS , + obj->efile.bss_shndx, obj->efile.bss,NULL );if (err)return err;
@@ -953,7 +962,10 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) } map->libbpf_type =LIBBPF_MAP_UNSPEC ; - map->offset = sym.st_value; + map->sec_idx = sym.st_shndx; + map->sec_offset = sym.st_value; +pr_debug ("map '%s' (legacy): at sec_idx %d, offset %zu.\n" , + map_name, map->sec_idx, map->sec_offset);if (sym.st_value + map_def_sz > data->d_size) {pr_warning ("corrupted maps section in %s: last map \"%s\" too small\n" , obj->path, map_name);
@@ -1453,9 +1465,13 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,if (maps[map_idx].libbpf_type != type)continue ;if (type !=LIBBPF_MAP_UNSPEC || - maps[map_idx].offset == sym.st_value) { -pr_debug ("relocation: find map %zd (%s) for insn %u\n" , - map_idx, maps[map_idx].name, insn_idx); + (maps[map_idx].sec_idx == sym.st_shndx && + maps[map_idx].sec_offset == sym.st_value)) { +pr_debug ("relocation: found map %zd (%s, sec_idx %d, offset %zu) for insn %u\n" , + map_idx, maps[map_idx].name, + maps[map_idx].sec_idx, + maps[map_idx].sec_offset, + insn_idx);break ; } }
@@ -3472,13 +3488,7 @@ bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name)struct bpf_map *bpf_object__find_map_by_offset (struct bpf_object *obj,size_t offset) { -int i; - -for (i =0 ; i < obj->nr_maps; i++) { -if (obj->maps[i].offset == offset) -return &obj->maps[i]; - } -return ERR_PTR (-ENOENT ); +return ERR_PTR (-ENOTSUP ); }long libbpf_get_error (const void *ptr)
Signature · 1 line
2.17.1
Re: [RFC PATCH bpf-next 4/8] libbpf: identify maps by section index in addition to offset
Quoted 122 lines · Andrii Nakryiko
To support maps to be defined in multiple sections, it's important to identify map not just by offset within its section, but section index as well. This patch adds tracking of section index.
For global data, we record section index of corresponding .data/.bss/.rodata ELF section for uniformity, and thus don't need a special value of offset for those maps.
Signed-off-by Andrii Nakryiko <[email protected]>--- tools/lib/bpf/libbpf.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-)tools/lib/bpf/libbpf.c +25
-9@@ -207,7 +207,8 @@ static const char * const libbpf_type_to_btf_name[] = {struct bpf_map {int fd;char *name; -size_t offset; +int sec_idx; +size_t sec_offset;int map_ifindex;int inner_map_fd;struct bpf_map_def def;@@ -647,7 +648,9 @@ static int compare_bpf_map(const void *_a, const void *_b)const struct bpf_map *a = _a;const struct bpf_map *b = _b; -return a->offset - b->offset; +if (a->sec_idx != b->sec_idx) +return a->sec_idx - b->sec_idx; +return a->sec_offset - b->sec_offset; }static bool bpf_map_type__is_map_in_map (enum bpf_map_type type)@@ -800,14 +803,15 @@ static struct bpf_map *bpf_object__add_map(struct bpf_object *obj)static int bpf_object__init_internal_map (struct bpf_object *obj,struct bpf_map *map, -enum libbpf_map_type type,Elf_Data *data, -void **data_buff) +enum libbpf_map_type type,int sec_idx, +Elf_Data *data,void **data_buff) {struct bpf_map_def *def = &map->def;char map_name[BPF_OBJ_NAME_LEN ]; map->libbpf_type = type; - map->offset = ~(typeof(map->offset))0; + map->sec_idx = sec_idx; + map->sec_offset =0 ;snprintf (map_name,sizeof (map_name),"%.8s%.7s" , obj->name, libbpf_type_to_btf_name[type]); map->name =strdup (map_name);@@ -815,6 +819,8 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,pr_warning ("failed to alloc map name\n" );return -ENOMEM ; } +pr_debug ("map '%s' (global data): at sec_idx %d, offset %zu.\n" , + map_name, map->sec_idx, map->sec_offset); def->type =BPF_MAP_TYPE_ARRAY ; def->key_size =sizeof (int );@@ -850,6 +856,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)if (IS_ERR (map))return PTR_ERR (map); err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_DATA , + obj->efile.data_shndx, obj->efile.data, &obj->sections.data);if (err)@@ -860,6 +867,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)if (IS_ERR (map))return PTR_ERR (map); err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_RODATA , + obj->efile.rodata_shndx, obj->efile.rodata, &obj->sections.rodata);if (err)@@ -870,6 +878,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)if (IS_ERR (map))return PTR_ERR (map); err =bpf_object__init_internal_map (obj, map,LIBBPF_MAP_BSS , + obj->efile.bss_shndx, obj->efile.bss,NULL );if (err)return err;@@ -953,7 +962,10 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) } map->libbpf_type =LIBBPF_MAP_UNSPEC ; - map->offset = sym.st_value; + map->sec_idx = sym.st_shndx; + map->sec_offset = sym.st_value; +pr_debug ("map '%s' (legacy): at sec_idx %d, offset %zu.\n" , + map_name, map->sec_idx, map->sec_offset);if (sym.st_value + map_def_sz > data->d_size) {pr_warning ("corrupted maps section in %s: last map \"%s\" too small\n" , obj->path, map_name);@@ -1453,9 +1465,13 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,if (maps[map_idx].libbpf_type != type)continue ;if (type !=LIBBPF_MAP_UNSPEC || - maps[map_idx].offset == sym.st_value) { -pr_debug ("relocation: find map %zd (%s) for insn %u\n" , - map_idx, maps[map_idx].name, insn_idx); + (maps[map_idx].sec_idx == sym.st_shndx && + maps[map_idx].sec_offset == sym.st_value)) { +pr_debug ("relocation: found map %zd (%s, sec_idx %d, offset %zu) for insn %u\n" , + map_idx, maps[map_idx].name, + maps[map_idx].sec_idx, + maps[map_idx].sec_offset, + insn_idx);break ; } }@@ -3472,13 +3488,7 @@ bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name) struct bpf_map *
tools/lib/bpf/libbpf.c bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name) · line 3491
Quoted 10 lines
tools/lib/bpf/libbpf.c +1
-7bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset) { - int i; - -for (i =0 ; i < obj->nr_maps; i++) { -if (obj->maps[i].offset == offset) -return &obj->maps[i]; - } -return ERR_PTR (-ENOENT ); +return ERR_PTR (-ENOTSUP );
I probably missed some discussion. But is it OK to stop supporting this function?
Thanks,
Song
Quoted 6 lines
tools/lib/bpf/libbpf.c +0
-1}long libbpf_get_error (const void *ptr) --2.17.1
Re: [RFC PATCH bpf-next 4/8] libbpf: identify maps by section index in addition to offset
Quoted 16 lines · Song Liu
Quoted 14 lines · Andrii Nakryiko
To support maps to be defined in multiple sections, it's important to identify map not just by offset within its section, but section index as well. This patch adds tracking of section index.
For global data, we record section index of corresponding .data/.bss/.rodata ELF section for uniformity, and thus don't need a special value of offset for those maps.
Signed-off-by Andrii Nakryiko <[email protected]>--- tools/lib/bpf/libbpf.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-)
<snip>
Quoted 7 lines
Quoted 7 lines
tools/lib/bpf/libbpf.c +0
-3@@ -3472,13 +3488,7 @@ bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name)struct bpf_map *bpf_object__find_map_by_offset (struct bpf_object *obj,size_t offset) { -int i; - -for (i =0 ; i < obj->nr_maps; i++) {
Quoted 8 lines
tools/lib/bpf/libbpf.c bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name) · line 3491
Quoted 5 lines
tools/lib/bpf/libbpf.c +1
-4-if (obj->maps[i].offset == offset) -return &obj->maps[i]; - } -return ERR_PTR (-ENOENT ); +return ERR_PTR (-ENOTSUP );I probably missed some discussion. But is it OK to stop supporting this function?
This function was added long time ago for some perf (the tool) specific use case. But I haven't found any uses of that in kernel code, as well as anywhere on github/internal FB code base. It appears it's not used anywhere.
Also, this function makes bad assumption that map can be identified by single offset, while we are going to support maps in two (or more, if necessary) different ELF sections, so offset is not unique anymore. It's not clear what's the intended use case for this API is, looking up by name should be the way to do this. Given it's not used, but we still need to preserve ABI, I switched it to return -ENOTSUP.
Quoted 10 lines
Thanks,
SongQuoted 6 lines
tools/lib/bpf/libbpf.c +0
-1}long libbpf_get_error (const void *ptr) --2.17.1
Song Liu
Acked-byRe: [RFC PATCH bpf-next 4/8] libbpf: identify maps by section index in addition to offset
Quoted 45 lines · Andrii Nakryiko
Quoted 16 lines · Song Liu
Quoted 14 lines · Andrii Nakryiko
To support maps to be defined in multiple sections, it's important to identify map not just by offset within its section, but section index as well. This patch adds tracking of section index.
For global data, we record section index of corresponding .data/.bss/.rodata ELF section for uniformity, and thus don't need a special value of offset for those maps.
Signed-off-by Andrii Nakryiko <[email protected]>---
tools/lib/bpf/libbpf.c| 42 ++++++++++++++++++++++++++----------------1 file changed, 26 insertions(+), 16 deletions(-)<snip>
Quoted 7 lines
Quoted 7 lines
(quoted diff) +0
-0@@ -3472,13 +3488,7 @@ bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name)struct
bpf_map*bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset){tools/lib/bpf/libbpf.c +0
-3-int i; - -for (i =0 ; i < obj->nr_maps; i++) {Quoted 8 lines
tools/lib/bpf/libbpf.c bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name) · line 3491
Quoted 5 lines
tools/lib/bpf/libbpf.c +1
-4-if (obj->maps[i].offset == offset) -return &obj->maps[i]; - } -return ERR_PTR (-ENOENT ); +return ERR_PTR (-ENOTSUP );I probably missed some discussion. But is it OK to stop supporting this function?
This function was added long time ago for some perf (the tool) specific use case. But I haven't found any uses of that in kernel code, as well as anywhere on github/internal FB code base. It appears it's not used anywhere.
Quoted 6 lines
Also, this function makes bad assumption that map can be identified by single offset, while we are going to support maps in two (or more, if necessary) different ELF sections, so offset is not unique anymore. It's not clear what's the intended use case for this API is, looking up by name should be the way to do this. Given it's not used, but we still need to preserve ABI, I switched it to return
-ENOTSUP.
Good survey of the use cases! Yeah, I agree returning -ENOTSUP is the best option here.
RFC PATCH 5/8 libbpf: split initialization and loading of BTF
In reply to Andrii NakryikoLibbpf does sanitization of BTF before loading it into kernel, if kernel doesn't support some of newer BTF features. This removes some of the important information from BTF (e.g., DATASEC and VAR description), which will be used for map construction. This patch splits BTF processing into initialization step, in which BTF is initialized from ELF and all the original data is still preserved; and sanitization/loading step, which ensures that BTF is safe to load into kernel. This allows to use full BTF information to construct maps, while still loading valid BTF into older kernels.
--- tools/lib/bpf/libbpf.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-)
tools/lib/bpf/libbpf.c +24 -10
@@ -1118,7 +1118,7 @@ static void bpf_object__sanitize_btf_ext(struct bpf_object *obj) } } -static int bpf_object__load_btf (struct bpf_object *obj, +static int bpf_object__init_btf (struct bpf_object *obj,Elf_Data *btf_data,Elf_Data *btf_ext_data) {
@@ -1137,13 +1137,6 @@ static int bpf_object__load_btf(struct bpf_object *obj, BTF_ELF_SEC, err); goto out; } -bpf_object__sanitize_btf (obj); - err =btf__load (obj->btf); -if (err) { -pr_warning ("Error loading %s into kernel: %d.\n" , -BTF_ELF_SEC , err); - goto out; - } }if (btf_ext_data) {if (!obj->btf) {
@@ -1159,7 +1152,6 @@ static int bpf_object__load_btf(struct bpf_object *obj, obj->btf_ext =NULL ; goto out; } -bpf_object__sanitize_btf_ext (obj); } out:if (err ||IS_ERR (obj->btf)) {
@@ -1170,6 +1162,26 @@ static int bpf_object__load_btf(struct bpf_object *obj,return 0 ; } +static int bpf_object__sanitize_and_load_btf (struct bpf_object *obj) +{ +int err =0 ; + +if (!obj->btf) +return 0 ; + +bpf_object__sanitize_btf (obj); +bpf_object__sanitize_btf_ext (obj); + + err =btf__load (obj->btf); +if (err) { +pr_warning ("Error loading %s into kernel: %d.\n" , +BTF_ELF_SEC , err); +btf__free (obj->btf); + obj->btf =NULL ; + } +return 0 ; +} +static int bpf_object__elf_collect (struct bpf_object *obj,int flags) {Elf *elf = obj->efile.elf;
@@ -1301,9 +1313,11 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)pr_warning ("Corrupted ELF file: index of strtab invalid\n" );return -LIBBPF_ERRNO__FORMAT ; } - err =bpf_object__load_btf (obj, btf_data, btf_ext_data); + err =bpf_object__init_btf (obj, btf_data, btf_ext_data);if (!err) err =bpf_object__init_maps (obj, flags); +if (!err) + err =bpf_object__sanitize_and_load_btf (obj);if (!err) err =bpf_object__init_prog_names (obj);return err;
Signature · 1 line
2.17.1
RFC PATCH 6/8 libbpf: allow specifying map definitions using BTF
In reply to Andrii NakryikoThis patch adds support for a new way to define BPF maps. It relies on BTF to describe mandatory and optional attributes of a map, as well as captures type information of key and value naturally. This eliminates the need for BPF_ANNOTATE_KV_PAIR hack and ensures key/value sizes are always in sync with the key/value type.
Relying on BTF, this approach allows for both forward and backward compatibility w.r.t. extending supported map definition features. By default, any unrecognized attributes are treated as an error, but it's possible relax this using MAPS_RELAX_COMPAT flag. New attributes, added in the future will need to be optional.
The outline of the new map definition (short, BTF-defined maps) is as follows:
1. All the maps should be defined in .maps ELF section. It's possible to have both "legacy" map definitions in maps sections and BTF-defined maps in .maps sections. Everything will still work transparently.
2. The map declaration and initialization is done through
a global/static variable of a struct type with few mandatory and extra optional fields:
- type field is mandatory and specified type of BPF map;
- key/value fields are mandatory and capture key/value type/size information;
- max_entries attribute is optional; if max_entries is not specified or initialized, it has to be provided in runtime through libbpf API before loading bpf_object;
- map_flags is optional and if not defined, will be assumed to be 0.
3. Key/value fields should be **a pointer** to a type describing key/value. The pointee type is assumed (and will be recorded as such and used for size determination) to be a type describing key/value of the map. This is done to save excessive amounts of space allocated in corresponding ELF sections for key/value of big size.
4. As some maps disallow having BTF type ID associated with key/value, it's possible to specify key/value size explicitly without associating BTF type ID with it. Use key_size and value_size fields to do that (see example below).
Here's an example of simple ARRAY map defintion:
struct my_value { int x, y, z; };
struct {
int type;
int max_entries;
int *key;
struct my_value *value;
} btf_map SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 16,
};This will define BPF ARRAY map 'btf_map' with 16 elements. The key will be of type int and thus key size will be 4 bytes. The value is struct my_value of size 12 bytes. This map can be used from C code exactly the same as with existing maps defined through struct bpf_map_def.
Here's an example of STACKMAP definition (which currently disallows BTF type IDs for key/value):
struct {
__u32 type;
__u32 max_entries;
__u32 map_flags;
__u32 key_size;
__u32 value_size;
} stackmap SEC(".maps") = { .type = BPF_MAP_TYPE_STACK_TRACE,
.max_entries = 128,
.map_flags = BPF_F_STACK_BUILD_ID,
.key_size = sizeof(__u32),
.value_size = PERF_MAX_STACK_DEPTH * sizeof(struct bpf_stack_build_id),
};
This approach is naturally extended to support map-in-map, by making a value field to be another struct that describes inner map. This feature is not implemented yet. It's also possible to incrementally add features like pinning with full backwards and forward compatibility. Support for static initialization of BPF_MAP_TYPE_PROG_ARRAY using pointers to BPF programs is also on the roadmap.
--- tools/lib/bpf/btf.h | 1 + tools/lib/bpf/libbpf.c | 338 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 330 insertions(+), 9 deletions(-)
tools/lib/bpf/btf.h +1 -0
@@ -17,6 +17,7 @@ extern "C" {#define BTF_ELF_SEC ".BTF"#define BTF_EXT_ELF_SEC ".BTF.ext" +#define MAPS_ELF_SEC ".maps"struct btf ;struct btf_ext ;
tools/lib/bpf/libbpf.c +329 -9
434 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 7/8 selftests/bpf: add test for BTF-defined maps
In reply to Andrii NakryikoAdd file test for BTF-defined map definition.
--- .../selftests/bpf/progs/test_btf_newkv.c | 73 +++++++++++++++++++ tools/testing/selftests/bpf/test_btf.c | 10 +-- 2 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_btf_newkv.c
tools/testing/selftests/bpf/progs/test_btf_newkv.c new file +73 -0
@@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2018 Facebook */ +#include <linux/bpf.h> +#include "bpf_helpers.h" + +int _version SEC("version") = 1; + +struct ipv_counts { +unsigned int v4; +unsigned int v6; +}; + +/* just to validate we can handle maps in multiple sections */ +struct bpf_map_def SEC("maps") btf_map_legacy = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(int), + .value_size = sizeof(long long), + .max_entries = 4, +}; + +BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts); + +struct { +int *key; +struct ipv_counts *value; +unsigned int type; +unsigned int max_entries; +} btf_map SEC(".maps") = { + .type = BPF_MAP_TYPE_ARRAY, + .max_entries = 4, +}; + +struct dummy_tracepoint_args { +unsigned long long pad; +struct sock *sock; +}; + +__attribute__((noinline)) +static int test_long_fname_2 (struct dummy_tracepoint_args *arg) +{ +struct ipv_counts *counts; +int key =0 ; + +if (!arg->sock) +return 0 ; + + counts =bpf_map_lookup_elem (&btf_map, &key); +if (!counts) +return 0 ; + + counts->v6++; + +/* just verify we can reference both maps */ + counts =bpf_map_lookup_elem (&btf_map_legacy, &key); +if (!counts) +return 0 ; + +return 0 ; +} + +__attribute__((noinline)) +static int test_long_fname_1 (struct dummy_tracepoint_args *arg) +{ +return test_long_fname_2 (arg); +} + +SEC("dummy_tracepoint") +int _dummy_tracepoint (struct dummy_tracepoint_args *arg) +{ +return test_long_fname_1 (arg); +} + +char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/test_btf.c +3 -7
@@ -4016,13 +4016,9 @@ struct btf_file_test { };static struct btf_file_test file_tests[] = { -{ - .file ="test_btf_haskv.o" , -}, -{ - .file ="test_btf_nokv.o" , - .btf_kv_notfound = true, -}, + { .file ="test_btf_haskv.o" , }, + { .file ="test_btf_newkv.o" , }, + { .file ="test_btf_nokv.o" , .btf_kv_notfound = true, }, };static int do_test_file (unsigned int test_num)
Signature · 1 line
2.17.1
RFC PATCH 8/8 selftests/bpf: switch tests to BTF-defined map definitions
In reply to Andrii NakryikoSwitch test map definition to new BTF-defined format.
--- tools/testing/selftests/bpf/progs/bpf_flow.c | 18 +++-- .../selftests/bpf/progs/get_cgroup_id_kern.c | 18 +++-- .../testing/selftests/bpf/progs/netcnt_prog.c | 22 +++--- .../selftests/bpf/progs/sample_map_ret0.c | 18 +++-- .../selftests/bpf/progs/socket_cookie_prog.c | 9 ++- .../bpf/progs/sockmap_verdict_prog.c | 36 +++++++--- .../bpf/progs/test_get_stack_rawtp.c | 27 ++++--- .../selftests/bpf/progs/test_global_data.c | 27 ++++--- tools/testing/selftests/bpf/progs/test_l4lb.c | 45 ++++++++---- .../selftests/bpf/progs/test_l4lb_noinline.c | 45 ++++++++---- .../selftests/bpf/progs/test_map_in_map.c | 20 ++++-- .../selftests/bpf/progs/test_map_lock.c | 22 +++--- .../testing/selftests/bpf/progs/test_obj_id.c | 9 ++- .../bpf/progs/test_select_reuseport_kern.c | 45 ++++++++---- .../bpf/progs/test_send_signal_kern.c | 22 +++--- .../bpf/progs/test_skb_cgroup_id_kern.c | 9 ++- .../bpf/progs/test_sock_fields_kern.c | 60 +++++++++------- .../selftests/bpf/progs/test_spin_lock.c | 33 ++++----- .../bpf/progs/test_stacktrace_build_id.c | 44 ++++++++---- .../selftests/bpf/progs/test_stacktrace_map.c | 40 +++++++---- .../testing/selftests/bpf/progs/test_tc_edt.c | 9 ++- .../bpf/progs/test_tcp_check_syncookie_kern.c | 9 ++- .../selftests/bpf/progs/test_tcp_estats.c | 9 ++- .../selftests/bpf/progs/test_tcpbpf_kern.c | 18 +++-- .../selftests/bpf/progs/test_tcpnotify_kern.c | 18 +++-- tools/testing/selftests/bpf/progs/test_xdp.c | 18 +++-- .../selftests/bpf/progs/test_xdp_noinline.c | 60 ++++++++++------ .../selftests/bpf/test_queue_stack_map.h | 20 ++++-- .../testing/selftests/bpf/test_sockmap_kern.h | 72 +++++++++++++------ 29 files changed, 526 insertions(+), 276 deletions(-)
tools/testing/selftests/bpf/progs/bpf_flow.c +13 -5
@@ -57,17 +57,25 @@ struct frag_hdr {__be32 identification; }; -struct bpf_map_def SEC("maps") jmp_table = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} jmp_table SEC(".maps") = { .type = BPF_MAP_TYPE_PROG_ARRAY, + .max_entries = 8, .key_size = sizeof(__u32), .value_size = sizeof(__u32), - .max_entries =8 }; -struct bpf_map_def SEC("maps") last_dissection = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct bpf_flow_keys *value; +} last_dissection SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(struct bpf_flow_keys), .max_entries = 1, };
tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c +12 -6
@@ -4,17 +4,23 @@#include <linux/bpf.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") cg_ids = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} cg_ids SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 1, }; -struct bpf_map_def SEC("maps") pidmap = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u32 *value; +} pidmap SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u32), .max_entries = 1, };
tools/testing/selftests/bpf/progs/netcnt_prog.c +10 -12
@@ -10,24 +10,22 @@#define REFRESH_TIME_NS 100000000#define NS_PER_SEC 1000000000 -struct bpf_map_def SEC("maps") percpu_netcnt = { +struct { +__u32 type; +struct bpf_cgroup_storage_key *key; +struct percpu_net_cnt *value; +} percpu_netcnt SEC(".maps") = { .type = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, - .key_size = sizeof(struct bpf_cgroup_storage_key), - .value_size = sizeof(struct percpu_net_cnt), }; -BPF_ANNOTATE_KV_PAIR(percpu_netcnt, struct bpf_cgroup_storage_key, - struct percpu_net_cnt); - -struct bpf_map_def SEC("maps") netcnt = { +struct { +__u32 type; +struct bpf_cgroup_storage_key *key; +struct net_cnt *value; +} netcnt SEC(".maps") = { .type =BPF_MAP_TYPE_CGROUP_STORAGE , - .key_size = sizeof(struct bpf_cgroup_storage_key), - .value_size = sizeof(struct net_cnt), }; -BPF_ANNOTATE_KV_PAIR(netcnt, struct bpf_cgroup_storage_key, - struct net_cnt); - SEC("cgroup/skb")int bpf_nextcnt (struct __sk_buff *skb) {
tools/testing/selftests/bpf/progs/sample_map_ret0.c +12 -6
@@ -2,17 +2,23 @@#include <linux/bpf.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") htab = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +long *value; +} htab SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(__u32), - .value_size = sizeof(long), .max_entries = 2, }; -struct bpf_map_def SEC("maps") array = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +long *value; +} array SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(long), .max_entries = 2, };
tools/testing/selftests/bpf/progs/socket_cookie_prog.c +6 -3
@@ -7,10 +7,13 @@#include "bpf_helpers.h" #include "bpf_endian.h" -struct bpf_map_def SEC("maps") socket_cookies = { +struct { +__u32 type; +__u32 max_entries; +__u64 *key; +__u32 *value; +} socket_cookies SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(__u64), - .value_size = sizeof(__u32), .max_entries = 1 << 8, };
tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c +27 -9
@@ -5,31 +5,49 @@ int _version SEC("version") = 1; -struct bpf_map_def SEC("maps") sock_map_rx = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} sock_map_rx SEC(".maps") = { .type = BPF_MAP_TYPE_SOCKMAP, + .max_entries = 20, .key_size = sizeof(int), .value_size = sizeof(int), - .max_entries = 20, }; -struct bpf_map_def SEC("maps") sock_map_tx = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} sock_map_tx SEC(".maps") = { .type = BPF_MAP_TYPE_SOCKMAP, + .max_entries = 20, .key_size = sizeof(int), .value_size = sizeof(int), - .max_entries = 20, }; -struct bpf_map_def SEC("maps") sock_map_msg = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} sock_map_msg SEC(".maps") = { .type = BPF_MAP_TYPE_SOCKMAP, + .max_entries = 20, .key_size = sizeof(int), .value_size = sizeof(int), - .max_entries = 20, }; -struct bpf_map_def SEC("maps") sock_map_break = { +struct { +__u32 type; +__u32 max_entries; +int *key; +int *value; +} sock_map_break SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(int), - .value_size = sizeof(int), .max_entries = 20, };
tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c +19 -8
@@ -15,17 +15,25 @@ struct stack_trace_t {struct bpf_stack_build_id user_stack_buildid[MAX_STACK_RAWTP ]; }; -struct bpf_map_def SEC("maps") perfmap = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} perfmap SEC(".maps") = { .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, + .max_entries = 2, .key_size = sizeof(int), .value_size = sizeof(__u32), - .max_entries = 2, }; -struct bpf_map_def SEC("maps") stackdata_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct stack_trace_t *value; +} stackdata_map SEC(".maps") = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(struct stack_trace_t), .max_entries = 1, };
@@ -47,10 +55,13 @@ struct bpf_map_def SEC("maps") stackdata_map = {* issue and avoid complicated C programming massaging. * This is an acceptable workaround since there is one entry here. */ -struct bpf_map_def SEC("maps") rawdata_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 (*value)[2 *MAX_STACK_RAWTP ]; +} rawdata_map SEC(".maps") = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .key_size = sizeof(__u32), - .value_size = MAX_STACK_RAWTP * sizeof(__u64) * 2, .max_entries = 1, };
tools/testing/selftests/bpf/progs/test_global_data.c +18 -9
@@ -7,17 +7,23 @@#include "bpf_helpers.h" -struct bpf_map_def SEC("maps") result_number = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} result_number SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 11, }; -struct bpf_map_def SEC("maps") result_string = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +const char (*value)[32 ]; +} result_string SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = 32, .max_entries = 5, };
@@ -27,10 +33,13 @@ struct foo {__u64 c; }; -struct bpf_map_def SEC("maps") result_struct = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct foo *value; +} result_struct SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(struct foo), .max_entries = 5, };
tools/testing/selftests/bpf/progs/test_l4lb.c +30 -15
68 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_l4lb_noinline.c +30 -15
68 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_map_in_map.c +14 -6
@@ -5,22 +5,30 @@#include <linux/types.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") mim_array = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} mim_array SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY_OF_MAPS, + .max_entries = 1, .key_size = sizeof(int),/* must be sizeof(__u32) for map in map */ .value_size = sizeof(__u32), - .max_entries = 1, - .map_flags = 0, }; -struct bpf_map_def SEC("maps") mim_hash = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} mim_hash SEC(".maps") = { .type = BPF_MAP_TYPE_HASH_OF_MAPS, + .max_entries = 1, .key_size = sizeof(int),/* must be sizeof(__u32) for map in map */ .value_size =sizeof (__u32), - .max_entries = 1, - .map_flags = 0, };SEC ("xdp_mimtest" )
tools/testing/selftests/bpf/progs/test_map_lock.c +12 -10
@@ -11,29 +11,31 @@ struct hmap_elem {int var[VAR_NUM ]; }; -struct bpf_map_def SEC("maps") hash_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct hmap_elem *value; +} hash_map SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(int), - .value_size = sizeof(struct hmap_elem), .max_entries = 1, }; -BPF_ANNOTATE_KV_PAIR(hash_map, int, struct hmap_elem); -struct array_elem {struct bpf_spin_lock lock;int var[VAR_NUM ]; }; -struct bpf_map_def SEC("maps") array_map = { +struct { +__u32 type; +__u32 max_entries; +int *key; +struct array_elem *value; +} array_map SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(int), - .value_size = sizeof(struct array_elem), .max_entries =1 , }; -BPF_ANNOTATE_KV_PAIR(array_map, int, struct array_elem); - SEC("map_lock_demo")int bpf_map_lock_test (struct __sk_buff *skb) {
tools/testing/selftests/bpf/progs/test_obj_id.c +6 -3
@@ -16,10 +16,13 @@ int _version SEC("version") = 1; -struct bpf_map_def SEC("maps") test_map_id = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} test_map_id SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 1, };
tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c +31 -14
69 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_send_signal_kern.c +12 -10
@@ -4,24 +4,26 @@#include <linux/version.h> #include "bpf_helpers.h" -struct bpf_map_def SEC("maps") info_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} info_map SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 1, }; -BPF_ANNOTATE_KV_PAIR (info_map, __u32, __u64); - -struct bpf_map_def SEC("maps") status_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} status_map SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 1, }; -BPF_ANNOTATE_KV_PAIR (status_map, __u32, __u64); - SEC("send_signal_demo")int bpf_send_signal_test (void *ctx) {
tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c +6 -3
@@ -10,10 +10,13 @@#define NUM_CGROUP_LEVELS 4 -struct bpf_map_def SEC("maps") cgroup_ids = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} cgroup_ids SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = NUM_CGROUP_LEVELS, };
tools/testing/selftests/bpf/progs/test_sock_fields_kern.c +36 -24
93 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_spin_lock.c +17 -16
@@ -10,30 +10,29 @@ struct hmap_elem {int test_padding; }; -struct bpf_map_def SEC("maps") hmap = { +struct { +__u32 type; +__u32 max_entries; +int *key; +struct hmap_elem *value; +} hmap SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(int), - .value_size = sizeof(struct hmap_elem), .max_entries = 1, }; -BPF_ANNOTATE_KV_PAIR(hmap, int, struct hmap_elem); - -struct cls_elem {struct bpf_spin_lock lock;volatile int cnt; }; -struct bpf_map_def SEC("maps") cls_map = { +struct { +__u32 type; +struct bpf_cgroup_storage_key *key; +struct cls_elem *value; +} cls_map SEC(".maps") = { .type = BPF_MAP_TYPE_CGROUP_STORAGE, - .key_size = sizeof(struct bpf_cgroup_storage_key), - .value_size = sizeof(struct cls_elem), }; -BPF_ANNOTATE_KV_PAIR(cls_map, struct bpf_cgroup_storage_key, - struct cls_elem); -struct bpf_vqueue {struct bpf_spin_lock lock;/* 4 byte hole */
@@ -42,14 +41,16 @@ struct bpf_vqueue {unsigned int rate; }; -struct bpf_map_def SEC("maps") vqueue = { +struct { +__u32 type; +__u32 max_entries; +int *key; +struct bpf_vqueue *value; +} vqueue SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(int), - .value_size = sizeof(struct bpf_vqueue), .max_entries = 1, }; -BPF_ANNOTATE_KV_PAIR(vqueue, int, struct bpf_vqueue);#define CREDIT_PER_NS (delta, rate) (((delta) * rate) >> 20)SEC ("spin_lock_demo" )
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +30 -14
64 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_stacktrace_map.c +28 -12
@@ -8,31 +8,47 @@#define PERF_MAX_STACK_DEPTH 127#endif -struct bpf_map_def SEC("maps") control_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u32 *value; +} control_map SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u32), .max_entries = 1, }; -struct bpf_map_def SEC("maps") stackid_hmap = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u32 *value; +} stackid_hmap SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(__u32), - .value_size = sizeof(__u32), .max_entries = 16384, }; -struct bpf_map_def SEC("maps") stackmap = { +typedef __u64 stack_trace_t [PERF_MAX_STACK_DEPTH ]; + +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} stackmap SEC(".maps") = { .type = BPF_MAP_TYPE_STACK_TRACE, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64) * PERF_MAX_STACK_DEPTH, .max_entries = 16384, + .key_size = sizeof(__u32), + .value_size = sizeof(stack_trace_t), }; -struct bpf_map_def SEC("maps") stack_amap = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 (*value)[PERF_MAX_STACK_DEPTH ]; +} stack_amap SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64) * PERF_MAX_STACK_DEPTH, .max_entries = 16384, };
tools/testing/selftests/bpf/progs/test_tc_edt.c +6 -3
@@ -16,10 +16,13 @@#define THROTTLE_RATE_BPS (5 * 1000 * 1000)/* flow_key => last_tstamp timestamp used */ -struct bpf_map_def SEC("maps") flow_map = { +struct { +__u32 type; +__u32 max_entries; +uint32_t *key; +uint64_t *value; +} flow_map SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint64_t), .max_entries = 1, };
tools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c +6 -3
@@ -16,10 +16,13 @@#include "bpf_helpers.h" #include "bpf_endian.h" -struct bpf_map_def SEC("maps") results = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} results SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 1, };
tools/testing/selftests/bpf/progs/test_tcp_estats.c +6 -3
@@ -148,10 +148,13 @@ struct tcp_estats_basic_event {struct tcp_estats_conn_id conn_id; }; -struct bpf_map_def SEC("maps") ev_record_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct tcp_estats_basic_event *value; +} ev_record_map SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(__u32), - .value_size = sizeof(struct tcp_estats_basic_event), .max_entries = 1024, };
tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c +12 -6
@@ -14,17 +14,23 @@#include "bpf_endian.h" #include "test_tcpbpf.h" -struct bpf_map_def SEC("maps") global_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct tcpbpf_globals *value; +} global_map SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(struct tcpbpf_globals), .max_entries = 4, }; -struct bpf_map_def SEC("maps") sockopt_results = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +int *value; +} sockopt_results SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(int), .max_entries = 2, };
tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c +13 -5
@@ -14,18 +14,26 @@#include "bpf_endian.h" #include "test_tcpnotify.h" -struct bpf_map_def SEC("maps") global_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +struct tcpnotify_globals *value; +} global_map SEC(".maps") = { .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(struct tcpnotify_globals), .max_entries = 4, }; -struct bpf_map_def SEC("maps") perf_event_map = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} perf_event_map SEC(".maps") = { .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, + .max_entries = 2, .key_size = sizeof(int), .value_size = sizeof(__u32), - .max_entries = 2, }; int _version SEC("version") = 1;
tools/testing/selftests/bpf/progs/test_xdp.c +12 -6
@@ -22,17 +22,23 @@ int _version SEC("version") = 1; -struct bpf_map_def SEC("maps") rxcnt = { +struct { +__u32 type; +__u32 max_entries; +__u32 *key; +__u64 *value; +} rxcnt SEC(".maps") = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, - .key_size = sizeof(__u32), - .value_size = sizeof(__u64), .max_entries = 256, }; -struct bpf_map_def SEC("maps") vip2tnl = { +struct { +__u32 type; +__u32 max_entries; +struct vip *key; +struct iptnl_info *value; +} vip2tnl SEC(".maps") = { .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(struct vip), - .value_size = sizeof(struct iptnl_info), .max_entries = MAX_IPTNL_ENTRIES, };
tools/testing/selftests/bpf/progs/test_xdp_noinline.c +37 -23
89 lines not on this page · raw message
tools/testing/selftests/bpf/test_queue_stack_map.h +14 -6
@@ -10,20 +10,28 @@ int _version SEC("version") = 1; -struct bpf_map_def __attribute__ ((section ("maps" ), used)) map_in = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} map_in SEC(".maps") = { .type = MAP_TYPE, + .max_entries = 32, .key_size = 0, .value_size = sizeof(__u32), - .max_entries =32 , - .map_flags =0 , }; -struct bpf_map_def __attribute__ ((section ("maps" ), used)) map_out = { +struct { +__u32 type; +__u32 max_entries; +__u32 key_size; +__u32 value_size; +} map_out SEC(".maps") = { .type = MAP_TYPE, + .max_entries = 32, .key_size = 0, .value_size =sizeof (__u32), - .max_entries =32 , - .map_flags =0 , };SEC ("test" )
tools/testing/selftests/bpf/test_sockmap_kern.h +51 -21
110 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 74 lines · Andrii Nakryiko
This patch set implements initial version (as discussed at LSF/MM2019 conference) of a new way to specify BPF maps, relying on BTF type information, which allows for easy extensibility, preserving forward and backward compatibility. See details and examples in description for patch #6.
Patch #1 centralizes commonly used min/max macro in
libbpf_internal.h. Patch #2 extracts .BTF and .BTF.ext loading loging fromelf_collect(). Patch #3 refactors map initialization logic into user-provided maps and global data maps, in preparation to adding another way (BTF-defined maps). Patch #4 adds support for map definitions in multiple ELF sections and deprecatesbpf_object__find_map_by_offset()API which doesn't appear to be used anymore and makes assumption that all map definitions reside in single ELF section.
Patch #5 splits BTF intialization from sanitization/loading into kernel to preserve original BTF at the time of map initialization.
Patch #6 adds support for BTF-defined maps.
Patch #7 adds new test for BTF-defined map definition.
Patch #8 converts test BPF map definitions to use BTF way.
rfc->v1:
- error out on unknown field by default (Stanislav, Jakub, Lorenz);Andrii Nakryiko (8):
libbpf: add common min/max macro tolibbpf_internal.h
libbpf: extract BTF loading and simplify ELF parsing logic
libbpf: refactor map initialization
libbpf: identify maps by section index in addition to offset
libbpf: split initialization and loading of BTF
libbpf: allow specifying map definitions using BTF selftests/bpf: add test for BTF-defined maps selftests/bpf: switch tests to BTF-defined map definitionstools/lib/bpf/bpf.c | 7 +- tools/lib/bpf/bpf_prog_linfo.c | 5 +- tools/lib/bpf/btf.c | 3 - tools/lib/bpf/btf.h | 1 + tools/lib/bpf/btf_dump.c | 3 - tools/lib/bpf/libbpf.c | 767 +++++++++++++----- tools/lib/bpf/libbpf_internal.h | 7 + tools/testing/selftests/bpf/progs/bpf_flow.c | 18 +- .../selftests/bpf/progs/get_cgroup_id_kern.c | 18 +- .../testing/selftests/bpf/progs/netcnt_prog.c | 22 +- .../selftests/bpf/progs/sample_map_ret0.c | 18 +- .../selftests/bpf/progs/socket_cookie_prog.c | 9 +- .../bpf/progs/sockmap_verdict_prog.c | 36 +- .../selftests/bpf/progs/test_btf_newkv.c | 73 ++ .../bpf/progs/test_get_stack_rawtp.c | 27 +- .../selftests/bpf/progs/test_global_data.c | 27 +- tools/testing/selftests/bpf/progs/test_l4lb.c | 45 +- .../selftests/bpf/progs/test_l4lb_noinline.c | 45 +- .../selftests/bpf/progs/test_map_in_map.c | 20 +- .../selftests/bpf/progs/test_map_lock.c | 22 +- .../testing/selftests/bpf/progs/test_obj_id.c | 9 +- .../bpf/progs/test_select_reuseport_kern.c | 45 +- .../bpf/progs/test_send_signal_kern.c | 22 +- .../bpf/progs/test_skb_cgroup_id_kern.c | 9 +- .../bpf/progs/test_sock_fields_kern.c | 60 +- .../selftests/bpf/progs/test_spin_lock.c | 33 +- .../bpf/progs/test_stacktrace_build_id.c | 44 +- .../selftests/bpf/progs/test_stacktrace_map.c | 40 +- .../testing/selftests/bpf/progs/test_tc_edt.c | 9 +- .../bpf/progs/test_tcp_check_syncookie_kern.c | 9 +- .../selftests/bpf/progs/test_tcp_estats.c | 9 +- .../selftests/bpf/progs/test_tcpbpf_kern.c | 18 +- .../selftests/bpf/progs/test_tcpnotify_kern.c | 18 +- tools/testing/selftests/bpf/progs/test_xdp.c | 18 +- .../selftests/bpf/progs/test_xdp_noinline.c | 60 +- tools/testing/selftests/bpf/test_btf.c | 10 +- .../selftests/bpf/test_queue_stack_map.h | 20 +- .../testing/selftests/bpf/test_sockmap_kern.h | 72 +- 38 files changed, 1187 insertions(+), 491 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_btf_newkv.c
Quoted 3 lines
--
2.17.1
Argh, forgot to remove RFC part, will resend, sorry for spam!