UPSTREAM: bpf: Provide function to get vmlinux BTF information

It will be used later for BPF structure display support

Change-Id: I5de76be6dc13bf9e23f6b9d3afb1b4feff407170
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/1601292670-1616-2-git-send-email-alan.maguire@oracle.com
This commit is contained in:
Alan Maguire 2020-09-28 12:31:03 +01:00 • committed by basamaryan
commit 0ca8045820
No known key found for this signature in database
GPG key ID: 210D5384FB2A5885
2 changed files with 14 additions and 6 deletions

View file

@ -1368,6 +1368,8 @@ int bpf_check(struct bpf_prog **fp, union bpf_attr *attr,
void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth);
#endif
struct btf *bpf_get_btf_vmlinux(void);
/* Map specifics */
struct xdp_buff;
struct sk_buff;

View file

@ -11698,6 +11698,17 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
return 0;
}
struct btf *bpf_get_btf_vmlinux(void)
{
if (!btf_vmlinux && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
mutex_lock(&bpf_verifier_lock);
if (!btf_vmlinux)
btf_vmlinux = btf_parse_vmlinux();
mutex_unlock(&bpf_verifier_lock);
}
return btf_vmlinux;
}
int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
union bpf_attr __user *uattr)
{
@ -11731,12 +11742,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
env->ops = bpf_verifier_ops[env->prog->type];
is_priv = bpf_capable();
if (!btf_vmlinux && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {
mutex_lock(&bpf_verifier_lock);
if (!btf_vmlinux)
btf_vmlinux = btf_parse_vmlinux();
mutex_unlock(&bpf_verifier_lock);
}
bpf_get_btf_vmlinux();
/* grab the mutex to protect few globals used by verifier */
if (!is_priv)