Commit 59d3656d authored by Brenden Blanco's avatar Brenden Blanco Committed by David S. Miller

bpf: add bpf_prog_add api for bulk prog refcnt

A subsystem may need to store many copies of a bpf program, each
deserving its own reference. Rather than requiring the caller to loop
one by one (with possible mid-loop failure), add a bulk bpf_prog_add
api.
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ddbcb794
...@@ -224,6 +224,7 @@ void bpf_register_map_type(struct bpf_map_type_list *tl); ...@@ -224,6 +224,7 @@ void bpf_register_map_type(struct bpf_map_type_list *tl);
struct bpf_prog *bpf_prog_get(u32 ufd); struct bpf_prog *bpf_prog_get(u32 ufd);
struct bpf_prog *bpf_prog_get_type(u32 ufd, enum bpf_prog_type type); struct bpf_prog *bpf_prog_get_type(u32 ufd, enum bpf_prog_type type);
struct bpf_prog *bpf_prog_add(struct bpf_prog *prog, int i);
struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog); struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog);
void bpf_prog_put(struct bpf_prog *prog); void bpf_prog_put(struct bpf_prog *prog);
......
...@@ -670,14 +670,20 @@ static struct bpf_prog *____bpf_prog_get(struct fd f) ...@@ -670,14 +670,20 @@ static struct bpf_prog *____bpf_prog_get(struct fd f)
return f.file->private_data; return f.file->private_data;
} }
struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog) struct bpf_prog *bpf_prog_add(struct bpf_prog *prog, int i)
{ {
if (atomic_inc_return(&prog->aux->refcnt) > BPF_MAX_REFCNT) { if (atomic_add_return(i, &prog->aux->refcnt) > BPF_MAX_REFCNT) {
atomic_dec(&prog->aux->refcnt); atomic_sub(i, &prog->aux->refcnt);
return ERR_PTR(-EBUSY); return ERR_PTR(-EBUSY);
} }
return prog; return prog;
} }
EXPORT_SYMBOL_GPL(bpf_prog_add);
struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog)
{
return bpf_prog_add(prog, 1);
}
static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *type) static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *type)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment