mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-27 11:49:07 +08:00
libbpf: Pass BPF token from find_prog_btf_id to BPF_BTF_GET_FD_BY_ID
Pass BPF token from bpf_program__set_attach_target to BPF_BTF_GET_FD_BY_ID bpf command. When freplace program attaches to target program, it needs to look up for BTF of the target, this may require BPF token, if, for example, running from user namespace. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/bpf/20250317174039.161275-4-mykyta.yatsenko5@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
009a8cb452
commit
90844e28dc
15
src/btf.c
15
src/btf.c
@@ -1619,12 +1619,18 @@ exit_free:
|
||||
return btf;
|
||||
}
|
||||
|
||||
struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf)
|
||||
struct btf *btf_load_from_kernel(__u32 id, struct btf *base_btf, int token_fd)
|
||||
{
|
||||
struct btf *btf;
|
||||
int btf_fd;
|
||||
LIBBPF_OPTS(bpf_get_fd_by_id_opts, opts);
|
||||
|
||||
btf_fd = bpf_btf_get_fd_by_id(id);
|
||||
if (token_fd) {
|
||||
opts.open_flags |= BPF_F_TOKEN_FD;
|
||||
opts.token_fd = token_fd;
|
||||
}
|
||||
|
||||
btf_fd = bpf_btf_get_fd_by_id_opts(id, &opts);
|
||||
if (btf_fd < 0)
|
||||
return libbpf_err_ptr(-errno);
|
||||
|
||||
@@ -1634,6 +1640,11 @@ struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf)
|
||||
return libbpf_ptr(btf);
|
||||
}
|
||||
|
||||
struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf)
|
||||
{
|
||||
return btf_load_from_kernel(id, base_btf, 0);
|
||||
}
|
||||
|
||||
struct btf *btf__load_from_kernel_by_id(__u32 id)
|
||||
{
|
||||
return btf__load_from_kernel_by_id_split(id, NULL);
|
||||
|
||||
Reference in New Issue
Block a user