• Joanne Koong's avatar
    bpf: Add bpf_dynptr_clone · 361f129f
    Joanne Koong authored
    The cloned dynptr will point to the same data as its parent dynptr,
    with the same type, offset, size and read-only properties.
    
    Any writes to a dynptr will be reflected across all instances
    (by 'instance', this means any dynptrs that point to the same
    underlying data).
    
    Please note that data slice and dynptr invalidations will affect all
    instances as well. For example, if bpf_dynptr_write() is called on an
    skb-type dynptr, all data slices of dynptr instances to that skb
    will be invalidated as well (eg data slices of any clones, parents,
    grandparents, ...). Another example is if a ringbuf dynptr is submitted,
    any instance of that dynptr will be invalidated.
    
    Changing the view of the dynptr (eg advancing the offset or
    trimming the size) will only affect that dynptr and not affect any
    other instances.
    
    One example use case where cloning may be helpful is for hashing or
    iterating through dynptr data. Cloning will allow the user to maintain
    the original view of the dynptr for future use, while also allowing
    views to smaller subsets of the data after the offset is advanced or the
    size is trimmed.
    Signed-off-by: default avatarJoanne Koong <joannelkoong@gmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20230420071414.570108-5-joannelkoong@gmail.com
    361f129f
helpers.c 64.1 KB