🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Xu Kuohai Fri, 20 Nov 2026 06:48
[RFC PATCH 2/3] seccomp: Use the classic BPF filter cache
#19666
Author: Xu Kuohai
Date: Fri, 20 Nov 2026 06:48
51 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads