Re: [PATCH bpf-next v4 12/21] bpf: add PTR_TO_BTF_ID_OR_NULL support

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

 



On Sat, May 9, 2020 at 10:19 PM Yonghong Song <yhs@xxxxxx> wrote:
>
>
>
> On 5/9/20 5:50 PM, Alexei Starovoitov wrote:
> > On Sat, May 09, 2020 at 10:59:12AM -0700, Yonghong Song wrote:
> >> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> >> index a2cfba89a8e1..c490fbde22d4 100644
> >> --- a/kernel/bpf/btf.c
> >> +++ b/kernel/bpf/btf.c
> >> @@ -3790,7 +3790,10 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
> >>              return true;
> >>
> >>      /* this is a pointer to another type */
> >> -    info->reg_type = PTR_TO_BTF_ID;
> >> +    if (off != 0 && prog->aux->btf_id_or_null_non0_off)
> >> +            info->reg_type = PTR_TO_BTF_ID_OR_NULL;
> >> +    else
> >> +            info->reg_type = PTR_TO_BTF_ID;
> >
> > I think the verifier should be smarter than this.
> > It's too specific and inflexible. All ctx fields of bpf_iter execpt first
> > will be such ? let's figure out a different way to tell verifier about this.
> > How about using typedef with specific suffix? Like:
> > typedef struct bpf_map *bpf_map_or_null;
> >   struct bpf_iter__bpf_map {
> >     struct bpf_iter_meta *meta;
> >     bpf_map_or_null map;
> >   };
> > or use a union with specific second member? Like:
> >   struct bpf_iter__bpf_map {
> >     struct bpf_iter_meta *meta;
> >     union {
> >       struct bpf_map *map;
> >       long null;
> >     };
> >   };
>
> I have an alternative approach to refactor this for future
> support for map elements as well.
>
> For example, for bpf_map_elements iterator the prog context type
> can be
>      struct bpf_iter_bpf_map_elem {
>         struct bpf_iter_meta *meta;
>         strruct bpf_map *map;
>         <key type>  *key;
>         <value type> *val;
>     };
>
> target will pass the following information to bpf_iter registration:
>     arg 1: PTR_TO_BTF_ID
>     arg 2: PTR_TO_BTF_ID_OR_NULL
>     arg 3: PTR_TO_BUFFER
>     arg 4: PTR_TO_BUFFER
>
> verifier will retrieve the reg_type from target.

you mean to introduce something like 'struct bpf_func_proto'
that describes types of helpers, but instead something similar
to clarify the types in ctx ? That should work. Thanks



[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