Re: [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp
From: Kees Cook
Date: Sun Nov 22 2026 - 21:48:12 EST
On November 20, 2026 4:48:49 PM GMT+10:00, Xu Kuohai <xukuohai@xxxxxxxxxxxxxxx> wrote:
>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.
I would expect either memory usage or launch benchmarks, not just filter install timings.
Is there a workload where there is a problem? It is hinted at in the opening paragraph, but I'd want to better understand the actual constraints before jumping to a solution. E.g. it's already possible to share filters by way of process hierarchy, so perhaps the issue is lack of hierarchy?
I've seen proposals in the past about having handles to pre-constructed filters, which could be applied (i.e. much of the existing caching and lifetime management remained unchanged).
-Kees
--
Kees Cook