* [PATCH bpf] libbpf: handle unsupported mmap-based /sys/kernel/btf/vmlinux correctly
@ 2025-06-06 20:21 Andrii Nakryiko
2025-06-06 21:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2025-06-06 20:21 UTC (permalink / raw)
To: bpf, ast, daniel, martin.lau
Cc: linux-perf-users, kernel-team, Andrii Nakryiko,
Arnaldo Carvalho de Melo, Lorenz Bauer
libbpf_err_ptr() helpers are meant to return NULL and set errno, if
there is an error. But btf_parse_raw_mmap() is meant to be used
internally and is expected to return ERR_PTR() values. Because of this
mismatch, when libbpf tries to mmap /sys/kernel/btf/vmlinux, we don't
detect the error correctly with IS_ERR() check, and never fallback to
old non-mmap-based way of loading vmlinux BTF.
Fix this by using proper ERR_PTR() returns internally.
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Fixes: 3c0421c93ce4 ("libbpf: Use mmap to parse vmlinux BTF from sysfs")
Cc: Lorenz Bauer <lmb@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/btf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index f1d495dc66bb..37682908cb0f 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1384,12 +1384,12 @@ static struct btf *btf_parse_raw_mmap(const char *path, struct btf *base_btf)
fd = open(path, O_RDONLY);
if (fd < 0)
- return libbpf_err_ptr(-errno);
+ return ERR_PTR(-errno);
if (fstat(fd, &st) < 0) {
err = -errno;
close(fd);
- return libbpf_err_ptr(err);
+ return ERR_PTR(err);
}
data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -1397,7 +1397,7 @@ static struct btf *btf_parse_raw_mmap(const char *path, struct btf *base_btf)
close(fd);
if (data == MAP_FAILED)
- return libbpf_err_ptr(err);
+ return ERR_PTR(err);
btf = btf_new(data, st.st_size, base_btf, true);
if (IS_ERR(btf))
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] libbpf: handle unsupported mmap-based /sys/kernel/btf/vmlinux correctly
2025-06-06 20:21 [PATCH bpf] libbpf: handle unsupported mmap-based /sys/kernel/btf/vmlinux correctly Andrii Nakryiko
@ 2025-06-06 21:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-06-06 21:20 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, ast, daniel, martin.lau, linux-perf-users, kernel-team, acme,
lmb
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Fri, 6 Jun 2025 13:21:34 -0700 you wrote:
> libbpf_err_ptr() helpers are meant to return NULL and set errno, if
> there is an error. But btf_parse_raw_mmap() is meant to be used
> internally and is expected to return ERR_PTR() values. Because of this
> mismatch, when libbpf tries to mmap /sys/kernel/btf/vmlinux, we don't
> detect the error correctly with IS_ERR() check, and never fallback to
> old non-mmap-based way of loading vmlinux BTF.
>
> [...]
Here is the summary with links:
- [bpf] libbpf: handle unsupported mmap-based /sys/kernel/btf/vmlinux correctly
https://git.kernel.org/bpf/bpf/c/02670deede22
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-06 21:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 20:21 [PATCH bpf] libbpf: handle unsupported mmap-based /sys/kernel/btf/vmlinux correctly Andrii Nakryiko
2025-06-06 21:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).