Article View: linux.kernel.netdev
Article #19666[RFC PATCH 2/3] seccomp: Use the classic BPF filter cache
From: Xu Kuohai
Date: Fri, 20 Nov 2026 06:48
Date: Fri, 20 Nov 2026 06:48
51 lines
10607 bytes
10607 bytes
From: Xu Kuohai <xukuohai@huawei.com>
Define a classic BPF filter cache in seccomp. This allows identical
seccomp filters to share a single prepared program instead of each
paying the cost of the check, rewrite, migration, and JIT compilation
pipeline.
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
kernel/seccomp.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 01e26bfc6ea1..b1c40ffbc6f2 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -465,6 +465,9 @@ static inline void seccomp_assign_mode(struct task_struct *task,
}
#ifdef CONFIG_SECCOMP_FILTER
+
+static DEFINE_CBPF_CACHE(seccomp_cbpf_cache);
+
/* Returns 1 if the parent is an ancestor of the child. */
static int is_ancestor(struct seccomp_filter *parent,
struct seccomp_filter *child)
@@ -526,7 +529,11 @@ static inline pid_t seccomp_can_sync_threads(void)
static inline void seccomp_filter_free(struct seccomp_filter *filter)
{
if (filter) {
- bpf_prog_destroy(filter->prog);
+ if (filter->prog->orig_prog &&
+ filter->prog->orig_prog->cache_entry)
+ cbpf_cache_put_prog(filter->prog);
+ else
+ bpf_prog_destroy(filter->prog);
kfree(filter);
}
}
@@ -702,7 +709,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
mutex_init(&sfilter->notify_lock);
ret = bpf_prog_create_from_user(&sfilter->prog, fprog,
seccomp_check_filter, save_orig,
- NULL);
+ &seccomp_cbpf_cache);
if (ret < 0) {
kfree(sfilter);
return ERR_PTR(ret);
--
2.43.0
Technical Details
Message-ID:
<03575b8ff18b1ec40809ada33257bcf5ac1ab29c.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-367735-linux-kernel-netdev=dewy.ruReferences:
<cover.1795139109.git.xukuohai@huaweicloud.com>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-367735-linux-kernel-netdev=dewy.ru From: xukuohai@huaweicloud.com (Xu Kuohai) Newsgroups: linux.kernel.netdev Subject: [RFC PATCH 2/3] seccomp: Use the classic BPF filter cache Date: Fri, 20 Nov 2026 06:48:51 +0000 Organization: Usenet Network Message-ID: <03575b8ff18b1ec40809ada33257bcf5ac1ab29c.1795139109.git.xukuohai@huaweicloud.com> References: <cover.1795139109.git.xukuohai@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3091994"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:47CofAVPclp4ukbOUPuf2b/17gQ= sha256:OipmQ62unggFiB/IsH3/0flBZQ0hTKkeQ7yKwkBuxfo= sha1:KbijeESZ1TCJ9r2D9B2mgIGUdRc= sha256:FXpssMUC53KC+3/nbqHqPde9leVPaB7F8SBdnAx2LVg= 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 E69141158E6; Fri, 20 Nov 2026 10:16:17 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[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 zr0IjE5v026u; Fri, 20 Nov 2026 10:16:14 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367735-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 81FD81158E4; Fri, 20 Nov 2026 10:16:11 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 1E856681710; Fri, 20 Nov 2026 07:16:11 +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=1795158962; b=DccaIPDgUA1uoRohTpSlDvjUgxWWDvkAmWGNBkfI+sFjWdTPike5d8GVsQ/sMUmAEXdu FVwemruA6mqZh73vHsleuWzpJdziGYmn70B0QzD7u4Oik4UbLVwoD442bGDaR78rwjiWw w0WFmqMcf7sC9j8AaRakH59ZfxwpO/P7I4oGT/A7JTVw6xQTr4An6cHQ6kW1uaYc7mWMf YvNvvcc1S3OHOp1CDSAljuM77V9PcEa6LnQaPpYE5yd5DAwkTNW1Ar4ODfZtVWvENeZks u7HRhSVYYbhblglwA2WkOQXrqODeKynUiJBxYiVidGF3TjfqE+pyGBviFE7Yibw7nMg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795158962; h=X-Original-To:Received:DMARC-Filter:Received:Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: 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=qFKUjQZcSUKgt4QCK8R+XPbzFwqo/yxdcFdNLs4a7Cc=; b=xZ0Aossg5QhPiQ7KZ4X6gZ+poLlMxTSWE81GDtdT2SgP/xMhVWQebe3/wCNe29cbhgiI QEJ0VxWVOuy8P0UbUnb43aubU3oEf1REcCgSmypFBg+RrATicykDkXqBaDj0fxElbB6lH a7s83apNuyQaBG48IwC2DbScAkAiUQQZEFlDSN4126k/bLQiJ/mAvFU7Y90WWVufQgX9p yKt1lAEwyR1RlzdZiJhf0eAYQUdK5Jx7Rue3mIs3TR0ocdEcVjaWq+xjLI92cLzzTp6Rr 1WmR8XRXZfvnPUdE1xnY41iJUXlpM5FLFoJWHCq6/tyiYNeep/fwztNb1i0uzmCrCWA== 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 C0DFD60A2610; Fri, 20 Nov 2026 07:16:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=124.71.93.99 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795158957; b=jETKUrgVTR9s3tq8yp4oTUYnfOZUpOapqIQb1Akrnyb0DEkQR+LtELhFNjHDMcR2UbVZ 607hGmEJzGXlWqJHgUwNPMxYPvKAzLunBXGyfj0JUk90zYF0RdcjDLF4xp9m0wXz99c6k DJ4nON7fWBtkP2nsqaK+ntTpbOHWMr04doqKttgSE1bgaj2FN455hXt2Gh9h673HwkwN0 jApu95wGvtMDFW0dUm2CaqlgMcBIcj+PFZtkoIorap/rMGIEjaUT86pIGS7hrUEovYU7Q atrP7lSdrUFg+dxYdo+7NWJ5gc84cUY6Zk/Htl/1f8yKnbkT5DAtre44Q+zDf84ECYg== 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:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=qFKUjQZcSUKgt4QCK8R+XPbzFwqo/yxdcFdNLs4a7Cc=; b=koE9e97idFU+Vr09aMFuUDRfI0CC3DgYl5Jmm9s5Gl3r/y1BpZDs4JiS18yyaz6lsZPJ JNxz5N9CLchXKecuiB8t9tUlA6WyB5Owasl+H9eA1oTS7y+vOHHy8nqBN6r2dx9mTFKqu fzmM+7bu8gBWHyHyqU2k3eWWJbq4mBjsE1kshUn1tqjax6FMQ/c+2u1r6FCK05b5bZZzy VbQcocBJ1emWFz8WCKdJVzc31GrS6EUJSku9nfrC6HLFCZMsqoO8m+Q1hx2Lqb8y8Q/9W GCyQpoG0CYIxT5LA8vKrZrFBvX/d9v5DG/LJqdKzznZYT9VHTkEtCpQRgzMFLTpGcLw== 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.99 X-Received: from dggmsgout11.his.huawei.com (dggmsgout11.his.huawei.com [124.71.93.99]) (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 AD2F9606A325; Fri, 20 Nov 2026 07:15:54 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD2F9606A325 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.198]) by dggmsgout11.his.huawei.com (SkyGuard) with ESMTP id 4jW66R5MMgz1c0nX; Fri, 20 Nov 2026 15:14:55 +0800 (CST) X-Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id CCCA840577; 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--.40246S4; 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-In-Reply-To: <cover.1795139109.git.xukuohai@huaweicloud.com> 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--.40246S4 X-Coremail-Antispam: 1UD129KBjvJXoW7uFy3CFy7ur47Cw15Ar1UJrb_yoW8WF18pa 45Gw1Yyw4xXFn7Gr95GFWUCFyrJFnYgr9rur1UK34fAry3Xr1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