libbpf: Add capability for resizing datasec maps
authorJP Kobryn <inwardvessel@gmail.com>
Wed, 24 May 2023 00:45:36 +0000 (17:45 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 24 May 2023 18:44:16 +0000 (11:44 -0700)
commit9d0a23313b1aa107df857e8441ea2ed74811ea17
treed3e91563c9a3d95b1e8a3bd72a08b522d940a8f2
parent3b22f98e5a05feee20699df0870dc5d47c9b61dd
libbpf: Add capability for resizing datasec maps

This patch updates bpf_map__set_value_size() so that if the given map is
memory mapped, it will attempt to resize the mapped region. Initial
contents of the mapped region are preserved. BTF is not required, but
after the mapping is resized an attempt is made to adjust the associated
BTF information if the following criteria is met:
 - BTF info is present
 - the map is a datasec
 - the final variable in the datasec is an array

... the resulting BTF info will be updated so that the final array
variable is associated with a new BTF array type sized to cover the
requested size.

Note that the initial resizing of the memory mapped region can succeed
while the subsequent BTF adjustment can fail. In this case, BTF info is
dropped from the map by clearing the key and value type.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20230524004537.18614-2-inwardvessel@gmail.com
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h