On Wed, May 12, 2021 at 2:33 PM Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > From: Alexei Starovoitov <ast@xxxxxxxxxx> > > Introduce bpf_map__initial_value() to read initial contents > of rodata/bss maps. Note only mmaped maps qualify. > Just as bpf_map__set_initial_value() works only for mmaped kconfig. This sentence is confusing. bpf_map__set_initial_value() rejects LIBBPF_MAP_KCONFIG, so it *doesn't* work for kconfig. But your implementation will return non-NULL pointer for kconfig (it will be all zeroes before load). So did you intend to match set_initial_value() semantics or not? > > Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> > --- > tools/lib/bpf/libbpf.c | 8 ++++++++ > tools/lib/bpf/libbpf.h | 1 + > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 10 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 8fd70f0592ad..8d3b136c6b29 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -9736,6 +9736,14 @@ int bpf_map__set_initial_value(struct bpf_map *map, > return 0; > } > > +const void *bpf_map__initial_value(struct bpf_map *map, size_t *psize) > +{ > + if (!map->mmaped) > + return NULL; > + *psize = map->def.value_size; > + return map->mmaped; > +} > + > bool bpf_map__is_offload_neutral(const struct bpf_map *map) > { > return map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY; > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index 8cf168f3717c..a50eab5fec0a 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -471,6 +471,7 @@ LIBBPF_API int bpf_map__set_priv(struct bpf_map *map, void *priv, > LIBBPF_API void *bpf_map__priv(const struct bpf_map *map); > LIBBPF_API int bpf_map__set_initial_value(struct bpf_map *map, > const void *data, size_t size); > +LIBBPF_API const void *bpf_map__initial_value(struct bpf_map *map, size_t *psize); > LIBBPF_API bool bpf_map__is_offload_neutral(const struct bpf_map *map); > LIBBPF_API bool bpf_map__is_internal(const struct bpf_map *map); > LIBBPF_API int bpf_map__set_pin_path(struct bpf_map *map, const char *path); > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index 889ee2f3611c..dd0f24370939 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -359,6 +359,7 @@ LIBBPF_0.4.0 { > bpf_linker__finalize; > bpf_linker__free; > bpf_linker__new; > + bpf_map__initial_value; > bpf_map__inner_map; > bpf_object__gen_loader; > bpf_object__set_kversion; > -- > 2.30.2 >