libbpf: deprecate bpf_program__get_prog_info_linear
Subsystems (4)
v3 cover libbpf: deprecate bpf_program__get_prog_info_linear
bpf_program__get_prog_info_linear is a helper which wraps the bpf_obj_get_info_by_fd BPF syscall with some niceties that put all dynamic-length bpf_prog_info in one buffer contiguous with struct bpf_prog_info, and simplify the selection of which dynamic data to grab.
The resultant combined struct, bpf_prog_info_linear, is persisted to file by 'perf' to enable later annotation of BPF prog data. libbpf includes some vaddr <-> offset conversion helpers for struct bpf_prog_info_linear to simplify this.
This functionality is heavily tailored to perf's usecase, so its use as a general prog info API should be deemphasized in favor of just calling bpf_obj_get_info_by_fd, which can be more easily fit to purpose. Some examples from caller migrations in this series:
* Some callers weren't requesting or using dynamic-sized prog info and are well served by a simple get_info_by_fd call (e.g. dump_prog_id_as_func_ptr in bpftool)
* Some callers were requesting all of a specific dynamic info type but only using the first record, so can avoid unnecessary malloc by only requesting 1 (e.g. profile_target_name in bpftool)
* bpftool's do_dump saves some malloc/free by growing and reusing its dynamic prog_info buf as it loops over progs to grab info and dump.
Perf does need the full functionality of bpf_program__get_prog_info_linear and its accompanying structs + helpers, so copy the code to its codebase, migrate all other uses in the tree, and deprecate the helper in libbpf.
Since the deprecated symbols continue to be included in perf some renaming was necessary in perf's copy, otherwise functionality is unchanged.
This work was previously discussed in libbpf's issue tracker [0].
[0]: https://github.com/libbpf/libbpf/issues/313
v2->v3:
* Remove v2's patch 1 ("libbpf: Migrate internal use of bpf_program__get_prog_info_linear"), which was applied [Andrii]
* Add new patch 1 migrating error checking of libbpf calls to new scheme [Andrii, Quentin]
* In patch 2, fix != -1 error check of libbpf call, improper realloc handling, and get rid of confusing macros [Andrii]
* In patch 4, deprecate starting from 0.6 instead of 0.7 [Andrii]
v1->v2: fix bpftool do_dump changes to clear bpf_prog_info after use and correctly pass realloc'd ptr back (patch 2)
Dave Marchevsky (4):
bpftool: Migrate -1 err checks of libbpf fn calls
bpftool: use bpf_obj_get_info_by_fd directly
perf: pull in bpf_program__get_prog_info_linear
libbpf: deprecate bpf_program__get_prog_info_linear
tools/bpf/bpftool/btf_dumper.c | 42 +-- tools/bpf/bpftool/prog.c | 158 ++++++++--- tools/bpf/bpftool/struct_ops.c | 2 +- tools/lib/bpf/libbpf.h | 3 + .../Documentation/perf.data-file-format.txt | 2 +- tools/perf/util/Build | 1 + tools/perf/util/annotate.c | 3 +- tools/perf/util/bpf-event.c | 41 ++- tools/perf/util/bpf-event.h | 2 +- tools/perf/util/bpf-utils.c | 261 ++++++++++++++++++ tools/perf/util/bpf-utils.h | 76 +++++ tools/perf/util/bpf_counter.c | 6 +- tools/perf/util/dso.c | 1 + tools/perf/util/env.c | 1 + tools/perf/util/header.c | 13 +- 15 files changed, 527 insertions(+), 85 deletions(-) create mode 100644 tools/perf/util/bpf-utils.c create mode 100644 tools/perf/util/bpf-utils.h
Signature · 1 line
2.30.2
PATCH v3 1/4 bpftool: Migrate -1 err checks of libbpf fn calls
Per [0], callers of libbpf functions with LIBBPF_STRICT_DIRECT_ERRS set should handle negative error codes of various values (e.g. -EINVAL). Migrate two callsites which were explicitly checking for -1 only to handle the new scheme.
--- tools/bpf/bpftool/btf_dumper.c | 2 +- tools/bpf/bpftool/struct_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/btf_dumper.c +1 -1
@@ -52,7 +52,7 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,/* Get the bpf_prog's name. Obtain from func_info. */ prog_fd =bpf_prog_get_fd_by_id (prog_id); -if (prog_fd ==-1 ) +if (prog_fd <0 ) goto print; prog_info = bpf_program__get_prog_info_linear(prog_fd,
tools/bpf/bpftool/struct_ops.c +1 -1
@@ -252,7 +252,7 @@ static struct res do_one_id(const char *id_str, work_func func, void *data, } fd =bpf_map_get_fd_by_id (id); -if (fd ==-1 ) { +if (fd <0 ) {p_err ("can't get map by id (%lu): %s" , id,strerror (errno)); res.nr_errs++;return res;
Signature · 1 line
2.30.2
PATCH v3 2/4 bpftool: use bpf_obj_get_info_by_fd directly
In reply to Dave MarchevskyTo prepare for impending deprecation of libbpf's bpf_program__get_prog_info_linear, migrate uses of this function to use bpf_obj_get_info_by_fd.
Since the profile_target_name and dump_prog_id_as_func_ptr helpers were only looking at the first func_info, avoid grabbing the rest to save a malloc. For do_dump, add a more full-featured helper, but avoid free/realloc of buffer when possible for multi-prog dumps.
--- tools/bpf/bpftool/btf_dumper.c | 40 +++++---- tools/bpf/bpftool/prog.c | 158 ++++++++++++++++++++++++++------- 2 files changed, 148 insertions(+), 50 deletions(-)
tools/bpf/bpftool/btf_dumper.c +24 -16
@@ -32,14 +32,16 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d, const struct btf_type *func_proto, __u32 prog_id) { -struct bpf_prog_info_linear *prog_info =NULL ;const struct btf_type *func_type; +int prog_fd =-1 , func_sig_len; +struct bpf_prog_info info = {}; +__u32 info_len =sizeof (info);const char *prog_name =NULL ; -struct bpf_func_info *finfo;struct btf *prog_btf =NULL ; -struct bpf_prog_info *info; -int prog_fd, func_sig_len; +struct bpf_func_info finfo; +__u32 finfo_rec_size;char prog_str[1024 ]; +int err;/* Get the ptr's func_proto */ func_sig_len = btf_dump_func(d->btf, prog_str, func_proto, NULL, 0,
@@ -55,22 +57,27 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,if (prog_fd <0 ) goto print; - prog_info =bpf_program__get_prog_info_linear (prog_fd, -1UL <<BPF_PROG_INFO_FUNC_INFO ); -close (prog_fd); -if (IS_ERR (prog_info)) { - prog_info =NULL ; + err =bpf_obj_get_info_by_fd (prog_fd, &info, &info_len); +if (err) goto print; - } - info = &prog_info->info; -if (!info->btf_id || !info->nr_func_info) +if (!info.btf_id || !info.nr_func_info) + goto print; + + finfo_rec_size = info.func_info_rec_size; +memset (&info,0 ,sizeof (info)); + info.nr_func_info =1 ; + info.func_info_rec_size = finfo_rec_size; + info.func_info =ptr_to_u64 (&finfo); + + err =bpf_obj_get_info_by_fd (prog_fd, &info, &info_len); +if (err) goto print; - prog_btf =btf__load_from_kernel_by_id (info->btf_id); + + prog_btf =btf__load_from_kernel_by_id (info.btf_id);if (libbpf_get_error (prog_btf)) goto print; - finfo =u64_to_ptr (info->func_info); - func_type =btf__type_by_id (prog_btf, finfo->type_id); + func_type =btf__type_by_id (prog_btf, finfo.type_id);if (!func_type || !btf_is_func (func_type)) goto print;
@@ -92,7 +99,8 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d, prog_str[sizeof (prog_str) -1 ] ='\0' ;jsonw_string (d->jw, prog_str);btf__free (prog_btf); -free (prog_info); +if (prog_fd >=0 ) +close (prog_fd);return 0 ; }
tools/bpf/bpftool/prog.c +124 -34
239 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v3 3/4 perf: pull in bpf_program__get_prog_info_linear
In reply to Dave MarchevskyTo prepare for impending deprecation of libbpf's bpf_program__get_prog_info_linear, pull in the function and associated helpers into the perf codebase and migrate existing uses to the perf copy.
Since libbpf's deprecated definitions will still be visible to perf, it is necessary to rename perf's definitions.
--- .../Documentation/perf.data-file-format.txt | 2 +- tools/perf/util/Build | 1 + tools/perf/util/annotate.c | 3 +- tools/perf/util/bpf-event.c | 41 ++- tools/perf/util/bpf-event.h | 2 +- tools/perf/util/bpf-utils.c | 261 ++++++++++++++++++ tools/perf/util/bpf-utils.h | 76 +++++ tools/perf/util/bpf_counter.c | 6 +- tools/perf/util/dso.c | 1 + tools/perf/util/env.c | 1 + tools/perf/util/header.c | 13 +- 11 files changed, 374 insertions(+), 33 deletions(-) create mode 100644 tools/perf/util/bpf-utils.c create mode 100644 tools/perf/util/bpf-utils.h
tools/perf/Documentation/perf.data-file-format.txt +1 -1
@@ -346,7 +346,7 @@ to special needs. HEADER_BPF_PROG_INFO = 25, -struct bpf_prog_info_linear, which contains detailed information about +struct perf_bpil, which contains detailed information about a BPF program, including type, id, tag, jited/xlated instructions, etc. HEADER_BPF_BTF = 26,
tools/perf/util/Build +1 -0
@@ -201,6 +201,7 @@ endif perf-y += perf-hooks.o perf-$(CONFIG_LIBBPF) += bpf-event.o +perf-$(CONFIG_LIBBPF) += bpf-utils.o perf-$(CONFIG_CXX) += c++/
tools/perf/util/annotate.c +2 -1
@@ -28,6 +28,7 @@#include "evsel.h" #include "evlist.h" #include "bpf-event.h" +#include "bpf-utils.h" #include "block-range.h" #include "string2.h" #include "util/event.h"
@@ -1700,12 +1701,12 @@ static int symbol__disassemble_bpf(struct symbol *sym, {struct annotation *notes =symbol__annotation (sym);struct annotation_options *opts = args->options; -struct bpf_prog_info_linear *info_linear;struct bpf_prog_linfo *prog_linfo =NULL ;struct bpf_prog_info_node *info_node;int len = sym->end - sym->start;disassembler_ftype disassemble;struct map *map = args->ms.map; +struct perf_bpil *info_linear;struct disassemble_info info;struct dso *dso = map->dso;int pc =0 , count, sub_id;
tools/perf/util/bpf-event.c +20 -21
90 lines not on this page · raw message
tools/perf/util/bpf-event.h +1 -1
@@ -19,7 +19,7 @@ struct evlist;struct target ;struct bpf_prog_info_node { -struct bpf_prog_info_linear *info_linear; +struct perf_bpil *info_linear;struct rb_node rb_node; };
tools/perf/util/bpf-utils.c new file +261 -0
261 lines not on this page · raw message
tools/perf/util/bpf-utils.h new file +76 -0
76 lines not on this page · raw message
tools/perf/util/bpf_counter.c +3 -3
@@ -13,6 +13,7 @@#include <perf/bpf_perf.h> #include "bpf_counter.h" +#include "bpf-utils.h" #include "counts.h" #include "debug.h" #include "evsel.h"
@@ -61,14 +62,13 @@ static int bpf_program_profiler__destroy(struct evsel *evsel)static char *bpf_target_prog_name (int tgt_fd) { -struct bpf_prog_info_linear *info_linear;struct bpf_func_info *func_info; +struct perf_bpil *info_linear;const struct btf_type *t;struct btf *btf =NULL ;char *name =NULL ; - info_linear =bpf_program__get_prog_info_linear ( - tgt_fd,1UL <<BPF_PROG_INFO_FUNC_INFO ); + info_linear =get_bpf_prog_info_linear (tgt_fd,1UL <<PERF_BPIL_FUNC_INFO );if (IS_ERR_OR_NULL (info_linear)) {pr_debug ("failed to get info_linear for prog FD %d\n" , tgt_fd);return NULL ;
tools/perf/util/dso.c +1 -0
@@ -14,6 +14,7 @@#ifdef HAVE_LIBBPF_SUPPORT #include <bpf/libbpf.h> #include "bpf-event.h" +#include "bpf-utils.h" #endif #include "compress.h" #include "env.h"
tools/perf/util/env.c +1 -0
@@ -16,6 +16,7 @@ struct perf_env perf_env;#ifdef HAVE_LIBBPF_SUPPORT #include "bpf-event.h" +#include "bpf-utils.h" #include <bpf/libbpf.h> void perf_env__insert_bpf_prog_info(struct perf_env *env,
tools/perf/util/header.c +7 -6
@@ -48,6 +48,7 @@#include "util/util.h" // perf_exe() #include "cputopo.h" #include "bpf-event.h" +#include "bpf-utils.h" #include "clockid.h" #include "pmu-hybrid.h"
@@ -1006,17 +1007,17 @@ static int write_bpf_prog_info(struct feat_fd *ff, node = rb_entry(next, struct bpf_prog_info_node, rb_node); next =rb_next (&node->rb_node); - len =sizeof (struct bpf_prog_info_linear ) + + len =sizeof (struct perf_bpil ) + node->info_linear->data_len;/* before writing to file, translate address to offset */ -bpf_program__bpil_addr_to_offs (node->info_linear); +bpil_addr_to_offs (node->info_linear); ret =do_write (ff, node->info_linear, len);/* * translate back to address even when do_write() fails, * so that this function never changes the data. */ -bpf_program__bpil_offs_to_addr (node->info_linear); +bpil_offs_to_addr (node->info_linear);if (ret <0 ) goto out; }
@@ -3018,9 +3019,9 @@ static int process_dir_format(struct feat_fd *ff,#ifdef HAVE_LIBBPF_SUPPORT static int process_bpf_prog_info (struct feat_fd *ff,void *data__maybe_unused ) { -struct bpf_prog_info_linear *info_linear;struct bpf_prog_info_node *info_node;struct perf_env *env = &ff->ph->env; +struct perf_bpil *info_linear;u32 count, i;int err =-1 ;
@@ -3049,7 +3050,7 @@ static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused) goto out; } - info_linear =malloc (sizeof (struct bpf_prog_info_linear ) + + info_linear =malloc (sizeof (struct perf_bpil ) + data_len);if (!info_linear) goto out;
@@ -3071,7 +3072,7 @@ static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused) goto out;/* after reading from file, translate offset to address */ -bpf_program__bpil_offs_to_addr (info_linear); +bpil_offs_to_addr (info_linear); info_node->info_linear = info_linear;perf_env__insert_bpf_prog_info (env, info_node); }
Signature · 1 line
2.30.2
PATCH v3 4/4 libbpf: deprecate bpf_program__get_prog_info_linear
In reply to Dave MarchevskyAs part of the road to libbpf 1.0, and discussed in libbpf issue tracker [0], bpf_program__get_prog_info_linear and its associated structs and helper functions should be deprecated. The functionality is too specific to the needs of 'perf', and there's little/no out-of-tree usage to preclude introduction of a more general helper in the future.
[0] Closes: https://github.com/libbpf/libbpf/issues/313
--- tools/lib/bpf/libbpf.h | 3 +++ 1 file changed, 3 insertions(+)
tools/lib/bpf/libbpf.h +3 -0
@@ -918,12 +918,15 @@ struct bpf_prog_info_linear {__u8 data[]; }; +LIBBPF_DEPRECATED_SINCE(0, 6, "use a custom linear prog_info wrapper") LIBBPF_API struct bpf_prog_info_linear *bpf_program__get_prog_info_linear (int fd,__u64 arrays); +LIBBPF_DEPRECATED_SINCE(0, 6, "use a custom linear prog_info wrapper") LIBBPF_API voidbpf_program__bpil_addr_to_offs (struct bpf_prog_info_linear *info_linear); +LIBBPF_DEPRECATED_SINCE(0, 6, "use a custom linear prog_info wrapper") LIBBPF_API voidbpf_program__bpil_offs_to_addr (struct bpf_prog_info_linear *info_linear);
Signature · 1 line
2.30.2
Quoted 38 lines · Dave Marchevsky
bpf_program__get_prog_info_linearis a helper which wraps thebpf_obj_get_info_by_fdBPF syscall with some niceties that put all dynamic-lengthbpf_prog_infoin one buffer contiguous with structbpf_prog_info, and simplify the selection of which dynamic data to grab.The resultant combined struct,
bpf_prog_info_linear, is persisted to file by 'perf' to enable later annotation of BPF prog data. libbpf includes some vaddr <-> offset conversion helpers for structbpf_prog_info_linearto simplify this.This functionality is heavily tailored to perf's usecase, so its use as a general prog info API should be deemphasized in favor of just calling
bpf_obj_get_info_by_fd, which can be more easily fit to purpose. Some examples from caller migrations in this series:* Some callers weren't requesting or using dynamic-sized prog info and are well served by a simple
get_info_by_fdcall (e.g.dump_prog_id_as_func_ptrin bpftool)
* Some callers were requesting all of a specific dynamic info type but only using the first record, so can avoid unnecessary malloc by only requesting 1 (e.g.profile_target_namein bpftool)
* bpftool'sdo_dumpsaves some malloc/free by growing and reusing its dynamicprog_infobuf as it loops over progs to grab info and dump.Perf does need the full functionality of
bpf_program__get_prog_info_linearand its accompanying structs + helpers, so copy the code to its codebase, migrate all other uses in the tree, and deprecate the helper in libbpf.Since the deprecated symbols continue to be included in perf some renaming was necessary in perf's copy, otherwise functionality is unchanged.
This work was previously discussed in libbpf's issue tracker [0].
Quoted 8 lines
v2->v3:
* Remove v2's patch 1 ("libbpf: Migrate internal use ofbpf_program__get_prog_info_linear"), which was applied [Andrii]
* Add new patch 1 migrating error checking of libbpf calls to new scheme [Andrii, Quentin]
* In patch 2, fix != -1 error check of libbpf call, improper realloc handling, and get rid of confusing macros [Andrii]
* In patch 4, deprecate starting from 0.6 instead of 0.7 [Andrii]
LGTM. Quentin, can you please take a look and ack as well? Thanks!
Quoted 32 lines
v1->v2: fix bpftooldo_dumpchanges to clearbpf_prog_infoafter use and correctly pass realloc'd ptr back (patch 2)Dave Marchevsky (4):
bpftool: Migrate -1 err checks of libbpf fn calls
bpftool: usebpf_obj_get_info_by_fddirectly
perf: pull inbpf_program__get_prog_info_linear
libbpf: deprecatebpf_program__get_prog_info_lineartools/bpf/bpftool/btf_dumper.c | 42 +-- tools/bpf/bpftool/prog.c | 158 ++++++++--- tools/bpf/bpftool/struct_ops.c | 2 +- tools/lib/bpf/libbpf.h | 3 + .../Documentation/perf.data-file-format.txt | 2 +- tools/perf/util/Build | 1 + tools/perf/util/annotate.c | 3 +- tools/perf/util/bpf-event.c | 41 ++- tools/perf/util/bpf-event.h | 2 +- tools/perf/util/bpf-utils.c | 261 ++++++++++++++++++ tools/perf/util/bpf-utils.h | 76 +++++ tools/perf/util/bpf_counter.c | 6 +- tools/perf/util/dso.c | 1 + tools/perf/util/env.c | 1 + tools/perf/util/header.c | 13 +- 15 files changed, 527 insertions(+), 85 deletions(-) create mode 100644 tools/perf/util/bpf-utils.c create mode 100644 tools/perf/util/bpf-utils.h--
2.30.2
Quentin Monnet
Acked-by2021-11-02 16:06 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 48 lines · Dave Marchevsky
Quoted 38 lines
bpf_program__get_prog_info_linearis a helper which wraps thebpf_obj_get_info_by_fdBPF syscall with some niceties that put all dynamic-lengthbpf_prog_infoin one buffer contiguous with structbpf_prog_info, and simplify the selection of which dynamic data to grab.The resultant combined struct,
bpf_prog_info_linear, is persisted to file by 'perf' to enable later annotation of BPF prog data. libbpf includes some vaddr <-> offset conversion helpers for structbpf_prog_info_linearto simplify this.This functionality is heavily tailored to perf's usecase, so its use as a general prog info API should be deemphasized in favor of just calling
bpf_obj_get_info_by_fd, which can be more easily fit to purpose. Some examples from caller migrations in this series:* Some callers weren't requesting or using dynamic-sized prog info and are well served by a simple
get_info_by_fdcall (e.g.dump_prog_id_as_func_ptrin bpftool)
* Some callers were requesting all of a specific dynamic info type but only using the first record, so can avoid unnecessary malloc by only requesting 1 (e.g.profile_target_namein bpftool)
* bpftool'sdo_dumpsaves some malloc/free by growing and reusing its dynamicprog_infobuf as it loops over progs to grab info and dump.Perf does need the full functionality of
bpf_program__get_prog_info_linearand its accompanying structs + helpers, so copy the code to its codebase, migrate all other uses in the tree, and deprecate the helper in libbpf.Since the deprecated symbols continue to be included in perf some renaming was necessary in perf's copy, otherwise functionality is unchanged.
This work was previously discussed in libbpf's issue tracker [0].
Quoted 8 lines
v2->v3:
* Remove v2's patch 1 ("libbpf: Migrate internal use ofbpf_program__get_prog_info_linear"), which was applied [Andrii]
* Add new patch 1 migrating error checking of libbpf calls to new scheme [Andrii, Quentin]
* In patch 2, fix != -1 error check of libbpf call, improper realloc handling, and get rid of confusing macros [Andrii]
* In patch 4, deprecate starting from 0.6 instead of 0.7 [Andrii]
Quoted 1 line
LGTM. Quentin, can you please take a look and ack as well? Thanks!
Thanks Andrii for the Cc! I realised yesterday morning that I'd been hit by the unsubscription incident and missed v3 of this set.
The changes look good to me, and you can add my tag to the first three patches:
Regarding patch 4, looking at the latest deprecations in libbpf, I would have expected the functions to be deprecated starting in v0.7, and not v0.6?
Other than that, on patch 2 (apologies for not answering inline), it would feel more natural, in do_dump()'s "for" loop in prog.c, to have the memset() above the call to bpf_obj_get_info_by_fd() (and to skip the zero-initialisation of "info") instead of at the end of the loop, which means a useless memset() just before we exit the loop. But probably not worth a respin just for that.
Thanks,
Quentin
Quoted 50 lines · Quentin Monnet
2021-11-02 16:06 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 48 lines · Dave Marchevsky
Quoted 46 lines
bpf_program__get_prog_info_linearis a helper which wraps thebpf_obj_get_info_by_fdBPF syscall with some niceties that put all dynamic-lengthbpf_prog_infoin one buffer contiguous with structbpf_prog_info, and simplify the selection of which dynamic data to grab.The resultant combined struct,
bpf_prog_info_linear, is persisted to file by 'perf' to enable later annotation of BPF prog data. libbpf includes some vaddr <-> offset conversion helpers for structbpf_prog_info_linearto simplify this.This functionality is heavily tailored to perf's usecase, so its use as a general prog info API should be deemphasized in favor of just calling
bpf_obj_get_info_by_fd, which can be more easily fit to purpose. Some examples from caller migrations in this series:* Some callers weren't requesting or using dynamic-sized prog info and are well served by a simple
get_info_by_fdcall (e.g.dump_prog_id_as_func_ptrin bpftool)
* Some callers were requesting all of a specific dynamic info type but only using the first record, so can avoid unnecessary malloc by only requesting 1 (e.g.profile_target_namein bpftool)
* bpftool'sdo_dumpsaves some malloc/free by growing and reusing its dynamicprog_infobuf as it loops over progs to grab info and dump.Perf does need the full functionality of
bpf_program__get_prog_info_linearand its accompanying structs + helpers, so copy the code to its codebase, migrate all other uses in the tree, and deprecate the helper in libbpf.Since the deprecated symbols continue to be included in perf some renaming was necessary in perf's copy, otherwise functionality is unchanged.
This work was previously discussed in libbpf's issue tracker [0].
[0]: https://github.com/libbpf/libbpf/issues/313
v2->v3:
* Remove v2's patch 1 ("libbpf: Migrate internal use ofbpf_program__get_prog_info_linear"), which was applied [Andrii]
* Add new patch 1 migrating error checking of libbpf calls to new scheme [Andrii, Quentin]
* In patch 2, fix != -1 error check of libbpf call, improper realloc handling, and get rid of confusing macros [Andrii]
* In patch 4, deprecate starting from 0.6 instead of 0.7 [Andrii]
Quoted 4 lines
Quoted 1 line
LGTM. Quentin, can you please take a look and ack as well? Thanks!
Thanks Andrii for the Cc! I realised yesterday morning that I'd been hit by the unsubscription incident and missed v3 of this set.
Yeah, super unfortunate this unsubscription. Had to go through that as well.
Quoted 5 lines
The changes look good to me, and you can add my tag to the first three patches:
Acked-by Quentin Monnet <[email protected]>
Thanks, I will.
Quoted 3 lines
Regarding patch 4, looking at the latest deprecations in libbpf, I would have expected the functions to be deprecated starting in v0.7, and not v0.6?
The reason to do it in upcoming v0.6 is because there are no replacement APIs that we are going to wait for. No point in delaying the inevitable just for the sake of delaying it.
Quoted 7 lines
Other than that, on patch 2 (apologies for not answering inline), it would feel more natural, in do_dump()'s "for" loop in
prog.c, to have thememset()above the call tobpf_obj_get_info_by_fd()(and to skip the zero-initialisation of "info") instead of at the end of the loop, which means a uselessmemset()just before we exit the loop. But probably not worth a respin just for that.
Yeah, that bothered me a bit as well, but if you are also mentioning that I'll just move it up as you suggested, while applying. Thanks.
Quoted 3 lines
Thanks,
Quentin
Andrii Nakryiko
AppliedQuoted 83 lines · Andrii Nakryiko
Quoted 50 lines · Quentin Monnet
2021-11-02 16:06 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 48 lines · Dave Marchevsky
Quoted 46 lines
bpf_program__get_prog_info_linearis a helper which wraps thebpf_obj_get_info_by_fdBPF syscall with some niceties that put all dynamic-lengthbpf_prog_infoin one buffer contiguous with structbpf_prog_info, and simplify the selection of which dynamic data to grab.The resultant combined struct,
bpf_prog_info_linear, is persisted to file by 'perf' to enable later annotation of BPF prog data. libbpf includes some vaddr <-> offset conversion helpers for structbpf_prog_info_linearto simplify this.This functionality is heavily tailored to perf's usecase, so its use as a general prog info API should be deemphasized in favor of just calling
bpf_obj_get_info_by_fd, which can be more easily fit to purpose. Some examples from caller migrations in this series:* Some callers weren't requesting or using dynamic-sized prog info and are well served by a simple
get_info_by_fdcall (e.g.dump_prog_id_as_func_ptrin bpftool)
* Some callers were requesting all of a specific dynamic info type but only using the first record, so can avoid unnecessary malloc by only requesting 1 (e.g.profile_target_namein bpftool)
* bpftool'sdo_dumpsaves some malloc/free by growing and reusing its dynamicprog_infobuf as it loops over progs to grab info and dump.Perf does need the full functionality of
bpf_program__get_prog_info_linearand its accompanying structs + helpers, so copy the code to its codebase, migrate all other uses in the tree, and deprecate the helper in libbpf.Since the deprecated symbols continue to be included in perf some renaming was necessary in perf's copy, otherwise functionality is unchanged.
This work was previously discussed in libbpf's issue tracker [0].
[0]: https://github.com/libbpf/libbpf/issues/313
v2->v3:
* Remove v2's patch 1 ("libbpf: Migrate internal use ofbpf_program__get_prog_info_linear"), which was applied [Andrii]
* Add new patch 1 migrating error checking of libbpf calls to new scheme [Andrii, Quentin]
* In patch 2, fix != -1 error check of libbpf call, improper realloc handling, and get rid of confusing macros [Andrii]
* In patch 4, deprecate starting from 0.6 instead of 0.7 [Andrii]Quoted 4 lines
Quoted 1 line
LGTM. Quentin, can you please take a look and ack as well? Thanks!
Thanks Andrii for the Cc! I realised yesterday morning that I'd been hit by the unsubscription incident and missed v3 of this set.
Yeah, super unfortunate this unsubscription. Had to go through that as well.
Quoted 5 lines
The changes look good to me, and you can add my tag to the first three patches:
Acked-by Quentin Monnet <[email protected]>Thanks, I will.
Quoted 3 lines
Regarding patch 4, looking at the latest deprecations in libbpf, I would have expected the functions to be deprecated starting in v0.7, and not v0.6?
The reason to do it in upcoming v0.6 is because there are no replacement APIs that we are going to wait for. No point in delaying the inevitable just for the sake of delaying it.
Quoted 7 lines
Other than that, on patch 2 (apologies for not answering inline), it would feel more natural, in do_dump()'s "for" loop in
prog.c, to have thememset()above the call tobpf_obj_get_info_by_fd()(and to skip the zero-initialisation of "info") instead of at the end of the loop, which means a uselessmemset()just before we exit the loop. But probably not worth a respin just for that.
Quoted 3 lines
Yeah, that bothered me a bit as well, but if you are also mentioning that I'll just move it up as you suggested, while applying. Thanks.
Applied to bpf-next, thanks.
Quoted 3 lines
Quoted 3 lines
Thanks,
Quentin