bpf: fix a libbpf loader issue
Subsystems (4)
PATCH 1/1 bpf: fix a libbpf loader issue
Commit 2993e0515bb4 ("tools/bpf: add support to read .BTF.ext sections") added support to read .BTF.ext sections from an object file, create and pass prog_btf_fd and func_info to the kernel.
The program btf_fd (prog->btf_fd) is initialized to be -1 to please zclose so we do not need special handling dur prog close. Passing -1 to the kernel, however, will cause loading error. Passing btf_fd 0 to the kernel if prog->btf_fd is invalid fixed the problem.
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
@@ -1387,7 +1387,7 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt, load_attr.license = license; load_attr.kern_version = kern_version; load_attr.prog_ifindex = prog->prog_ifindex; - load_attr.prog_btf_fd = prog->btf_fd; + load_attr.prog_btf_fd = prog->btf_fd >=0 ? prog->btf_fd :0 ; load_attr.func_info = prog->func_info; load_attr.func_info_rec_size = prog->func_info_rec_size; load_attr.func_info_cnt = func_info_cnt;
Signature · 1 line
2.17.1
Quoted 9 lines · Yonghong Song
Commit
2993e0515bb4("tools/bpf: add support to read .BTF.ext sections") added support to read .BTF.ext sections from an object file, create and passprog_btf_fdandfunc_infoto the kernel.The program
btf_fd(prog->btf_fd) is initialized to be -1 to please zclose so we do not need special handling dur prog close. Passing -1 to the kernel, however, will cause loading error. Passingbtf_fd0 to the kernel ifprog->btf_fdis invalid fixed the problem.
Quoted 10 lines · Yonghong Song
Commit
2993e0515bb4("tools/bpf: add support to read .BTF.ext sections") added support to read .BTF.ext sections from an object file, create and passprog_btf_fdandfunc_infoto the kernel.The program
btf_fd(prog->btf_fd) is initialized to be -1 to please zclose so we do not need special handling dur prog close. Passing -1 to the kernel, however, will cause loading error. Passingbtf_fd0 to the kernel ifprog->btf_fdis invalid fixed the problem.
Quoted 5 lines
Fixes 2993e0515bb4 ("tools/bpf: add support to read .BTF.ext sections")Reported-by Andrey Ignatov <[email protected]>Reported-by Emre Cantimur <[email protected]>Tested-by Andrey Ignatov <[email protected]>Signed-off-by Yonghong Song <[email protected]>
Applied, thanks!