Re: [PATCH bpf-next v1 5/8] bpf: Add bpf_dynptr_clone

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

 



On Fri, Sep 9, 2022 at 9:41 AM Shmulik Ladkani
<shmulik.ladkani@xxxxxxxxx> wrote:
>
> On Wed,  7 Sep 2022 17:02:51 -0700 Joanne Koong <joannelkoong@xxxxxxxxx> wrote:
>
> > Add a new helper, bpf_dynptr_clone, which clones a dynptr.
> >
> > The cloned dynptr will point to the same data as its parent dynptr,
> > with the same type, offset, size and read-only properties.
>
> [...]
>
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index 4ca07cf500d2..16973fa4d073 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -5508,6 +5508,29 @@ union bpf_attr {
> >   *   Return
> >   *           The offset of the dynptr on success, -EINVAL if the dynptr is
> >   *           invalid.
> > + *
> > + * long bpf_dynptr_clone(struct bpf_dynptr *ptr, struct bpf_dynptr *clone)
> > + *   Description
> > + *           Clone an initialized dynptr *ptr*. After this call, both *ptr*
> > + *           and *clone* will point to the same underlying data.
> > + *
>
> How about adding 'off' and 'len' parameters so that a view ("slice") of
> the dynptr can be created in a single call?
>
> Otherwise, for a simple slice creation, ebpf user needs to:
>   bpf_dynptr_clone(orig, clone)
>   bpf_dynptr_advance(clone, off)
>   trim_len = bpf_dynptr_get_size(clone) - len
>   bpf_dynptr_trim(clone, trim_len)

I like the idea, where 'off' is an offset from ptr's offset and 'len'
is the number of bytes to trim.

Btw, I will be traveling for the next ~6 weeks and won't have access
to a computer, so v2 will be sometime after that.

>
> This fits the usecase described here:
>   https://lore.kernel.org/bpf/20220830231349.46c49c50@blondie/



[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