• Dave Marchevsky's avatar
    bpf: Centralize btf_field-specific initialization logic · 3e81740a
    Dave Marchevsky authored
    All btf_fields in an object are 0-initialized by memset in
    bpf_obj_init. This might not be a valid initial state for some field
    types, in which case kfuncs that use the type will properly initialize
    their input if it's been 0-initialized. Some BPF graph collection types
    and kfuncs do this: bpf_list_{head,node} and bpf_rb_node.
    
    An earlier patch in this series added the bpf_refcount field, for which
    the 0 state indicates that the refcounted object should be free'd.
    bpf_obj_init treats this field specially, setting refcount to 1 instead
    of relying on scattered "refcount is 0? Must have just been initialized,
    let's set to 1" logic in kfuncs.
    
    This patch extends this treatment to list and rbtree field types,
    allowing most scattered initialization logic in kfuncs to be removed.
    
    Note that bpf_{list_head,rb_root} may be inside a BPF map, in which case
    they'll be 0-initialized without passing through the newly-added logic,
    so scattered initialization logic must remain for these collection root
    types.
    Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
    Link: https://lore.kernel.org/r/20230415201811.343116-9-davemarchevsky@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    3e81740a
helpers.c 62.9 KB