• Kumar Kartikeya Dwivedi's avatar
    bpf: Implement support for adding hidden subprogs · 335d1c5b
    Kumar Kartikeya Dwivedi authored
    Introduce support in the verifier for generating a subprogram and
    include it as part of a BPF program dynamically after the do_check phase
    is complete. The first user will be the next patch which generates
    default exception callbacks if none are set for the program. The phase
    of invocation will be do_misc_fixups. Note that this is an internal
    verifier function, and should be used with instruction blocks which
    uphold the invariants stated in check_subprogs.
    
    Since these subprogs are always appended to the end of the instruction
    sequence of the program, it becomes relatively inexpensive to do the
    related adjustments to the subprog_info of the program. Only the fake
    exit subprogram is shifted forward, making room for our new subprog.
    
    This is useful to insert a new subprogram, get it JITed, and obtain its
    function pointer. The next patch will use this functionality to insert a
    default exception callback which will be invoked after unwinding the
    stack.
    
    Note that these added subprograms are invisible to userspace, and never
    reported in BPF_OBJ_GET_INFO_BY_ID etc. For now, only a single
    subprogram is supported, but more can be easily supported in the future.
    
    To this end, two function counts are introduced now, the existing
    func_cnt, and real_func_cnt, the latter including hidden programs. This
    allows us to conver the JIT code to use the real_func_cnt for management
    of resources while syscall path continues working with existing
    func_cnt.
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20230912233214.1518551-4-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    335d1c5b
verifier.c 586 KB