From: Mykyta Yatsenko A storage object must have room for the slots of the inline maps of its owner type. Make a new object as big as the end of the last used slot. The size of an object does not change after that, so the slots that an object holds stay at fixed places. No map can have a slot yet, so all objects keep the size of the struct. Signed-off-by: Mykyta Yatsenko --- kernel/bpf/bpf_local_storage.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c index eed6f18bf52a..072807a1245f 100644 --- a/kernel/bpf/bpf_local_storage.c +++ b/kernel/bpf/bpf_local_storage.c @@ -525,6 +525,17 @@ static int check_flags(const struct bpf_local_storage_data *old_sdata, return 0; } +/* + * Once an inline map exists, a new object gets an inline area up to the end + * of the last slot, also for other maps. Its size does not change. + */ +static u32 bpf_local_storage_obj_size(struct bpf_local_storage_map *smap) +{ + u32 end = max(READ_ONCE(smap->cache->inline_end), smap->inline_end); + + return end ? kmalloc_size_roundup(end) : sizeof(struct bpf_local_storage); +} + int bpf_local_storage_alloc(void *owner, struct bpf_local_storage_map *smap, struct bpf_local_storage_elem *first_selem) @@ -532,7 +543,7 @@ int bpf_local_storage_alloc(void *owner, struct bpf_local_storage *prev_storage, *storage; struct bpf_local_storage **owner_storage_ptr; struct bpf_local_storage_map_bucket *b; - u32 size = sizeof(*storage); + u32 size = bpf_local_storage_obj_size(smap); unsigned long flags; int err; -- 2.53.1-Meta