[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190528194342.GC20578@tower.DHCP.thefacebook.com>
Date: Tue, 28 May 2019 19:43:46 +0000
From: Roman Gushchin <guro@...com>
To: Stanislav Fomichev <sdf@...gle.com>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"davem@...emloft.net" <davem@...emloft.net>,
"ast@...nel.org" <ast@...nel.org>,
"daniel@...earbox.net" <daniel@...earbox.net>
Subject: Re: [PATCH bpf-next v3 3/4] bpf: cgroup: properly use bpf_prog_array
api
On Tue, May 28, 2019 at 11:29:45AM -0700, Stanislav Fomichev wrote:
> Now that we don't have __rcu markers on the bpf_prog_array helpers,
> let's use proper rcu_dereference_protected to obtain array pointer
> under mutex.
>
> We also don't need __rcu annotations on cgroup_bpf.inactive since
> it's not read/updated concurrently.
>
> v3:
> * amend cgroup_rcu_dereference to include percpu_ref_is_dying;
> cgroup_bpf is now reference counted and we don't hold cgroup_mutex
> anymore in cgroup_bpf_release
>
> v2:
> * replace xchg with rcu_swap_protected
>
> Cc: Roman Gushchin <guro@...com>
> Signed-off-by: Stanislav Fomichev <sdf@...gle.com>
> ---
> include/linux/bpf-cgroup.h | 2 +-
> kernel/bpf/cgroup.c | 32 +++++++++++++++++++++-----------
> 2 files changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
> index 9f100fc422c3..b631ee75762d 100644
> --- a/include/linux/bpf-cgroup.h
> +++ b/include/linux/bpf-cgroup.h
> @@ -72,7 +72,7 @@ struct cgroup_bpf {
> u32 flags[MAX_BPF_ATTACH_TYPE];
>
> /* temp storage for effective prog array used by prog_attach/detach */
> - struct bpf_prog_array __rcu *inactive;
> + struct bpf_prog_array *inactive;
>
> /* reference counter used to detach bpf programs after cgroup removal */
> struct percpu_ref refcnt;
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index d995edbe816d..118b70175dd9 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -22,6 +22,13 @@
> DEFINE_STATIC_KEY_FALSE(cgroup_bpf_enabled_key);
> EXPORT_SYMBOL(cgroup_bpf_enabled_key);
>
> +#define cgroup_rcu_dereference(cgrp, p) \
> + rcu_dereference_protected(p, lockdep_is_held(&cgroup_mutex) || \
> + percpu_ref_is_dying(&cgrp->bpf.refcnt))
Some comments why percpu_ref_is_dying(&cgrp->bpf.refcnt) is enough here will
be appreciated.
Thanks!
Powered by blists - more mailing lists