]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Allow specifying a BTF ID per argument in function protos
authorLorenz Bauer <lmb@cloudflare.com>
Mon, 21 Sep 2020 12:12:20 +0000 (13:12 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Sep 2020 22:00:40 +0000 (15:00 -0700)
commit82018db636d9adbdc62e1c2e97bed5c9adefefa6
treed492819683666eba4815ed5d705e7a9cf281c3fa
parentf2fc15f7303f29c3e8fa4dd6878d700d78ec43bf
bpf: Allow specifying a BTF ID per argument in function protos

Function prototypes using ARG_PTR_TO_BTF_ID currently use two ways to signal
which BTF IDs are acceptable. First, bpf_func_proto.btf_id is an array of
IDs, one for each argument. This array is only accessed up to the highest
numbered argument that uses ARG_PTR_TO_BTF_ID and may therefore be less than
five arguments long. It usually points at a BTF_ID_LIST. Second, check_btf_id
is a function pointer that is called by the verifier if present. It gets the
actual BTF ID of the register, and the argument number we're currently checking.
It turns out that the only user check_arg_btf_id ignores the argument, and is
simply used to check whether the BTF ID has a struct sock_common at it's start.

Replace both of these mechanisms with an explicit BTF ID for each argument
in a function proto. Thanks to btf_struct_ids_match this is very flexible:
check_arg_btf_id can be replaced by requiring struct sock_common.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200921121227.255763-5-lmb@cloudflare.com
include/linux/bpf.h
kernel/bpf/bpf_inode_storage.c
kernel/bpf/btf.c
kernel/bpf/stackmap.c
kernel/bpf/verifier.c
kernel/trace/bpf_trace.c
net/core/bpf_sk_storage.c
net/core/filter.c
net/ipv4/bpf_tcp_ca.c