From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796139183; b=HQja5WGyrO7ugEem2w/vOfAxxJ2l3EonIB72qHap/J3KNvUv1Ra0QB6qOiPc8AzmqzLF dr49O5MmoqDZY1RXwSQc8ytBusCW8MaTF3LqzyfZJZugMpKY1Ok9WQ34xT12e9z8L3TsB e1LMsk7o3CQSfMw6ngyHdYOzHAvnMc0P2glyf56Q1Ks0MVO3oHQaHWYeKhUFF0qPxPG0B 1Rh3x6C59qRhNv+4ONaR4SnZPvHAVDgBW/FHPevVBRtKv1KcPuYaDTnieipTxSYF0mIO+ UfGG1hJaht81FCy7qa5d50KpU7UYP/knAgr9SwHOzv7PJWo9RMt1rjvbq+hdCF7tyww== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139183; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BaGzO4pgMIY69sf++DmVYabw2YkohDXjpdIMQ0spmTY=; b=sG7wtHtGaZLOxIBiFe9r6D/ckywu94LxQPIqudtMU8gYzWbSLXK0PVf35yWLpGrboSuE 6TKJMP+aklzsg6TDjc9mHAeUsy6mYMAddYt1p7yL6cNVXoJ0XkJiPEeTPTqc3lGFIcmt9 7ttedX4Fqdo6p0ZeDb7McbhEOYEY2UxYDNJd6JZshbWYZESueaJxEqxhXTVGTSQgp3RDp OGqvryMCfZfwlDnI9DckbdiYcNCxmneeW1XD9DffqwMeodZSuplDCoaMf4EwfTDSfrvv1 CPVkfprjNrKICpIFE9nSyLN6z3VG8TnVIvO/3hi9TRPeUDbDXmjm+BO5ypscCc7OHiA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gYoHbysm; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FA6E606A33B; Tue, 1 Dec 2026 15:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gYoHbysm Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796139182; b=eSvEs0x2V9GhHu9hjB0UXh6F9Wvook3XhF7bEGhYqCOAEdWPFuuDgc0Yf4kID5Ug7PqN Y+AirY4OtGAfEhpSWXMfLxZymMuoQr/5u7zqh+iRo9MZDqN0IelBgRdTwZ8RmtDdHtARX xN00vBtVDgqm6okPHvP0o/0Zg6Red8BNrTXdltHt40Ii4IENYRJQc1fqUCggQ94+CPdiB kjXroA/MZ7TbzVzXd5yT30xudu+ubnkSZy1iy0BkvZSLagRb21kGwi0hrijw5mK7tAuBG 4wbUXguUCQr7HM7HjFae2f8EnSLKyRdvTCX4A+zddRw1XRXLTpzhwb45bJCxLVBwSDQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796139182; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BaGzO4pgMIY69sf++DmVYabw2YkohDXjpdIMQ0spmTY=; b=QeY1wvZW9BKsFwwp9syrIgFQ52wdSagrK8etU5bUl3Coz6Y8zgYPvfT7t2O8q1f3LA/M J2VVa9foT8CKIJ2tS+09M5vKXBZcI9MzdzFFoiXU2OhhpZ/M/BFoE7s4/evRqke04f6E5 DAXS8NtLuHsRrAuk0+svBpAA5VermRxjCZhMnV3LHxOXd9EhID5pmpmcbLuR94NCD3JlB aMTIa4Ge5MYEXNwCkqzwN/EStgUsLBkAIMFEl5axA08yydELpgVWl0ieUAFpAATfY7fAs gqn3GoI7rBWB6HHxbof/Jb8CbWsoR8IQsCwHiHOFbSa6taQrXq1EhkjVQqXMVD9cshA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 8F7F81F0093A; Tue, 1 Dec 2026 15:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796139182; bh=BaGzO4pgMIY69sf++DmVYabw2YkohDXjpdIMQ0spmTY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=gYoHbysmleAnzZ+ZH2L9Ymy52mVuwED6sqarD3KGRl9XPYTZdcbWUm4aie7M51dvj CZAGwS61jHpsEUPShIvWWavg7zrROEVQq5NgvChZ5YiTknW4RftK7PhEzv3Wt5nO01 s4fS85M4u19UE33mBnOstWLAnoBY075+R3FHvFVbppytj351khOGN3YiAEMht2LLlc d8UorgKoq0qlglmTc4rSKsebt98HE6NiaT4+OVW6ZkR6fiY9EVWd1xwxus+nKeP6kB Y4ZlK1T55W1o4D7GwTGeekhnDULus95K/DAH6zJHL1lt63veYP6Cgm7YUWpzopTBqg B0AxnLHH/1prg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 14F534EE80; Tue, 1 Dec 2026 15:32:34 +0000 (UTC) From: Mike Bazov via B4 Relay Date: Tue, 01 Dec 2026 17:32:15 +0200 Subject: [PATCH bpf-next v5 4/5] bpf: Remove the per-CPU recursion counter of programs X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-bpf-preempt-v2-r2-v5-4-a6bb30daae35@sentinelone.com> References: <20261201-bpf-preempt-v2-r2-v5-0-a6bb30daae35@sentinelone.com> In-Reply-To: <20261201-bpf-preempt-v2-r2-v5-0-a6bb30daae35@sentinelone.com> To: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , John Fastabend , Emil Tsalapatis , Ihor Solodrai , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , JP Kobryn , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Bazov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796139152; l=3685; i=mikeba@sentinelone.com; s=20261022; h=from:subject:message-id; bh=sMlGGh+4PNtOew5gXfucz1Pq/zCn3LIfp4US0L1bcf8=; b=falh3zfY32l6jzyafdDr/xq8jdPGf7CQh0F2dSLsqUnvY6uZWXMTKXVLj2SDC5l0ONZhVT9q4 6LxHo2MugvRBMKMzBcrp0CMvx0Vpkh8xXsL/sZCHY0H7Pez5Bf+lo6s X-Developer-Key: i=mikeba@sentinelone.com; a=ed25519; pk=DBXcQ0qoCkgacRsRwT1JU7oOWpWSYuTyLiXMfNLcP+A= X-Endpoint-Received: by B4 Relay for mikeba@sentinelone.com/20261022 with auth_id=1284 X-Original-From: Mike Bazov Reply-To: mikeba@sentinelone.com Content-Transfer-Encoding: 7bit From: Mike Bazov Recursion of every program that used prog->active is checked per task now. Remove the counter, the bpf_prog_get_recursion_context() and bpf_prog_put_recursion_context() helpers, BPF_NR_CONTEXTS, and the per-CPU memory that each program allocated for it. Signed-off-by: Mike Bazov --- include/linux/bpf.h | 37 ------------------------------------- kernel/bpf/core.c | 12 ------------ 2 files changed, 49 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 2172e732ccc2..648a8b9be47b 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2055,8 +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 */ u32 jited:1, /* Is our filter JIT'ed? */ @@ -2086,7 +2084,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 */ @@ -2379,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