• Andrii Nakryiko's avatar
    bpf: Support symbolic BPF FS delegation mount options · 6c1752e0
    Andrii Nakryiko authored
    Besides already supported special "any" value and hex bit mask, support
    string-based parsing of delegation masks based on exact enumerator
    names. Utilize BTF information of `enum bpf_cmd`, `enum bpf_map_type`,
    `enum bpf_prog_type`, and `enum bpf_attach_type` types to find supported
    symbolic names (ignoring __MAX_xxx guard values and stripping repetitive
    prefixes like BPF_ for cmd and attach types, BPF_MAP_TYPE_ for maps, and
    BPF_PROG_TYPE_ for prog types). The case doesn't matter, but it is
    normalized to lower case in mount option output. So "PROG_LOAD",
    "prog_load", and "MAP_create" are all valid values to specify for
    delegate_cmds options, "array" is among supported for map types, etc.
    
    Besides supporting string values, we also support multiple values
    specified at the same time, using colon (':') separator.
    
    There are corresponding changes on bpf_show_options side to use known
    values to print them in human-readable format, falling back to hex mask
    printing, if there are any unrecognized bits. This shouldn't be
    necessary when enum BTF information is present, but in general we should
    always be able to fall back to this even if kernel was built without BTF.
    As mentioned, emitted symbolic names are normalized to be all lower case.
    
    Example below shows various ways to specify delegate_cmds options
    through mount command and how mount options are printed back:
    
    12/14 14:39:07.604
    vmuser@archvm:~/local/linux/tools/testing/selftests/bpf
    $ mount | rg token
    
      $ sudo mkdir -p /sys/fs/bpf/token
      $ sudo mount -t bpf bpffs /sys/fs/bpf/token \
                   -o delegate_cmds=prog_load:MAP_CREATE \
                   -o delegate_progs=kprobe \
                   -o delegate_attachs=xdp
      $ mount | grep token
      bpffs on /sys/fs/bpf/token type bpf (rw,relatime,delegate_cmds=map_create:prog_load,delegate_progs=kprobe,delegate_attachs=xdp)
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
    Link: https://lore.kernel.org/bpf/20240124022127.2379740-20-andrii@kernel.org
    6c1752e0
inode.c 23.7 KB