[RFC bpf-next 03/13] bpf: Move percpu memory allocator definition into core

Daniel Xu posted 13 patches 10 months ago
[RFC bpf-next 03/13] bpf: Move percpu memory allocator definition into core
Posted by Daniel Xu 10 months ago
The BPF percpu memory allocator is used from multiple places. So move it
into the core and have verifier.c simply consume it.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 include/linux/bpf.h   | 2 +-
 kernel/bpf/core.c     | 6 ++++++
 kernel/bpf/verifier.c | 3 ---
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index f1c5356dc099..8e26141f3e7e 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -64,7 +64,7 @@ extern struct idr btf_idr;
 extern spinlock_t btf_idr_lock;
 extern struct kobject *btf_kobj;
 extern struct bpf_mem_alloc bpf_global_ma, bpf_global_percpu_ma;
-extern bool bpf_global_ma_set;
+extern bool bpf_global_ma_set, bpf_global_percpu_ma_set;
 
 typedef u64 (*bpf_callback_t)(u64, u64, u64, u64, u64);
 typedef int (*bpf_iter_init_seq_priv_t)(void *private_data,
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index ba6b6118cf50..80ba83cb6350 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -68,6 +68,12 @@
 struct bpf_mem_alloc bpf_global_ma;
 bool bpf_global_ma_set;
 
+struct bpf_mem_alloc bpf_global_percpu_ma;
+EXPORT_SYMBOL_GPL(bpf_global_percpu_ma);
+
+bool bpf_global_percpu_ma_set;
+EXPORT_SYMBOL_GPL(bpf_global_percpu_ma_set);
+
 /* No hurry in this branch
  *
  * Exported for the bpf jit load helper.
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6ed302dab08b..322c1674b626 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -44,9 +44,6 @@ static const struct bpf_verifier_ops * const bpf_verifier_ops[] = {
 #undef BPF_LINK_TYPE
 };
 
-struct bpf_mem_alloc bpf_global_percpu_ma;
-static bool bpf_global_percpu_ma_set;
-
 /* bpf_check() is a static code analyzer that walks eBPF program
  * instruction by instruction and updates register/stack state.
  * All paths of conditional branches are analyzed until 'bpf_exit' insn.
-- 
2.47.1