bpf: Use separate RCU callbacks for freeing selem
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Fri, 3 Mar 2023 14:15:42 +0000 (15:15 +0100)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 3 Mar 2023 17:45:27 +0000 (09:45 -0800)
commite768e3c5aab44ee63f58649d4c8cbbb3270e5c06
tree8cbf80f196feba40d3f6875151593bef55010743
parentdb55174d05ee6bed9d0583ba08e99c891ef0ed05
bpf: Use separate RCU callbacks for freeing selem

Martin suggested that instead of using a byte in the hole (which he has
a use for in his future patch) in bpf_local_storage_elem, we can
dispatch a different call_rcu callback based on whether we need to free
special fields in bpf_local_storage_elem data. The free path, described
in commit 9db44fdd8105 ("bpf: Support kptrs in local storage maps"),
only waits for call_rcu callbacks when there are special (kptrs, etc.)
fields in the map value, hence it is necessary that we only access
smap in this case.

Therefore, dispatch different RCU callbacks based on the BPF map has a
valid btf_record, which dereference and use smap's btf_record only when
it is valid.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20230303141542.300068-1-memxor@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
include/linux/bpf_local_storage.h
kernel/bpf/bpf_local_storage.c