summaryrefslogtreecommitdiff
path: root/io_uring
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2026-01-16 14:37:28 -0700
committerJens Axboe <axboe@kernel.dk>2026-01-27 11:10:46 -0700
commite7f67c2be7877a3d44aa79b8d22eae8cb6e2c6d6 (patch)
tree71c9823078457158bd03549018f755542bf99faf /io_uring
parente7c30675a7fb79d94400987865a3bd620458ca1a (diff)
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. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/bpf_filter.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/io_uring/bpf_filter.c b/io_uring/bpf_filter.c
index 1409d625b686..b94944ab8442 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;
};
@@ -125,6 +126,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;
@@ -298,6 +304,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;