From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796393026; b=z7e88HvtTl9X+44vkocDz8ZADywXsl5on9lgxSAHRC9m1vB1hF6zFdFvS0z46yME/Khg LVn+3AWK9cF3AFFqGE6+uL1tGuD2Rp2P6SOQV9hSBbG2lOUrbLbwZIYwyFiwh3Ps8Qibz eHOG3h8rrypWy+XqEQxe1yE38LJe/E1lBmusF4sREgC3QYLY5qLQAhY8+nHu8olCcAbvd 7nB+vWik5hYYDtU4LB4Ugkj+4rj0kprxOh0fzXdj/shPD+8PPy6gp2R12Xc8hzVk88/qF klKj5cEo5rSJQ1GPtHxY5S+TjB2388bFV+b8UuBjtvvqRevvXm9+Rhrs96fkoHAeSfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796393026; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=1EiMrAHEmNVjY62wUCD5gnPab6WMyP525UXL9hLaGAg=; b=TTrubLLEPg4MC4aJb9KvWvsTveRY13cEYmGkhW4ntTjU8e/dRskvTcgMTmAtP4pxC2Yc 7gKD3XZuW5UKsIVbbnsAR1T3UO6xty+va7+NQkuVQ/+WmWLLDrAt//ZvpXN+5sf1Uqzju 5Y+csHqzItbia45ArHLgj1sCmoAmrfZGU3oeZlhcDv60LxMpgGip4XXSAWV19A7MLnAPY 2S9id0uhBRqEMkZqTRF9I3lentNFZsYGc0WF3HGddJXBBnaYqD0dGwiBAhDr1mbCn9Y6R zfGViquhWYKcBWbQIGXB+qok9fOU0TtgqrQEp5FOB3vA0WPB1CLxlwzHqlh/ugEiQlQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gQobG66f; arc=none 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 12356606A32C for ; Fri, 4 Dec 2026 14:03:46 +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=gQobG66f Received: by smtp.kernel.org (Postfix) with ESMTPSA id 504191F000CE; Fri, 4 Dec 2026 14:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796393025; bh=1EiMrAHEmNVjY62wUCD5gnPab6WMyP525UXL9hLaGAg=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=gQobG66ffmjgw/W2JAZ2l01+S6l/NwYZpTQ06HFHuYfL1rg24I9JGLWbbOqc+9dNh AqnDWkzJxRSJ8BNFbf+BXhhFy573/75wlz6hNSgykQDO8x9R4GY80BlOGcHZLtkQ2c wMNW+OSt9G7s5ufBxVQJ14Nu8E60+6nh7QkthlocbkR/NjTRaz2Kf4IVGp7v82DFoz 5cl73ViAgYNojTfGexEwoPxnNfGIsJOvE1WHWhA2jXnIuQOx/zwYN2tBjKYv2JhleW 4+2vRh/yYc+FVT6xeAZvxwp2PnNpGnHo8Pr2Dd9laE5sEQwkq3CnfRItKPbtsxhHHb Pd24h91n8RK9g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next 1/2] bpf: Track CPUs that have executed a BPF program Reply-To: sashiko-reviews@lists.linux.dev To: "Viktor Malik" , bpf@vger.kernel.org In-Reply-To: <5cf89312e3fea4409dc1fc9da6aa37b1e7a7f3b5.1796391323.git.vmalik@redhat.com> References: <5cf89312e3fea4409dc1fc9da6aa37b1e7a7f3b5.1796391323.git.vmalik@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:03:44 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] bpf: link failure under CONFIG_BPF_JIT=3Dn in bpf_prog_mark_ran() - [Medium] bpf: missing bpf_prog_mark_ran() in bpf_run_async_cb() - [Low] bpf: untracked bpf_prog_pack trampoline execution bypassing __bpf_prog_exit*() -- commit a794f32a47f5dda2a5c528bf869f1bd4c8182a6e Author: Viktor Malik bpf: Track CPUs that have executed a BPF program This commit introduces a per-CPU bpf_prog_ran flag, gated behind the bpf_pred_flush_enabled static key, and sets it in __bpf_prog_run() and the trampoline exit helpers so arch code can restrict indirect branch predictor flushes to CPUs that have executed BPF code. > diff --git a/include/linux/filter.h b/include/linux/filter.h > index 275c89ed7574a..cb408ddbca2f0 100644 > --- a/include/linux/filter.h > +++ b/include/linux/filter.h > @@ -873,6 +873,31 @@ typedef unsigned int (*bpf_dispatcher_fn)(const void= *ctx, > unsigned int (*bpf_func)(const void *, > const struct bpf_insn *)); > =20 > +DECLARE_STATIC_KEY_FALSE(bpf_pred_flush_enabled); > +DECLARE_PER_CPU(bool, bpf_prog_ran); > + > +/* > + * When BPF JIT-spraying mitigation is in place, record, on the current = CPU, > + * that a JITed BPF program has just executed. > + * > + * The mitigation flushes the indirect branch predictors (IBPB on x86) w= hen cBPF > + * JIT memory is reused, to drop stale predictions from the code that pr= eviously > + * occupied that memory. That flush is only ever needed on CPUs that have > + * actually executed BPF since the last flush, so arch code consults thi= s flag > + * to target those CPUs. > + */ > +static __always_inline void bpf_prog_mark_ran(void) > +{ > + bool *ran; > + > + if (!static_branch_unlikely(&bpf_pred_flush_enabled)) > + return; > + > + ran =3D raw_cpu_ptr(&bpf_prog_ran); > + if (!READ_ONCE(*ran)) > + WRITE_ONCE(*ran, true); > +} [Severity: High] Does this break linking when CONFIG_BPF=3Dy and CONFIG_BPF_JIT=3Dn? bpf_pred_flush_enabled and bpf_prog_ran are declared and referenced unconditionally here, but both definitions and exports in kernel/bpf/core.c sit inside #ifdef CONFIG_BPF_JIT. Any interpreter-only build with callers of __bpf_prog_run(), such as seccomp_run_filters(), will fail vmlinux link and module modpost with undefined references to both symbols. Guarding the declarations and bpf_prog_mark_ran() with #ifdef CONFIG_BPF_JIT and providing an empty stub otherwise fixes the build and avoids emitting a dead static branch when JIT is disabled. [ ... ] > @@ -898,6 +923,7 @@ static __always_inline u32 __bpf_prog_run(const struc= t bpf_prog *prog, > } else { > ret =3D dfunc(ctx, prog->insnsi, prog->bpf_func); > } > + bpf_prog_mark_ran(); > return ret; > } [Severity: Medium] Should bpf_run_async_cb() in kernel/bpf/helpers.c also call bpf_prog_mark_ran()? Async BPF callbacks (such as bpf_timer_cb() and bpf_wq_work()) invoke JITed subprograms allocated from bpf_prog_pack directly via callback_fn(), bypassing __bpf_prog_run() and the trampoline exit helpers. A CPU that runs one while bpf_prog_ran is false is skipped by a later targeted flush when those bpf_prog_pack chunks are reused by cBPF, leaving stale indirect branch predictions live. All callers of bpf_run_async_cb() already run with migration disabled, so calling bpf_prog_mark_ran() after callback_fn() there closes this gap. [ ... ] > diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c > index 619297eae8c15..43c1b2fb88399 100644 > --- a/kernel/bpf/trampoline.c > +++ b/kernel/bpf/trampoline.c > @@ -1382,6 +1382,7 @@ static void notrace __bpf_prog_exit_recur(struct bp= f_prog *prog, u64 start, > struct bpf_tramp_run_ctx *run_ctx) > __releases(RCU) > { > + bpf_prog_mark_ran(); > /* Before the exit, which can enable preemption: time off the CPU is no= t run time */ > update_prog_stats(prog, start); > bpf_prog_exit_run_ctx(prog, &run_ctx->run_ctx); [Severity: Low] Can a CPU execute JITed trampoline code from bpf_prog_pack without setting bpf_prog_ran? On x86-64, arch_alloc_bpf_trampoline() allocates trampolines from bpf_prog_pack, and under BPF_TRAMP_F_ORIG_STACK the trampoline runs an indirect call *rbx there with migration enabled. In an fexit-only trampoline, a task can run call *rbx on CPU0, sleep in the original function, and migrate to CPU1 where __bpf_prog_exit*() runs, leaving bpf_prog_ran false on CPU0. The same happens through __bpf_tramp_exit() or during skip patching in __bpf_trampoline_unlink_prog(= ). If the trampoline image is later freed and reused by a cBPF allocation, a targeted predictor flush would skip that CPU. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796391323.gi= t.vmalik@redhat.com?part=3D1