🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19668

[RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp

#19668
From: Xu Kuohai
Date: Fri, 20 Nov 2026 06:48
69 lines
12203 bytes
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
Technical Details
Message-ID: <cover.1795139109.git.xukuohai@huaweicloud.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367737-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367737-linux-kernel-netdev=dewy.ru
From: xukuohai@huaweicloud.com (Xu Kuohai)
Newsgroups: linux.kernel.netdev
Subject: [RFC PATCH 0/3] Introduce a classic BPF filter cache for seccomp
Date: Fri, 20 Nov 2026 06:48:49 +0000
Organization: Usenet Network
Message-ID: <cover.1795139109.git.xukuohai@huaweicloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3092098"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:LHlQ7v9p5tUcuN7X2c+ZXWxIL5c= sha256:Zpq130PZnFIsXvrr+T2RQtZUKKhqycPWpwo9XTwnS4k=
	sha1:ud7hUjFoz/G86nF+lAurtTeBqIc= sha256:m2NEOm7F+Zkwj6Vpd2EJK4Gtc+N7iYNn/6zSKpl2KxQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3C6371158E6; Fri, 20 Nov 2026 10:16:22 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id eG8wlmL_dXGY;
	Fri, 20 Nov 2026 10:16:19 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367737-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=huaweicloud.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 3822C1158E4; Fri, 20 Nov 2026 10:16:15 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id CC90F3906E; Fri, 20 Nov 2026 07:16:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795158958;
	b=uPi7T8TR7V+domk2gsUn8ceYDHw2hkTftWui1KXRCzupX8M5bK8oxAiG6fwdy1+tKdUB
	 5aw9Cjgp4054hUggCS04Kh/6IDWVSzbSmoBuuQq+W/FR3gytHCHfHcux/SP7nGhEWV+gW
	 JJYDSh5tVXuoTBOba7pNc/snVQffDf9dwjuqwqUX79oOP7LZOXr6NCioGGMVSB7y2LJO6
	 CqQVkunEM0/R59iIpM61WtZxaEYjxJmhGpGBRB4Jjrt6CmrW1BQL5H9FlJad6CGK7AWf0
	 nOyWWfiYmGe/KZ2lFZCnw0cT3c3b2Ki6x4s6zH/m7OMkjg7MyG9Aym6fKVnTAHuAthg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795158958;
	h=X-Original-To:Received:DMARC-Filter:Received:Received:Received:From:
	 To:Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Transfer-Encoding:X-CM-TRANSID:
	 X-Coremail-Antispam:X-CM-SenderInfo;
	bh=MpSejgr2yOWVjUY3TJB4/bXQFGqhZdUZzWXieqZDX5c=;
	b=fRLzIRXzigIH5Nu1k27/xdfo6UgG5r9pzTH1HpuRWYhXIiSjoXsha+ifOzaXs9ERx8MC
	 8vBO+K3DqQ+V+/FUgbJnXv8aAm8BYck8ue1GsZqGwBVmHxb8f4nko+wxk8RbTN2KVGfMM
	 9xliNPbAIv/78bTn1Xfn5cpU0JT64WeiqTu6KCxy+ZjLVpJSK0uHo7Vzd8zs0U/H2h8iP
	 TYjy7lbhj29fySlmN7UxxdIc9y/GYFnNq0GOM6DADx69hi9uq0u5TMXtv57J1pDLWQ+IC
	 0eK4wP0oZjWv2cwOZYi4nQWIj5fe0ws4OYQ/QTiQ+xLNLNZFLnH/j2vXx0u/WS+5Rag==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=huaweicloud.com;
	spf=pass smtp.mailfrom=huaweicloud.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 09991606A333;
	Fri, 20 Nov 2026 07:15:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=124.71.93.112
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795158957;
	b=cdHCK0t9GtOCbFGOWTPosbZvUI9mbz77VlX5IYUh/A3rsfl1w1RWPiK/czY4o0gMskyd
	 nHaEQF4WjdMPFBpbXNNBQ+u+euS8tPs85lKlHCoG3rez2vkb0pg6hx0RetTiQABajt6Md
	 RU+fd4fpY3YK0y/IOnjI9qTuOKKatnlYcRCKWlL78kW55G6SodBAuMw0rcRHHZfjuznbU
	 FC4qD+yILCDWDIi8XVQjxPCZUwRcTdUnI1Ji/tBav3aipuK+pujD5+N4e6qr1X2V9VbKT
	 OLJYyuU2b6rpeOHJ6YJPOTTOq+lwrFB205JOx1mmj/dF+t2uho6Bf/QkGpOAoAD71YQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795158957;
	h=DMARC-Filter:Received:Received:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding:
	 X-CM-TRANSID:X-Coremail-Antispam:X-CM-SenderInfo;
	bh=MpSejgr2yOWVjUY3TJB4/bXQFGqhZdUZzWXieqZDX5c=;
	b=ThT3iiLE5/ujxN3kb65Hb/yNb5ADkjrJjmUwiEAUHtdrD3+hILO4/+4yEi26Au46mKn9
	 /HSriK2LV53SOKD2QYBaOfJUoNWz4fStb6uLebwrfJNDMtAQADLnJvYHe6pDktOiZWsHJ
	 shjiF3rEDUMrGHH/7/J/BcXhcGx2cNjbpUsFRi3i9L+OqOpf/3Pb2hjf6rTp2T71jScns
	 LjUf8l+pmIIaRYt7hOsR9pUzNI2wVG8XdPVy1exnokR5Eb9MSYZ/AR+rwV1HM7/UnKV1q
	 zEHE2KJ9r5SNr094zOCjWB09w9Fac9PkfUxoqFhZL4B7meKpA89f1Tk14pIUqgqGy+Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=huaweicloud.com;
	spf=pass smtp.mailfrom=huaweicloud.com;
	arc=none smtp.remote-ip=124.71.93.112
X-Received: from dggmsgout12.his.huawei.com (dggmsgout12.his.huawei.com [124.71.93.112])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D15EF606A33E;
	Fri, 20 Nov 2026 07:15:54 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D15EF606A33E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com
X-Received: from mail.maildlp.com (unknown [172.19.163.170])
	by dggmsgout12.his.huawei.com (SkyGuard) with ESMTP id 4jW66S6z45z1xr2;
	Fri, 20 Nov 2026 15:14:56 +0800 (CST)
X-Received: from mail02.huawei.com (unknown [10.116.40.128])
	by mail.maildlp.com (Postfix) with ESMTP id 948114056B;
	Fri, 20 Nov 2026 15:15:51 +0800 (CST)
X-Received: from localhost.huawei.com (unknown [10.67.174.243])
	by APP4 (Coremail) with UTF8SMTPA id gCh0CgA3dfSm8_9qDM9HFA--.40246S2;
	Fri, 20 Nov 2026 15:15:51 +0800 (CST)
X-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>
X-Mailer: git-send-email 2.43.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-CM-TRANSID: gCh0CgA3dfSm8_9qDM9HFA--.40246S2
X-Coremail-Antispam: 1UD129KBjvJXoWxGFW3CF4fAryUWry7Kw45Jrb_yoW5CFWUpF
	W5G343KFn5JF1xJ3sFv3yUKF1rWr4kXr15J3Z5Gr9rZr1UKryjgaySqryYkas8Ar1Uu343
	ZF1Dt3s29a1DZ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDU0xBIdaVrnRJUUUv2b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2
	6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4
	vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7Cj
	xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x
	0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG
	6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV
	Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxkF7I0E
	n4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I
	0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWU
	tVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcV
	CY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAF
	wI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa
	7IU17KsUUUUUU==
X-CM-SenderInfo: 50xn30hkdlqx5xdzvxpfor3voofrz/