• Andrii Nakryiko's avatar
    bpf: Remove hard-coded btf_vmlinux assumption from BPF verifier · 22dc4a0f
    Andrii Nakryiko authored
    Remove a permeating assumption thoughout BPF verifier of vmlinux BTF. Instead,
    wherever BTF type IDs are involved, also track the instance of struct btf that
    goes along with the type ID. This allows to gradually add support for kernel
    module BTFs and using/tracking module types across BPF helper calls and
    registers.
    
    This patch also renames btf_id() function to btf_obj_id() to minimize naming
    clash with using btf_id to denote BTF *type* ID, rather than BTF *object*'s ID.
    
    Also, altough btf_vmlinux can't get destructed and thus doesn't need
    refcounting, module BTFs need that, so apply BTF refcounting universally when
    BPF program is using BTF-powered attachment (tp_btf, fentry/fexit, etc). This
    makes for simpler clean up code.
    
    Now that BTF type ID is not enough to uniquely identify a BTF type, extend BPF
    trampoline key to include BTF object ID. To differentiate that from target
    program BPF ID, set 31st bit of type ID. BTF type IDs (at least currently) are
    not allowed to take full 32 bits, so there is no danger of confusing that bit
    with a valid BTF type ID.
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20201203204634.1325171-10-andrii@kernel.org
    22dc4a0f
verifier.c 347 KB