[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260119235456.1722452-6-axboe@kernel.dk>
Date: Mon, 19 Jan 2026 16:54:28 -0700
From: Jens Axboe <axboe@...nel.dk>
To: io-uring@...r.kernel.org
Cc: brauner@...nel.org,
jannh@...gle.com,
kees@...nel.org,
linux-kernel@...r.kernel.org,
Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 5/7] io_uring/bpf_filter: add ref counts to struct io_bpf_filter
In preparation for allowing inheritance of BPF filters and filter
tables, add a reference count to the filter. This allows multiple tables
to safely include the same filter.
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
io_uring/bpf_filter.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/io_uring/bpf_filter.c b/io_uring/bpf_filter.c
index 06fad04c4b54..fc9eaf29fcbf 100644
--- a/io_uring/bpf_filter.c
+++ b/io_uring/bpf_filter.c
@@ -15,6 +15,7 @@
#include "openclose.h"
struct io_bpf_filter {
+ refcount_t refs;
struct bpf_prog *prog;
struct io_bpf_filter *next;
};
@@ -129,6 +130,11 @@ static void io_free_bpf_filters(struct rcu_head *head)
*/
if (f == &dummy_filter)
break;
+
+ /* Someone still holds a ref, stop iterating. */
+ if (!refcount_dec_and_test(&f->refs))
+ break;
+
bpf_prog_destroy(f->prog);
kfree(f);
f = next;
@@ -304,6 +310,7 @@ int io_register_bpf_filter(struct io_restriction *res,
ret = -ENOMEM;
goto err;
}
+ refcount_set(&filter->refs, 1);
filter->prog = prog;
res->bpf_filters = filters;
--
2.51.0
Powered by blists - more mailing lists