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) This fits the usecase described here: https://lore.kernel.org/bpf/20220830231349.46c49c50@blondie/