* [PATCH bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded
@ 2022-02-16 9:21 Jiri Olsa
2022-02-16 18:40 ` patchwork-bot+netdevbpf
2022-02-16 23:08 ` Andrii Nakryiko
0 siblings, 2 replies; 3+ messages in thread
From: Jiri Olsa @ 2022-02-16 9:21 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: Yinjun Zhang, netdev, bpf, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh
The commit e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
fails to dump map without BTF loaded in pretty mode (-p option).
Fixing this by making sure get_map_kv_btf won't fail in case there's
no BTF available for the map.
Cc: Yinjun Zhang <yinjun.zhang@corigine.com>
Fixes: e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/bpf/bpftool/map.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 7a341a472ea4..8562add7417d 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -805,29 +805,28 @@ static int maps_have_btf(int *fds, int nb_fds)
static struct btf *btf_vmlinux;
-static struct btf *get_map_kv_btf(const struct bpf_map_info *info)
+static int get_map_kv_btf(const struct bpf_map_info *info, struct btf **btf)
{
- struct btf *btf = NULL;
+ int err = 0;
if (info->btf_vmlinux_value_type_id) {
if (!btf_vmlinux) {
btf_vmlinux = libbpf_find_kernel_btf();
- if (libbpf_get_error(btf_vmlinux))
+ err = libbpf_get_error(btf_vmlinux);
+ if (err) {
p_err("failed to get kernel btf");
+ return err;
+ }
}
- return btf_vmlinux;
+ *btf = btf_vmlinux;
} else if (info->btf_value_type_id) {
- int err;
-
- btf = btf__load_from_kernel_by_id(info->btf_id);
- err = libbpf_get_error(btf);
- if (err) {
+ *btf = btf__load_from_kernel_by_id(info->btf_id);
+ err = libbpf_get_error(*btf);
+ if (err)
p_err("failed to get btf");
- btf = ERR_PTR(err);
- }
}
- return btf;
+ return err;
}
static void free_map_kv_btf(struct btf *btf)
@@ -862,8 +861,7 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
prev_key = NULL;
if (wtr) {
- btf = get_map_kv_btf(info);
- err = libbpf_get_error(btf);
+ err = get_map_kv_btf(info, &btf);
if (err) {
goto exit_free;
}
@@ -1054,8 +1052,7 @@ static void print_key_value(struct bpf_map_info *info, void *key,
json_writer_t *btf_wtr;
struct btf *btf;
- btf = get_map_kv_btf(info);
- if (libbpf_get_error(btf))
+ if (get_map_kv_btf(info, &btf))
return;
if (json_output) {
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded
2022-02-16 9:21 [PATCH bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded Jiri Olsa
@ 2022-02-16 18:40 ` patchwork-bot+netdevbpf
2022-02-16 23:08 ` Andrii Nakryiko
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-16 18:40 UTC (permalink / raw)
To: Jiri Olsa
Cc: ast, daniel, andrii, yinjun.zhang, netdev, bpf, kafai,
songliubraving, yhs, john.fastabend, kpsingh
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Wed, 16 Feb 2022 10:21:02 +0100 you wrote:
> The commit e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
> fails to dump map without BTF loaded in pretty mode (-p option).
>
> Fixing this by making sure get_map_kv_btf won't fail in case there's
> no BTF available for the map.
>
> Cc: Yinjun Zhang <yinjun.zhang@corigine.com>
> Fixes: e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>
> [...]
Here is the summary with links:
- [bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded
https://git.kernel.org/bpf/bpf-next/c/2e3f7bed2837
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] 3+ messages in thread
* Re: [PATCH bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded
2022-02-16 9:21 [PATCH bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded Jiri Olsa
2022-02-16 18:40 ` patchwork-bot+netdevbpf
@ 2022-02-16 23:08 ` Andrii Nakryiko
1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2022-02-16 23:08 UTC (permalink / raw)
To: Jiri Olsa
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Yinjun Zhang, Networking, bpf, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh
On Wed, Feb 16, 2022 at 1:21 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> The commit e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
> fails to dump map without BTF loaded in pretty mode (-p option).
>
> Fixing this by making sure get_map_kv_btf won't fail in case there's
> no BTF available for the map.
>
> Cc: Yinjun Zhang <yinjun.zhang@corigine.com>
> Fixes: e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/bpf/bpftool/map.c | 29 +++++++++++++----------------
> 1 file changed, 13 insertions(+), 16 deletions(-)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 7a341a472ea4..8562add7417d 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -805,29 +805,28 @@ static int maps_have_btf(int *fds, int nb_fds)
>
> static struct btf *btf_vmlinux;
>
> -static struct btf *get_map_kv_btf(const struct bpf_map_info *info)
> +static int get_map_kv_btf(const struct bpf_map_info *info, struct btf **btf)
> {
> - struct btf *btf = NULL;
> + int err = 0;
>
> if (info->btf_vmlinux_value_type_id) {
> if (!btf_vmlinux) {
> btf_vmlinux = libbpf_find_kernel_btf();
> - if (libbpf_get_error(btf_vmlinux))
> + err = libbpf_get_error(btf_vmlinux);
> + if (err) {
> p_err("failed to get kernel btf");
> + return err;
> + }
> }
> - return btf_vmlinux;
> + *btf = btf_vmlinux;
> } else if (info->btf_value_type_id) {
> - int err;
> -
> - btf = btf__load_from_kernel_by_id(info->btf_id);
> - err = libbpf_get_error(btf);
> - if (err) {
> + *btf = btf__load_from_kernel_by_id(info->btf_id);
> + err = libbpf_get_error(*btf);
> + if (err)
> p_err("failed to get btf");
> - btf = ERR_PTR(err);
> - }
> }
get_map_kv_btf is supposed to set btf to NULL, otherwise you can get a
crash in the caller
I've added
else {
*btf = NULL;
}
and force-pushed
>
> - return btf;
> + return err;
> }
>
> static void free_map_kv_btf(struct btf *btf)
> @@ -862,8 +861,7 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
> prev_key = NULL;
>
> if (wtr) {
> - btf = get_map_kv_btf(info);
> - err = libbpf_get_error(btf);
> + err = get_map_kv_btf(info, &btf);
> if (err) {
> goto exit_free;
> }
> @@ -1054,8 +1052,7 @@ static void print_key_value(struct bpf_map_info *info, void *key,
> json_writer_t *btf_wtr;
> struct btf *btf;
>
> - btf = get_map_kv_btf(info);
> - if (libbpf_get_error(btf))
> + if (get_map_kv_btf(info, &btf))
> return;
>
> if (json_output) {
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-16 23:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 9:21 [PATCH bpf-next] bpftool: Fix pretty print dump for maps without BTF loaded Jiri Olsa
2022-02-16 18:40 ` patchwork-bot+netdevbpf
2022-02-16 23:08 ` Andrii Nakryiko
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).