Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fd_array_cnt attribute for BPF_PROG_LOAD #8148

Closed

Commits on Dec 3, 2024

  1. bpf: add a __btf_get_by_fd helper

    Add a new helper to get a pointer to a struct btf from a file
    descriptor. This helper doesn't increase a refcnt. Add a comment
    explaining this and pointing to a corresponding function which
    does take a reference.
    
    Signed-off-by: Anton Protopopov <[email protected]>
    Acked-by: Andrii Nakryiko <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    e1edce4 View commit details
    Browse the repository at this point in the history
  2. bpf: move map/prog compatibility checks

    Move some inlined map/prog compatibility checks from the
    resolve_pseudo_ldimm64() function to the dedicated
    check_map_prog_compatibility() function. Call the latter function
    from the add_used_map_from_fd() function directly.
    
    This simplifies code and optimizes logic a bit, as before these
    changes the check_map_prog_compatibility() function was executed on
    every map usage, which doesn't make sense, as it doesn't include any
    per-instruction checks, only map type vs. prog type.
    
    (This patch also simplifies a consequent patch which will call the
    add_used_map_from_fd() function from another code path.)
    
    Signed-off-by: Anton Protopopov <[email protected]>
    Acked-by: Andrii Nakryiko <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    1fb233f View commit details
    Browse the repository at this point in the history
  3. bpf: add fd_array_cnt attribute for prog_load

    The fd_array attribute of the BPF_PROG_LOAD syscall may contain a set
    of file descriptors: maps or btfs. This field was introduced as a
    sparse array. Introduce a new attribute, fd_array_cnt, which, if
    present, indicates that the fd_array is a continuous array of the
    corresponding length.
    
    If fd_array_cnt is non-zero, then every map in the fd_array will be
    bound to the program, as if it was used by the program. This
    functionality is similar to the BPF_PROG_BIND_MAP syscall, but such
    maps can be used by the verifier during the program load.
    
    Signed-off-by: Anton Protopopov <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    1aa96eb View commit details
    Browse the repository at this point in the history
  4. libbpf: prog load: allow to use fd_array_cnt

    Add new fd_array_cnt field to bpf_prog_load_opts
    and pass it in bpf_attr, if set.
    
    Signed-off-by: Anton Protopopov <[email protected]>
    Acked-by: Andrii Nakryiko <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    cb031c9 View commit details
    Browse the repository at this point in the history
  5. selftests/bpf: Add tests for fd_array_cnt

    Add a new set of tests to test the new field in PROG_LOAD-related
    part of bpf_attr: fd_array_cnt.
    
    Add the following test cases:
    
      * fd_array_cnt/no-fd-array: program is loaded in a normal
        way, without any fd_array present
    
      * fd_array_cnt/fd-array-ok: pass two extra non-used maps,
        check that they're bound to the program
    
      * fd_array_cnt/fd-array-dup-input: pass a few extra maps,
        only two of which are unique
    
      * fd_array_cnt/fd-array-ref-maps-in-array: pass a map in
        fd_array which is also referenced from within the program
    
      * fd_array_cnt/fd-array-trash-input: pass array with some trash
    
      * fd_array_cnt/fd-array-with-holes: pass an array with holes (fd=0)
    
      * fd_array_cnt/fd-array-2big: pass too large array
    
    All the tests above are using the bpf(2) syscall directly,
    no libbpf involved.
    
    Signed-off-by: Anton Protopopov <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    a3e8ada View commit details
    Browse the repository at this point in the history
  6. bpf: fix potential error return

    The bpf_remove_insns() function returns WARN_ON_ONCE(error), where
    error is a result of bpf_adj_branches(), and thus should be always 0
    However, if for any reason it is not 0, then it will be converted to
    boolean by WARN_ON_ONCE and returned to user space as 1, not an actual
    error value. Fix this by returning the original err after the WARN check.
    
    Signed-off-by: Anton Protopopov <[email protected]>
    Acked-by: Jiri Olsa <[email protected]>
    Acked-by: Andrii Nakryiko <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    07dce1a View commit details
    Browse the repository at this point in the history
  7. selftest/bpf: replace magic constants by macros

    Replace magic constants in a BTF structure initialization code by
    proper macros, as is done in other similar selftests.
    
    Signed-off-by: Anton Protopopov <[email protected]>
    Suggested-by: Eduard Zingerman <[email protected]>
    aspsk authored and Kernel Patches Daemon committed Dec 3, 2024
    Configuration menu
    Copy the full SHA
    684e931 View commit details
    Browse the repository at this point in the history