From: Mike Bazov The previous patch was the last user of prog->active: the recursion of every program is checked per task now. Remove the counter, its bpf_prog_get_recursion_context() and bpf_prog_put_recursion_context() helpers, and the per-CPU memory that each program allocated for it. Signed-off-by: Mike Bazov --- include/linux/bpf.h | 36 ------------------------------------ kernel/bpf/core.c | 12 ------------ 2 files changed, 48 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index b24f26a48b77..7acb8b0ec576 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2055,7 +2055,6 @@ struct bpf_prog_aux { struct bpf_map __rcu *st_ops_assoc; }; -#define BPF_NR_CONTEXTS 4 /* normal, softirq, hardirq, NMI */ struct bpf_prog { u16 pages; /* Number of allocated pages */ @@ -2086,7 +2085,6 @@ struct bpf_prog { u8 tag[BPF_TAG_SIZE]; }; struct bpf_prog_stats __percpu *stats; - u8 __percpu *active; /* u8[BPF_NR_CONTEXTS] for recursion protection */ unsigned int (*bpf_func)(const void *ctx, const struct bpf_insn *insn); struct bpf_prog_aux *aux; /* Auxiliary fields */ @@ -2378,40 +2376,6 @@ struct bpf_struct_ops_common_value { enum bpf_struct_ops_state state; }; -static inline bool bpf_prog_get_recursion_context(struct bpf_prog *prog) -{ -#ifdef CONFIG_ARM64 - u8 rctx = interrupt_context_level(); - u8 *active = this_cpu_ptr(prog->active); - u32 val; - - preempt_disable(); - active[rctx]++; - val = le32_to_cpu(*(__le32 *)active); - preempt_enable(); - if (val != BIT(rctx * 8)) - return false; - - return true; -#else - return this_cpu_inc_return(*(int __percpu *)(prog->active)) == 1; -#endif -} - -static inline void bpf_prog_put_recursion_context(struct bpf_prog *prog) -{ -#ifdef CONFIG_ARM64 - u8 rctx = interrupt_context_level(); - u8 *active = this_cpu_ptr(prog->active); - - preempt_disable(); - active[rctx]--; - preempt_enable(); -#else - this_cpu_dec(*(int __percpu *)(prog->active)); -#endif -} - static inline bool is_tracing_multi(enum bpf_attach_type type) { return type == BPF_TRACE_FENTRY_MULTI || type == BPF_TRACE_FEXIT_MULTI || diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index facb0d6d2e8d..32a267656c0e 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -118,14 +118,6 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag vfree(fp); return NULL; } - fp->active = __alloc_percpu_gfp(sizeof(u8[BPF_NR_CONTEXTS]), 4, - bpf_memcg_flags(GFP_KERNEL | gfp_extra_flags)); - if (!fp->active) { - vfree(fp); - kfree(aux); - return NULL; - } - fp->pages = size / PAGE_SIZE; fp->aux = aux; fp->aux->main_prog_aux = aux; @@ -161,7 +153,6 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags) prog->stats = alloc_percpu_gfp(struct bpf_prog_stats, gfp_flags); if (!prog->stats) { - free_percpu(prog->active); kfree(prog->aux); vfree(prog); return NULL; @@ -282,7 +273,6 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size, */ fp_old->aux = NULL; fp_old->stats = NULL; - fp_old->active = NULL; __bpf_prog_free(fp_old); } @@ -302,7 +292,6 @@ void __bpf_prog_free(struct bpf_prog *fp) kfree(fp->aux); } free_percpu(fp->stats); - free_percpu(fp->active); vfree(fp); } @@ -1816,7 +1805,6 @@ static void bpf_prog_clone_free(struct bpf_prog *fp) */ fp->aux = NULL; fp->stats = NULL; - fp->active = NULL; __bpf_prog_free(fp); } -- 2.43.0