[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160719214608.GD64618@ast-mbp.thefacebook.com>
Date: Tue, 19 Jul 2016 14:46:09 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Brenden Blanco <bblanco@...mgrid.com>
Cc: davem@...emloft.net, netdev@...r.kernel.org,
Jamal Hadi Salim <jhs@...atatu.com>,
Saeed Mahameed <saeedm@....mellanox.co.il>,
Martin KaFai Lau <kafai@...com>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Ari Saha <as754m@....com>, Or Gerlitz <gerlitz.or@...il.com>,
john.fastabend@...il.com, hannes@...essinduktion.org,
Thomas Graf <tgraf@...g.ch>, Tom Herbert <tom@...bertland.com>,
Daniel Borkmann <daniel@...earbox.net>,
Tariq Toukan <ttoukan.linux@...il.com>
Subject: Re: [PATCH v10 01/12] bpf: add bpf_prog_add api for bulk prog refcnt
On Tue, Jul 19, 2016 at 12:16:46PM -0700, Brenden Blanco wrote:
> 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: Brenden Blanco <bblanco@...mgrid.com>
> ---
> include/linux/bpf.h | 1 +
> kernel/bpf/syscall.c | 12 +++++++++---
> 2 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index c13e92b..75a5ae6 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -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_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);
> void bpf_prog_put(struct bpf_prog *prog);
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 96d938a..228f962 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -670,14 +670,20 @@ static struct bpf_prog *____bpf_prog_get(struct fd f)
> 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) {
> - atomic_dec(&prog->aux->refcnt);
> + if (atomic_add_return(i, &prog->aux->refcnt) > BPF_MAX_REFCNT) {
> + atomic_sub(i, &prog->aux->refcnt);
> return ERR_PTR(-EBUSY);
> }
> return prog;
> }
> +EXPORT_SYMBOL_GPL(bpf_prog_add);
> +
> +struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog)
> +{
> + return bpf_prog_add(prog, 1);
> +}
that extension turned out to be smaller than I thought :)
Acked-by: Alexei Starovoitov <ast@...nel.org>
Powered by blists - more mailing lists