Skip to content

Commit e7f67c2

Browse files
committed
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>
1 parent e7c3067 commit e7f67c2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

io_uring/bpf_filter.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "openclose.h"
1616

1717
struct io_bpf_filter {
18+
refcount_t refs;
1819
struct bpf_prog *prog;
1920
struct io_bpf_filter *next;
2021
};
@@ -125,6 +126,11 @@ static void io_free_bpf_filters(struct rcu_head *head)
125126
*/
126127
if (f == &dummy_filter)
127128
break;
129+
130+
/* Someone still holds a ref, stop iterating. */
131+
if (!refcount_dec_and_test(&f->refs))
132+
break;
133+
128134
bpf_prog_destroy(f->prog);
129135
kfree(f);
130136
f = next;
@@ -298,6 +304,7 @@ int io_register_bpf_filter(struct io_restriction *res,
298304
ret = -ENOMEM;
299305
goto err;
300306
}
307+
refcount_set(&filter->refs, 1);
301308
filter->prog = prog;
302309
res->bpf_filters = filters;
303310

0 commit comments

Comments
 (0)