提交 74260b69 编写于 作者: A Alexei Starovoitov 提交者: Zheng Zengkai

libbpf: Introduce bpf_map__initial_value().

mainline inclusion
from mainline-5.14-rc1
commit 7723256b
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7723256bf2443d6bd7db3e583953d14107955233

-------------------------------------------------

Introduce bpf_map__initial_value() to read initial contents
of mmaped data/rodata/bss maps.
Note that bpf_map__set_initial_value() doesn't allow modifying
kconfig map while bpf_map__initial_value() allows reading
its values.
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210514003623.28033-17-alexei.starovoitov@gmail.com
(cherry picked from commit 7723256b)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 fcbd883a
...@@ -9828,6 +9828,14 @@ int bpf_map__set_initial_value(struct bpf_map *map, ...@@ -9828,6 +9828,14 @@ int bpf_map__set_initial_value(struct bpf_map *map,
return 0; 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) bool bpf_map__is_offload_neutral(const struct bpf_map *map)
{ {
return map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY; return map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
......
...@@ -475,6 +475,7 @@ LIBBPF_API int bpf_map__set_priv(struct bpf_map *map, void *priv, ...@@ -475,6 +475,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 void *bpf_map__priv(const struct bpf_map *map);
LIBBPF_API int bpf_map__set_initial_value(struct bpf_map *map, LIBBPF_API int bpf_map__set_initial_value(struct bpf_map *map,
const void *data, size_t size); 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_offload_neutral(const struct bpf_map *map);
LIBBPF_API bool bpf_map__is_internal(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); LIBBPF_API int bpf_map__set_pin_path(struct bpf_map *map, const char *path);
......
...@@ -359,6 +359,7 @@ LIBBPF_0.4.0 { ...@@ -359,6 +359,7 @@ LIBBPF_0.4.0 {
bpf_linker__finalize; bpf_linker__finalize;
bpf_linker__free; bpf_linker__free;
bpf_linker__new; bpf_linker__new;
bpf_map__initial_value;
bpf_map__inner_map; bpf_map__inner_map;
bpf_object__gen_loader; bpf_object__gen_loader;
bpf_object__set_kversion; bpf_object__set_kversion;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册