Netdev List
 help / color / mirror / Atom feed
From: Xu Kuohai <xukuohai@huaweicloud.com>
To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	io-uring@vger.kernel.org, netdev@vger.kernel.org
Cc: Kees Cook <kees@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Stanislav Fomichev <sdf@fomichev.me>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Jens Axboe <axboe@kernel.dk>
Subject: [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp
Date: Fri, 20 Nov 2026 06:48:49 +0000	[thread overview]
Message-ID: <cover.1795139109.git.xukuohai@huaweicloud.com> (raw)

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


             reply	other threads:[~2026-11-20  7:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:48 Xu Kuohai [this message]
2026-11-20  6:48 ` [RFC PATCH 1/3] bpf: Introduce classic BPF filter cache Xu Kuohai
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1795139109.git.xukuohai@huaweicloud.com \
    --to=xukuohai@huaweicloud.com \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=io-uring@vger.kernel.org \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=wad@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox