BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF
@ 2026-12-04 13:44 Viktor Malik
  2026-12-04 13:44 ` [PATCH bpf-next 1/2] bpf: Track CPUs that have executed a BPF program Viktor Malik
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Viktor Malik @ 2026-12-04 13:44 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, John Fastabend, Thomas Gleixner, Borislav Petkov,
	Peter Zijlstra, Josh Poimboeuf, Pawan Gupta, Ingo Molnar,
	Dave Hansen, x86, H. Peter Anvin, Valentin Schneider,
	Tomas Glozar, Viktor Malik

Hi,

we have recently started observing latency spikes on systems with
isolated CPUs when classic BPF programs were running in the background
(e.g. executed by NetworkManager or seccomp). The latencies are caused
by the BPF JIT-spraying mitigation introduced by commit 96cce16e26dd
("bpf: Support for hardening against JIT spraying") and its follow-ups.
The reason is that the IBPB flush is currently broadcast to every online
CPU, including the isolated ones that never run BPF programs.

While recent changes [1] have significantly decreased the frequency of
the IBPB flushes, they haven't eliminated them completely, which still
poses a serious problem for latency-sensitive workloads.

This patch series implement one of the ideas from a9b1f19a6a67 ("bpf:
Prefer packs that won't trigger an IBPB flush on allocation") and
introduce a mechanism to completely avoid the IBPB flushes on CPUs that
have not run any BPF program since the last flush. This is sound because
the original Spectre-v2 vulnerability is only exploitable if a cBPF
program runs on a CPU that previously ran any BPF program (and therefore
can reuse the branch predictors trained on the previous program).

Patch #1 introduces a new per-cpu flag bpf_prog_ran, which records that
a CPU executed any BPF program, and patch #2 restricts the IBPB flushes
on x86 to CPUs that have the flag set. This way, the isolated CPUs that
never run any BPF programs do not receive the unnecessary flushes.

[1] https://lore.kernel.org/bpf/cover.1796304466.git.xukuohai@huawei.com/

Viktor Malik (2):
  bpf: Track CPUs that have executed a BPF program
  x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF

 arch/x86/kernel/cpu/bugs.c |  8 +++++++-
 include/linux/filter.h     | 27 ++++++++++++++++++++++++++-
 kernel/bpf/core.c          |  8 ++++++++
 kernel/bpf/trampoline.c    |  5 +++++
 4 files changed, 46 insertions(+), 2 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-12-04 19:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 13:44 [PATCH bpf-next 0/2] bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF Viktor Malik
2026-12-04 13:44 ` [PATCH bpf-next 1/2] bpf: Track CPUs that have executed a BPF program Viktor Malik
2026-12-04 14:03   ` sashiko-bot
2026-12-04 15:22     ` Viktor Malik
2026-12-04 14:51   ` Valentin Schneider
2026-12-04 16:27   ` Dave Hansen
2026-12-04 16:45     ` Viktor Malik
2026-12-04 13:44 ` [PATCH bpf-next 2/2] x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF Viktor Malik
2026-12-04 14:17   ` sashiko-bot
2026-12-04 15:33     ` Viktor Malik
2026-12-04 14:51   ` Valentin Schneider
2026-12-04 15:01 ` [PATCH bpf-next 0/2] bpf, x86: " Valentin Schneider
2026-12-04 16:37   ` Dave Hansen
2026-12-04 17:46     ` Valentin Schneider
2026-12-04 19:42       ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox