diff mbox series

[bpf-next,v2,2/5] libbpf: init btf_{key,value}_type_id on internal map open

Message ID 6d868b6effca2549681a9e42ccbdd71aac6287e8.1646957399.git.delyank@fb.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Subskeleton support for BPF libraries | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: kpsingh@kernel.org john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com yhs@fb.com netdev@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next success VM_Test

Commit Message

Delyan Kratunov March 11, 2022, 12:11 a.m. UTC
For internal maps, look up the key and value btf types on
open() and not load(), so that `bpf_map_btf_value_type_id`
is usable in `bpftool gen`.

Signed-off-by: Delyan Kratunov <delyank@fb.com>
---
 tools/lib/bpf/libbpf.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Andrii Nakryiko March 11, 2022, 10:42 p.m. UTC | #1
On Thu, Mar 10, 2022 at 4:12 PM Delyan Kratunov <delyank@fb.com> wrote:
>
> For internal maps, look up the key and value btf types on
> open() and not load(), so that `bpf_map_btf_value_type_id`
> is usable in `bpftool gen`.
>
> Signed-off-by: Delyan Kratunov <delyank@fb.com>
> ---
>  tools/lib/bpf/libbpf.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index b6f11ce0d6bc..3fb9c926fe6e 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1517,6 +1517,9 @@ static char *internal_map_name(struct bpf_object *obj, const char *real_name)
>         return strdup(map_name);
>  }
>
> +static int
> +bpf_map_find_btf_info(struct bpf_object *obj, struct bpf_map *map);
> +
>  static int
>  bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
>                               const char *real_name, int sec_idx, void *data, size_t data_sz)
> @@ -1564,6 +1567,11 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
>                 return err;
>         }
>
> +       err = bpf_map_find_btf_info(obj, map);

is there any reason to still do bpf_map_find_btf_info() in
bpf_object__create_map()? It's also non-uniform, legacy user maps
won't have btf_key_type_id/btf_value_type_id set until load, while
internal maps (and BTF-defined maps) will. Let's make it uniform and
call bpf_map_find_btf_info() from bpf_object__init_user_maps() early
on as well (and not do that at all in bpf_object__create_map())

> +       /* intentionally ignoring err, failures are fine because of
> +        * maps like .rodata.str1.1
> +        */

if the intention is to explicitly ignore error, then the most explicit
way to express this is:

(void)func_that_can_return_error(...);

> +
>         if (data)
>                 memcpy(map->mmaped, data, data_sz);
>
> --
> 2.34.1
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b6f11ce0d6bc..3fb9c926fe6e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1517,6 +1517,9 @@  static char *internal_map_name(struct bpf_object *obj, const char *real_name)
 	return strdup(map_name);
 }
 
+static int
+bpf_map_find_btf_info(struct bpf_object *obj, struct bpf_map *map);
+
 static int
 bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
 			      const char *real_name, int sec_idx, void *data, size_t data_sz)
@@ -1564,6 +1567,11 @@  bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
 		return err;
 	}
 
+	err = bpf_map_find_btf_info(obj, map);
+	/* intentionally ignoring err, failures are fine because of
+	 * maps like .rodata.str1.1
+	 */
+
 	if (data)
 		memcpy(map->mmaped, data, data_sz);