WSL2-Linux-Kernel/kernel/bpf
Martin KaFai Lau 6ae9d5e99e bpf: Use bpf_mem_cache_alloc/free for bpf_local_storage
This patch uses bpf_mem_cache_alloc/free for allocating and freeing
bpf_local_storage for task and cgroup storage.

The changes are similar to the previous patch. A few things that
worth to mention for bpf_local_storage:

The local_storage is freed when the last selem is deleted.
Before deleting a selem from local_storage, it needs to retrieve the
local_storage->smap because the bpf_selem_unlink_storage_nolock()
may have set it to NULL. Note that local_storage->smap may have
already been NULL when the selem created this local_storage has
been removed. In this case, call_rcu will be used to free the
local_storage.
Also, the bpf_ma (true or false) value is needed before calling
bpf_local_storage_free(). The bpf_ma can either be obtained from
the local_storage->smap (if available) or any of its selem's smap.
A new helper check_storage_bpf_ma() is added to obtain
bpf_ma for a deleting bpf_local_storage.

When bpf_local_storage_alloc getting a reused memory, all
fields are either in the correct values or will be initialized.
'cache[]' must already be all NULLs. 'list' must be empty.
Others will be initialized.

Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20230322215246.1675516-4-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-03-25 19:52:52 -07:00
..
preload bpf: iterators: Split iterators.lskel.h into little- and big- endian versions 2023-01-28 12:45:15 -08:00
Kconfig
Makefile bpf: Enable cpumasks to be queried and used as kptrs 2023-01-25 07:57:49 -08:00
arraymap.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
bloom_filter.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
bpf_cgrp_storage.c bpf: Use bpf_mem_cache_alloc/free in bpf_local_storage_elem 2023-03-25 19:52:52 -07:00
bpf_inode_storage.c bpf: Use bpf_mem_cache_alloc/free in bpf_local_storage_elem 2023-03-25 19:52:52 -07:00
bpf_iter.c bpf: implement numbers iterator 2023-03-08 16:19:51 -08:00
bpf_local_storage.c bpf: Use bpf_mem_cache_alloc/free for bpf_local_storage 2023-03-25 19:52:52 -07:00
bpf_lru_list.c
bpf_lru_list.h
bpf_lsm.c bpf: Fix the kernel crash caused by bpf_setsockopt(). 2023-01-26 23:26:40 -08:00
bpf_struct_ops.c bpf: Check IS_ERR for the bpf_map_get() return value 2023-03-24 12:40:47 -07:00
bpf_struct_ops_types.h
bpf_task_storage.c bpf: Use bpf_mem_cache_alloc/free in bpf_local_storage_elem 2023-03-25 19:52:52 -07:00
btf.c bpf: Disable migration when freeing stashed local kptr using obj drop 2023-03-13 16:55:04 -07:00
cgroup.c bpf: allow ctx writes using BPF_ST_MEM instruction 2023-03-03 21:41:46 -08:00
cgroup_iter.c
core.c bpf: add missing header file include 2023-02-22 09:52:32 -08:00
cpumap.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
cpumask.c bpf: Treat KF_RELEASE kfuncs as KF_TRUSTED_ARGS 2023-03-25 16:56:22 -07:00
devmap.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
disasm.c
disasm.h
dispatcher.c bpf: Synchronize dispatcher update with bpf_dispatcher_xdp_func 2022-12-14 12:02:14 -08:00
hashtab.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
helpers.c bpf: Remove now-unnecessary NULL checks for KF_RELEASE kfuncs 2023-03-25 16:56:22 -07:00
inode.c fs: port inode_init_owner() to mnt_idmap 2023-01-19 09:24:28 +01:00
link_iter.c
local_storage.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
lpm_trie.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
map_in_map.c
map_in_map.h
map_iter.c
memalloc.c bpf: Add a few bpf mem allocator functions 2023-03-25 19:52:51 -07:00
mmap_unlock_work.h
net_namespace.c
offload.c bpf: offload map memory usage 2023-03-07 09:33:43 -08:00
percpu_freelist.c
percpu_freelist.h
prog_iter.c
queue_stack_maps.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
reuseport_array.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
ringbuf.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
stackmap.c bpf: return long from bpf_map_ops funcs 2023-03-22 15:11:30 -07:00
syscall.c bpf: Only invoke kptr dtor following non-NULL xchg 2023-03-25 16:56:22 -07:00
sysfs_btf.c
task_iter.c bpf: keep a reference to the mm, in case the task is dead. 2022-12-28 14:11:48 -08:00
tnum.c
trampoline.c bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules 2023-03-15 18:38:21 -07:00
verifier.c bpf: Treat KF_RELEASE kfuncs as KF_TRUSTED_ARGS 2023-03-25 16:56:22 -07:00