[RFC bpf-next 07/13] bpf: Make bpf_free_kfunc_btf_tab() static in core

From: Daniel Xu
Date: Tue Apr 08 2025 - 23:36:42 EST


This function is only used in one place in core. However, it was defined
in verifier.c b/c a bunch of struct definitions were hidden in
verifier.c. Now that those definitions are shared, we can move
bpf_free_kfunc_btf_tab() into core and mark it static.

Signed-off-by: Daniel Xu <dxu@xxxxxxxxx>
---
include/linux/bpf_verifier.h | 2 --
kernel/bpf/core.c | 13 +++++++++++++
kernel/bpf/verifier.c | 12 ------------
3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index f61f5429647a..f9a203e5f042 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -879,8 +879,6 @@ static inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)
*btf_id = key & 0x7FFFFFFF;
}

-void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);
-
int mark_chain_precision(struct bpf_verifier_env *env, int regno);

#define BPF_BASE_TYPE_MASK GENMASK(BPF_BASE_TYPE_BITS - 1, 0)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 8cbfe7d33c0a..e892e469061e 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -3251,6 +3251,19 @@ static void bpf_free_used_btfs(struct bpf_prog_aux *aux)
kfree(aux->used_btfs);
}

+static void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab)
+{
+ if (!tab)
+ return;
+
+ while (tab->nr_descs--) {
+ module_put(tab->descs[tab->nr_descs].module);
+ btf_put(tab->descs[tab->nr_descs].btf);
+ }
+ kfree(tab);
+}
+
+
static void bpf_prog_free_deferred(struct work_struct *work)
{
struct bpf_prog_aux *aux;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 161280f3371f..7e84df2abe41 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -3029,18 +3029,6 @@ static struct btf *__find_kfunc_desc_btf(struct bpf_verifier_env *env,
return btf;
}

-void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab)
-{
- if (!tab)
- return;
-
- while (tab->nr_descs--) {
- module_put(tab->descs[tab->nr_descs].module);
- btf_put(tab->descs[tab->nr_descs].btf);
- }
- kfree(tab);
-}
-
static struct btf *find_kfunc_desc_btf(struct bpf_verifier_env *env, s16 offset)
{
if (offset) {
--
2.47.1