Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: Add setter for initial value for internal maps

For internal maps (most notably the maps backing global variables), libbpf
uses an internal mmaped area to store the data after opening the object.
This data is subsequently copied into the kernel map when the object is
loaded.

This adds a function to set a new value for that data, which can be used to
before it is loaded into the kernel. This is especially relevant for RODATA
maps, since those are frozen on load.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200329132253.232541-1-toke@redhat.com

authored by

Toke Høiland-Jørgensen and committed by
Daniel Borkmann
e2842be5 5a95cbb8

+14
+11
tools/lib/bpf/libbpf.c
··· 6758 6758 return map ? map->priv : ERR_PTR(-EINVAL); 6759 6759 } 6760 6760 6761 + int bpf_map__set_initial_value(struct bpf_map *map, 6762 + const void *data, size_t size) 6763 + { 6764 + if (!map->mmaped || map->libbpf_type == LIBBPF_MAP_KCONFIG || 6765 + size != map->def.value_size || map->fd >= 0) 6766 + return -EINVAL; 6767 + 6768 + memcpy(map->mmaped, data, size); 6769 + return 0; 6770 + } 6771 + 6761 6772 bool bpf_map__is_offload_neutral(const struct bpf_map *map) 6762 6773 { 6763 6774 return map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
+2
tools/lib/bpf/libbpf.h
··· 407 407 LIBBPF_API int bpf_map__set_priv(struct bpf_map *map, void *priv, 408 408 bpf_map_clear_priv_t clear_priv); 409 409 LIBBPF_API void *bpf_map__priv(const struct bpf_map *map); 410 + LIBBPF_API int bpf_map__set_initial_value(struct bpf_map *map, 411 + const void *data, size_t size); 410 412 LIBBPF_API int bpf_map__reuse_fd(struct bpf_map *map, int fd); 411 413 LIBBPF_API int bpf_map__resize(struct bpf_map *map, __u32 max_entries); 412 414 LIBBPF_API bool bpf_map__is_offload_neutral(const struct bpf_map *map);
+1
tools/lib/bpf/libbpf.map
··· 243 243 bpf_link__pin; 244 244 bpf_link__pin_path; 245 245 bpf_link__unpin; 246 + bpf_map__set_initial_value; 246 247 bpf_program__set_attach_target; 247 248 bpf_set_link_xdp_fd_opts; 248 249 } LIBBPF_0.0.7;