• Kumar Kartikeya Dwivedi's avatar
    libbpf: Support kernel module function calls · 9dbe6015
    Kumar Kartikeya Dwivedi authored
    This patch adds libbpf support for kernel module function call support.
    The fd_array parameter is used during BPF program load to pass module
    BTFs referenced by the program. insn->off is set to index into this
    array, but starts from 1, because insn->off as 0 is reserved for
    btf_vmlinux.
    
    We try to use existing insn->off for a module, since the kernel limits
    the maximum distinct module BTFs for kfuncs to 256, and also because
    index must never exceed the maximum allowed value that can fit in
    insn->off (INT16_MAX). In the future, if kernel interprets signed offset
    as unsigned for kfunc calls, this limit can be increased to UINT16_MAX.
    
    Also introduce a btf__find_by_name_kind_own helper to start searching
    from module BTF's start id when we know that the BTF ID is not present
    in vmlinux BTF (in find_ksym_btf_id).
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20211002011757.311265-7-memxor@gmail.com
    9dbe6015
btf.c 122 KB