aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/percpu_alloc_array.c
diff options
context:
space:
mode:
authorYonghong Song <[email protected]>2023-08-27 15:27:44 +0000
committerAlexei Starovoitov <[email protected]>2023-09-08 15:42:17 +0000
commit36d8bdf75a93190e5669b9d1d95994e13e15ba1d (patch)
tree0866b8a5413703ee8c5bbb778f008f095195e850 /tools/testing/selftests/bpf/progs/percpu_alloc_array.c
parentbpf: Add BPF_KPTR_PERCPU as a field type (diff)
downloadkernel-36d8bdf75a93190e5669b9d1d95994e13e15ba1d.tar.gz
kernel-36d8bdf75a93190e5669b9d1d95994e13e15ba1d.zip
bpf: Add alloc/xchg/direct_access support for local percpu kptr
Add two new kfunc's, bpf_percpu_obj_new_impl() and bpf_percpu_obj_drop_impl(), to allocate a percpu obj. Two functions are very similar to bpf_obj_new_impl() and bpf_obj_drop_impl(). The major difference is related to percpu handling. bpf_rcu_read_lock() struct val_t __percpu_kptr *v = map_val->percpu_data; ... bpf_rcu_read_unlock() For a percpu data map_val like above 'v', the reg->type is set as PTR_TO_BTF_ID | MEM_PERCPU | MEM_RCU if inside rcu critical section. MEM_RCU marking here is similar to NON_OWN_REF as 'v' is not a owning reference. But NON_OWN_REF is trusted and typically inside the spinlock while MEM_RCU is under rcu read lock. RCU is preferred here since percpu data structures mean potential concurrent access into its contents. Also, bpf_percpu_obj_new_impl() is restricted such that no pointers or special fields are allowed. Therefore, the bpf_list_head and bpf_rb_root will not be supported in this patch set to avoid potential memory leak issue due to racing between bpf_obj_free_fields() and another bpf_kptr_xchg() moving an allocated object to bpf_list_head and bpf_rb_root. Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/percpu_alloc_array.c')
0 files changed, 0 insertions, 0 deletions