Re: [PATCH RFC bpf-next v1 05/32] bpf: Support kptrs in local storage maps

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

 



On Fri, 9 Sept 2022 at 07:27, Martin KaFai Lau <martin.lau@xxxxxxxxx> wrote:
>
> On 9/4/22 1:41 PM, Kumar Kartikeya Dwivedi wrote:
> > diff --git a/include/linux/bpf_local_storage.h b/include/linux/bpf_local_storage.h
> > index 7ea18d4da84b..6786d00f004e 100644
> > --- a/include/linux/bpf_local_storage.h
> > +++ b/include/linux/bpf_local_storage.h
> > @@ -74,7 +74,7 @@ struct bpf_local_storage_elem {
> >       struct hlist_node snode;        /* Linked to bpf_local_storage */
> >       struct bpf_local_storage __rcu *local_storage;
> >       struct rcu_head rcu;
> > -     /* 8 bytes hole */
> > +     struct bpf_map *map;            /* Only set for bpf_selem_free_rcu */
>
> Instead of adding another map ptr and using the last 8 bytes hole,
>
> >       /* The data is stored in another cacheline to minimize
> >        * the number of cachelines access during a cache hit.
> >        */
> > diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
> > index 802fc15b0d73..4a725379d761 100644
> > --- a/kernel/bpf/bpf_local_storage.c
> > +++ b/kernel/bpf/bpf_local_storage.c
> > @@ -74,7 +74,8 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
> >                               gfp_flags | __GFP_NOWARN);
> >       if (selem) {
> >               if (value)
> > -                     memcpy(SDATA(selem)->data, value, smap->map.value_size);
> > +                     copy_map_value(&smap->map, SDATA(selem)->data, value);
> > +             /* No call to check_and_init_map_value as memory is zero init */
> >               return selem;
> >       }
> >
> > @@ -92,12 +93,27 @@ void bpf_local_storage_free_rcu(struct rcu_head *rcu)
> >       kfree_rcu(local_storage, rcu);
> >   }
> >
> > +static void check_and_free_fields(struct bpf_local_storage_elem *selem)
> > +{
> > +     if (map_value_has_kptrs(selem->map))
>
> could SDATA(selem)->smap->map be used here ?
>

Yeah, that should work. Thanks Martin.

> > +             bpf_map_free_kptrs(selem->map, SDATA(selem));
> > +}
> > +
> [...]



[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