bpf: Remove hard-coded btf_vmlinux assumption from BPF verifier
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 3 Dec 2020 20:46:29 +0000 (12:46 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Dec 2020 01:38:21 +0000 (17:38 -0800)
commit22dc4a0f5ed11b6dc8fd73a0892fa0ea1a4c3cdf
treea802bb344f21f752808b58db3223d7ce541aa14f
parent6bcd39d366b64318562785d5b47c2837e3a53ae5
bpf: Remove hard-coded btf_vmlinux assumption from BPF verifier

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: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201203204634.1325171-10-andrii@kernel.org
include/linux/bpf.h
include/linux/bpf_verifier.h
include/linux/btf.h
kernel/bpf/btf.c
kernel/bpf/syscall.c
kernel/bpf/verifier.c
net/ipv4/bpf_tcp_ca.c