• Eduard Zingerman's avatar
    libbpf: Sync progs autoload with maps autocreate for struct_ops maps · fe9d049c
    Eduard Zingerman authored
    Automatically select which struct_ops programs to load depending on
    which struct_ops maps are selected for automatic creation.
    E.g. for the BPF code below:
    
        SEC("struct_ops/test_1") int BPF_PROG(foo) { ... }
        SEC("struct_ops/test_2") int BPF_PROG(bar) { ... }
    
        SEC(".struct_ops.link")
        struct test_ops___v1 A = {
            .foo = (void *)foo
        };
    
        SEC(".struct_ops.link")
        struct test_ops___v2 B = {
            .foo = (void *)foo,
            .bar = (void *)bar,
        };
    
    And the following libbpf API calls:
    
        bpf_map__set_autocreate(skel->maps.A, true);
        bpf_map__set_autocreate(skel->maps.B, false);
    
    The autoload would be enabled for program 'foo' and disabled for
    program 'bar'.
    
    During load, for each struct_ops program P, referenced from some
    struct_ops map M:
    - set P.autoload = true if M.autocreate is true for some M;
    - set P.autoload = false if M.autocreate is false for all M;
    - don't change P.autoload, if P is not referenced from any map.
    
    Do this after bpf_object__init_kern_struct_ops_maps()
    to make sure that shadow vars assignment is done.
    Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20240306104529.6453-9-eddyz87@gmail.com
    fe9d049c
libbpf.c 363 KB