* [PATCH bpf-next 0/3] bpftool: improve split BTF support
@ 2020-12-02 6:52 Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 1/3] tools/bpftool: emit name <anon> for anonymous BTFs Andrii Nakryiko
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-12-02 6:52 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii, kernel-team
Few follow up improvements to bpftool for split BTF support:
- emit "name <anon>" for non-named BTFs in `bpftool btf show` command;
- when dumping /sys/kernel/btf/<module> use /sys/kernel/btf/vmlinux as the
base BTF, unless base BTF is explicitly specified with -B flag.
This patch set also adds btf__base_btf() getter to access base BTF of the
struct btf.
Andrii Nakryiko (3):
tools/bpftool: emit name <anon> for anonymous BTFs
libbpf: add base BTF accessor
tools/bpftool: auto-detect split BTFs in common cases
tools/bpf/bpftool/btf.c | 27 +++++++++++++++++++++++----
tools/lib/bpf/btf.c | 5 +++++
tools/lib/bpf/btf.h | 1 +
tools/lib/bpf/libbpf.map | 1 +
4 files changed, 30 insertions(+), 4 deletions(-)
--
2.24.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf-next 1/3] tools/bpftool: emit name <anon> for anonymous BTFs
2020-12-02 6:52 [PATCH bpf-next 0/3] bpftool: improve split BTF support Andrii Nakryiko
@ 2020-12-02 6:52 ` Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 2/3] libbpf: add base BTF accessor Andrii Nakryiko
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-12-02 6:52 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii, kernel-team, Song Liu
For consistency of output, emit "name <anon>" for BTFs without the name. This
keeps output more consistent and obvious.
Suggested-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/btf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index ed5e97157241..bd46af6a61cc 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -750,6 +750,8 @@ show_btf_plain(struct bpf_btf_info *info, int fd,
printf("name [%s] ", name);
else if (name && name[0])
printf("name %s ", name);
+ else
+ printf("name <anon> ");
printf("size %uB", info->btf_size);
n = 0;
--
2.24.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next 2/3] libbpf: add base BTF accessor
2020-12-02 6:52 [PATCH bpf-next 0/3] bpftool: improve split BTF support Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 1/3] tools/bpftool: emit name <anon> for anonymous BTFs Andrii Nakryiko
@ 2020-12-02 6:52 ` Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 3/3] tools/bpftool: auto-detect split BTFs in common cases Andrii Nakryiko
2020-12-03 18:31 ` [PATCH bpf-next 0/3] bpftool: improve split BTF support Alexei Starovoitov
3 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-12-02 6:52 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii, kernel-team
Add ability to get base BTF. It can be also used to check if BTF is split BTF.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/btf.c | 5 +++++
tools/lib/bpf/btf.h | 1 +
tools/lib/bpf/libbpf.map | 1 +
3 files changed, 7 insertions(+)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 8ff46cd30ca1..1935e83d309c 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -432,6 +432,11 @@ __u32 btf__get_nr_types(const struct btf *btf)
return btf->start_id + btf->nr_types - 1;
}
+const struct btf *btf__base_btf(const struct btf *btf)
+{
+ return btf->base_btf;
+}
+
/* internal helper returning non-const pointer to a type */
static struct btf_type *btf_type_by_id(struct btf *btf, __u32 type_id)
{
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 1093f6fe6800..1237bcd1dd17 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -51,6 +51,7 @@ LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf,
const char *type_name, __u32 kind);
LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf);
+LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf);
LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
__u32 id);
LIBBPF_API size_t btf__pointer_size(const struct btf *btf);
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 29ff4807b909..ed55498c4122 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -340,6 +340,7 @@ LIBBPF_0.2.0 {
LIBBPF_0.3.0 {
global:
+ btf__base_btf;
btf__parse_elf_split;
btf__parse_raw_split;
btf__parse_split;
--
2.24.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next 3/3] tools/bpftool: auto-detect split BTFs in common cases
2020-12-02 6:52 [PATCH bpf-next 0/3] bpftool: improve split BTF support Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 1/3] tools/bpftool: emit name <anon> for anonymous BTFs Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 2/3] libbpf: add base BTF accessor Andrii Nakryiko
@ 2020-12-02 6:52 ` Andrii Nakryiko
2020-12-03 18:31 ` [PATCH bpf-next 0/3] bpftool: improve split BTF support Alexei Starovoitov
3 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2020-12-02 6:52 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii, kernel-team
In case of working with module's split BTF from /sys/kernel/btf/*,
auto-substitute /sys/kernel/btf/vmlinux as the base BTF. This makes using
bpftool with module BTFs faster and simpler.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/btf.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index bd46af6a61cc..94cd3bad5430 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -357,11 +357,13 @@ static int dump_btf_raw(const struct btf *btf,
dump_btf_type(btf, root_type_ids[i], t);
}
} else {
+ const struct btf *base;
int cnt = btf__get_nr_types(btf);
int start_id = 1;
- if (base_btf)
- start_id = btf__get_nr_types(base_btf) + 1;
+ base = btf__base_btf(btf);
+ if (base)
+ start_id = btf__get_nr_types(base) + 1;
for (i = start_id; i <= cnt; i++) {
t = btf__type_by_id(btf, i);
@@ -428,7 +430,7 @@ static int dump_btf_c(const struct btf *btf,
static int do_dump(int argc, char **argv)
{
- struct btf *btf = NULL;
+ struct btf *btf = NULL, *base = NULL;
__u32 root_type_ids[2];
int root_type_cnt = 0;
bool dump_c = false;
@@ -502,7 +504,21 @@ static int do_dump(int argc, char **argv)
}
NEXT_ARG();
} else if (is_prefix(src, "file")) {
- btf = btf__parse_split(*argv, base_btf);
+ const char sysfs_prefix[] = "/sys/kernel/btf/";
+ const char sysfs_vmlinux[] = "/sys/kernel/btf/vmlinux";
+
+ if (!base_btf &&
+ strncmp(*argv, sysfs_prefix, sizeof(sysfs_prefix) - 1) == 0 &&
+ strcmp(*argv, sysfs_vmlinux) != 0) {
+ base = btf__parse(sysfs_vmlinux, NULL);
+ if (libbpf_get_error(base)) {
+ p_err("failed to parse vmlinux BTF at '%s': %ld\n",
+ sysfs_vmlinux, libbpf_get_error(base));
+ base = NULL;
+ }
+ }
+
+ btf = btf__parse_split(*argv, base ?: base_btf);
if (IS_ERR(btf)) {
err = -PTR_ERR(btf);
btf = NULL;
@@ -567,6 +583,7 @@ static int do_dump(int argc, char **argv)
done:
close(fd);
btf__free(btf);
+ btf__free(base);
return err;
}
--
2.24.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next 0/3] bpftool: improve split BTF support
2020-12-02 6:52 [PATCH bpf-next 0/3] bpftool: improve split BTF support Andrii Nakryiko
` (2 preceding siblings ...)
2020-12-02 6:52 ` [PATCH bpf-next 3/3] tools/bpftool: auto-detect split BTFs in common cases Andrii Nakryiko
@ 2020-12-03 18:31 ` Alexei Starovoitov
3 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2020-12-03 18:31 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, netdev, ast, daniel, kernel-team
On Tue, Dec 01, 2020 at 10:52:40PM -0800, Andrii Nakryiko wrote:
> Few follow up improvements to bpftool for split BTF support:
> - emit "name <anon>" for non-named BTFs in `bpftool btf show` command;
> - when dumping /sys/kernel/btf/<module> use /sys/kernel/btf/vmlinux as the
> base BTF, unless base BTF is explicitly specified with -B flag.
>
> This patch set also adds btf__base_btf() getter to access base BTF of the
> struct btf.
Applied, Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-12-03 18:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 6:52 [PATCH bpf-next 0/3] bpftool: improve split BTF support Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 1/3] tools/bpftool: emit name <anon> for anonymous BTFs Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 2/3] libbpf: add base BTF accessor Andrii Nakryiko
2020-12-02 6:52 ` [PATCH bpf-next 3/3] tools/bpftool: auto-detect split BTFs in common cases Andrii Nakryiko
2020-12-03 18:31 ` [PATCH bpf-next 0/3] bpftool: improve split BTF support Alexei Starovoitov
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).