Skip to content

bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF

Viktor Malik bpf sashiko-reviews 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: Track CPUs that have executed a BPF programinclude/linux/filter.h kernel/bpf/core.c kernel/bpf/trampoline.c+39 -14 replies
2/2x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPFarch/x86/kernel/cpu/bugs.c+7 -12 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchValentin Schneider
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH bpf-next 0/2] bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF

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/[email protected]/

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(-)
Signature · 1 line
2.56.1