All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp
@ 2026-11-20  6:48 Xu Kuohai
  2026-11-20  6:48 ` [RFC PATCH 1/3] bpf: Introduce classic BPF filter cache Xu Kuohai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Xu Kuohai @ 2026-11-20  6:48 UTC (permalink / raw)
  To: bpf, linux-kernel, io-uring, netdev
  Cc: Kees Cook, Andy Lutomirski, Will Drewry, Alexei Starovoitov,
	Daniel Borkmann, Stanislav Fomichev, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jens Axboe

Sandboxes like Firecracker use seccomp filters to restrict allowed
syscalls. Hundreds to thousands of Firecracker VM instances can run
from a single template. Each instance loads identical seccomp filters.
The kernel repeatedly translates and JIT-compiles these same cBPF
programs, wasting CPU cycles and slowing down bulk startup of
identically sandboxed workloads. cBPF lacks dynamic instruction patching
features like tail calls or tracing. Its JITed instructions remain
immutable at runtime. This makes it possible to share the same cBPF
filter between different processes.

This series introduces a classic BPF filter cache. It is implemented as
a hash table that maps user-space filter instructions to the prepared
bpf prog.

The cache lookup occurs before filter preparation:
- cache hit: Returns the shared bpf prog directly.
- cache miss: Reserves an entry. Concurrent tasks loading the same filter
  wait on a wait queue until preparation completes.

The cache is instantiated per subsystem. Currently, seccomp is the only
user.

This series ends with a benchmark test. Every producer spawns one worker
thread at a time, the worker installs a batch of filters and exits, the
benchmark reports the number of filters installed per second. The table
below benchmarks the batch size and the instruction length in one round,
running the command below with different option values. The base column
runs the same command on a kernel without this series. All data was
measured on a local test setup with 32 producers.

$ ./bench --producers 32 --duration 10 seccomp-install \
        --sync-mode yes --filter-len 128 --batch 4 --same-filter yes

batch  filter-len   base      cache hit            cache miss
                              (--same-filter yes)  (--same-filter no)
1      32           0.044M/s  0.064M/s(1.5x)       0.040M/s(0.9x)
1      128          0.043M/s  0.062M/s(1.4x)       0.039M/s(0.9x)
1      512          0.037M/s  0.052M/s(1.4x)       0.034M/s(0.9x)
1      2048         0.023M/s  0.037M/s(1.6x)       0.023M/s(1.0x)
4      32           0.065M/s  0.187M/s(2.9x)       0.059M/s(0.9x)
4      128          0.062M/s  0.190M/s(3.1x)       0.055M/s(0.9x)
4      512          0.052M/s  0.167M/s(3.2x)       0.046M/s(0.9x)
4      2048         0.030M/s  0.119M/s(4.0x)       0.028M/s(0.9x)

On cache hits, the cache delivers 1.4x to 4.0x throughput. Hits bypass
the translation and JIT compilation pipeline entirely, so gains grow with
filter length. The worker thread setup hides the win at one install per
worker, a larger batch amortizes it. On cache misses, a miss costs a hash
lookup and an entry allocation, the throughput degradation stays within
about 10%.

Xu Kuohai (3):
  bpf: Introduce classic BPF filter cache
  seccomp: Use the classic BPF filter cache
  selftests/bpf: Add benchmark for seccomp filter install

 include/linux/filter.h                        |  25 +-
 io_uring/bpf_filter.c                         |   3 +-
 kernel/seccomp.c                              |  12 +-
 net/core/filter.c                             | 318 +++++++++++++++++-
 net/packet/af_packet.c                        |   2 +-
 tools/testing/selftests/bpf/bench.c           |   4 +
 .../bpf/benchs/bench_seccomp_install.c        | 249 ++++++++++++++
 7 files changed, 604 insertions(+), 9 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/benchs/bench_seccomp_install.c

-- 
2.43.0


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

end of thread, other threads:[~2026-11-20  7:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  6:48 [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp Xu Kuohai
2026-11-20  6:48 ` [RFC PATCH 1/3] bpf: Introduce classic BPF filter cache Xu Kuohai
2026-11-20  7:31   ` sashiko-bot
2026-11-20  6:48 ` [RFC PATCH 2/3] seccomp: Use the " Xu Kuohai
2026-11-20  6:48 ` [RFC PATCH 3/3] selftests/bpf: Add benchmark for seccomp filter install Xu Kuohai
2026-11-20  7:24   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.