Re: [PATCH bpf-next v2 18/18] bpf: enforce all maps having memory usage callback

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

 



On Thu, Feb 23, 2023 at 3:20 AM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Tue, Feb 21, 2023 at 5:47 PM Yafang Shao <laoar.shao@xxxxxxxxx> wrote:
> >
> > We have implemented memory usage callback for all maps, and we enforce
> > any newly added map having a callback as well. Show a warning if it
> > doesn't have.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> >  kernel/bpf/syscall.c | 10 +++-------
> >  1 file changed, 3 insertions(+), 7 deletions(-)
> >
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index e12b03e..d814d4e 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -775,13 +775,9 @@ static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)
> >  /* Show the memory usage of a bpf map */
> >  static u64 bpf_map_memory_usage(const struct bpf_map *map)
> >  {
> > -       unsigned long size;
> > -
> > -       if (map->ops->map_mem_usage)
> > -               return map->ops->map_mem_usage(map);
> > -
> > -       size = round_up(map->key_size + bpf_map_value_size(map), 8);
> > -       return round_up(map->max_entries * size, PAGE_SIZE);
> > +       if (WARN_ON_ONCE(!map->ops->map_mem_usage))
> > +               return 0;
>
> Since all maps are converted, let's do this check earlier.
> Like during find_and_alloc_map.
> And without WARN.

Good suggestion. I will do it.

-- 
Regards
Yafang



[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