Re: [PATCH bpf-next v3 11/15] libbpf: struct_ops in SEC("?.struct_ops") and SEC("?.struct_ops.link")

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 4, 2024 at 2:52 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> Allow using two new section names for struct_ops maps:
> - SEC("?.struct_ops")
> - SEC("?.struct_ops.link")
>
> To specify maps that have bpf_map->autocreate == false after open.
>
> Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
> ---
>  tools/lib/bpf/libbpf.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>

Please check that patch subject is <80, and perhaps shorten it a bit?

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 4ef3902e65db..c0212244bdf7 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -497,6 +497,8 @@ struct bpf_struct_ops {
>  #define KSYMS_SEC ".ksyms"
>  #define STRUCT_OPS_SEC ".struct_ops"
>  #define STRUCT_OPS_LINK_SEC ".struct_ops.link"
> +#define OPT_STRUCT_OPS_SEC "?.struct_ops"
> +#define OPT_STRUCT_OPS_LINK_SEC "?.struct_ops.link"
>

I wouldn't do this, see below


>  enum libbpf_map_type {
>         LIBBPF_MAP_UNSPEC,
> @@ -1324,6 +1326,15 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name,
>                         return -ENOMEM;
>                 map->btf_value_type_id = type_id;
>
> +               /* Follow same convention as for programs autoload:
> +                * SEC("?.struct_ops") means map is not created by default.
> +                */
> +               if (sec_name[0] == '?') {
> +                       map->autocreate = false;
> +                       /* from now on forget there was ? in section name */
> +                       sec_name++;
> +               }
> +
>                 map->def.type = BPF_MAP_TYPE_STRUCT_OPS;
>                 map->def.key_size = sizeof(int);
>                 map->def.value_size = type->size;
> @@ -3688,7 +3699,9 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
>                                 sec_desc->shdr = sh;
>                                 sec_desc->data = data;
>                         } else if (strcmp(name, STRUCT_OPS_SEC) == 0 ||
> -                                  strcmp(name, STRUCT_OPS_LINK_SEC) == 0) {
> +                                  strcmp(name, STRUCT_OPS_LINK_SEC) == 0 ||
> +                                  strcmp(name, OPT_STRUCT_OPS_SEC) == 0 ||
> +                                  strcmp(name, OPT_STRUCT_OPS_LINK_SEC) == 0) {

I'd do just

strcmp(name, "?" STRUCT_OPS_SEC) == 0 ||
strcmp(name, "?" STRUCT_OPS_LINK_SEC) == 0 ||


>                                 sec_desc->sec_type = SEC_ST_OPS;
>                                 sec_desc->shdr = sh;
>                                 sec_desc->data = data;
> @@ -3708,6 +3721,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
>                         if (!section_have_execinstr(obj, targ_sec_idx) &&
>                             strcmp(name, ".rel" STRUCT_OPS_SEC) &&
>                             strcmp(name, ".rel" STRUCT_OPS_LINK_SEC) &&
> +                           strcmp(name, ".rel" OPT_STRUCT_OPS_SEC) &&
> +                           strcmp(name, ".rel" OPT_STRUCT_OPS_LINK_SEC) &&

and similarly here, just use ".rel?" ?

>                             strcmp(name, ".rel" MAPS_ELF_SEC)) {
>                                 pr_info("elf: skipping relo section(%d) %s for section(%d) %s\n",
>                                         idx, name, targ_sec_idx,
> --
> 2.43.0
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux