• Kui-Feng Lee's avatar
    bpf: Create links for BPF struct_ops maps. · 68b04864
    Kui-Feng Lee authored
    Make bpf_link support struct_ops.  Previously, struct_ops were always
    used alone without any associated links. Upon updating its value, a
    struct_ops would be activated automatically. Yet other BPF program
    types required to make a bpf_link with their instances before they
    could become active. Now, however, you can create an inactive
    struct_ops, and create a link to activate it later.
    
    With bpf_links, struct_ops has a behavior similar to other BPF program
    types. You can pin/unpin them from their links and the struct_ops will
    be deactivated when its link is removed while previously need someone
    to delete the value for it to be deactivated.
    
    bpf_links are responsible for registering their associated
    struct_ops. You can only use a struct_ops that has the BPF_F_LINK flag
    set to create a bpf_link, while a structs without this flag behaves in
    the same manner as before and is registered upon updating its value.
    
    The BPF_LINK_TYPE_STRUCT_OPS serves a dual purpose. Not only is it
    used to craft the links for BPF struct_ops programs, but also to
    create links for BPF struct_ops them-self.  Since the links of BPF
    struct_ops programs are only used to create trampolines internally,
    they are never seen in other contexts. Thus, they can be reused for
    struct_ops themself.
    
    To maintain a reference to the map supporting this link, we add
    bpf_struct_ops_link as an additional type. The pointer of the map is
    RCU and won't be necessary until later in the patchset.
    Signed-off-by: default avatarKui-Feng Lee <kuifeng@meta.com>
    Link: https://lore.kernel.org/r/20230323032405.3735486-4-kuifeng@meta.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
    68b04864
bpf_struct_ops.c 22.2 KB