Message ID | 20210508034837.64585-18-alexei.starovoitov@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | bpf: syscall program, FD array, loader program, light skeleton. | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | fail | Series longer than 15 patches |
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | warning | 6 maintainers not CCed: netdev@vger.kernel.org yhs@fb.com kpsingh@kernel.org kafai@fb.com ast@kernel.org songliubraving@fb.com |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 31 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
On Fri, May 7, 2021 at 8:49 PM Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > From: Alexei Starovoitov <ast@kernel.org> > > Introduce bpf_map__get_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. > > Signed-off-by: Alexei Starovoitov <ast@kernel.org> > --- > tools/lib/bpf/libbpf.c | 10 ++++++++++ > tools/lib/bpf/libbpf.h | 2 ++ > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 13 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 24a659448782..f7cdbb0e1faf 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -9763,6 +9763,16 @@ int bpf_map__set_initial_value(struct bpf_map *map, > return 0; > } > > +int bpf_map__get_initial_value(struct bpf_map *map, > + const void **pdata, size_t *psize) the general patterns (there are legacy exceptions) for getters is to not have "get_" in the name. Please rename it to just bpf_map__initial_value(). Also btf__get_raw_data() (note the legacy naming) follows a slightly different pattern of returning NULL on error or valid pointer on success. And then the size is returned as outer param. Unless there is a good reason not to, let's be consistent with that pattern? > +{ > + if (!map->mmaped) > + return -EINVAL; > + *psize = map->def.value_size; > + *pdata = map->mmaped; > + return 0; > +} > + > 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 fb291b4529e8..f8976a30586f 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -471,6 +471,8 @@ 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 int bpf_map__get_initial_value(struct bpf_map *map, > + const void **pdata, 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..44285045ddf4 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -360,6 +360,7 @@ LIBBPF_0.4.0 { > bpf_linker__free; > bpf_linker__new; > bpf_map__inner_map; > + bpf_map__get_initial_value; nit: g < i, and as bpf_map__initial_value will still go before inner_map getter > bpf_object__gen_loader; > bpf_object__set_kversion; > } LIBBPF_0.3.0; > -- > 2.30.2 >
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 24a659448782..f7cdbb0e1faf 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9763,6 +9763,16 @@ int bpf_map__set_initial_value(struct bpf_map *map, return 0; } +int bpf_map__get_initial_value(struct bpf_map *map, + const void **pdata, size_t *psize) +{ + if (!map->mmaped) + return -EINVAL; + *psize = map->def.value_size; + *pdata = map->mmaped; + return 0; +} + 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 fb291b4529e8..f8976a30586f 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -471,6 +471,8 @@ 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 int bpf_map__get_initial_value(struct bpf_map *map, + const void **pdata, 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..44285045ddf4 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -360,6 +360,7 @@ LIBBPF_0.4.0 { bpf_linker__free; bpf_linker__new; bpf_map__inner_map; + bpf_map__get_initial_value; bpf_object__gen_loader; bpf_object__set_kversion; } LIBBPF_0.3.0;