cgroup: bpf: Move wrapper for __cgroup_bpf_*() to kernel/bpf/cgroup.c
In commit 324bda9e6c5a("bpf: multi program support for cgroup+bpf") cgroup_bpf_*() called from kernel/bpf/syscall.c, but now they are only used in kernel/bpf/cgroup.c, so move these function to kernel/bpf/cgroup.c, like cgroup_bpf_replace(). Signed-off-by: He Fengqing <hefengqing@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
parent
81c49d39ae
commit
588e5d8766
@ -157,26 +157,6 @@ struct cgroup_bpf {
|
|||||||
int cgroup_bpf_inherit(struct cgroup *cgrp);
|
int cgroup_bpf_inherit(struct cgroup *cgrp);
|
||||||
void cgroup_bpf_offline(struct cgroup *cgrp);
|
void cgroup_bpf_offline(struct cgroup *cgrp);
|
||||||
|
|
||||||
int __cgroup_bpf_attach(struct cgroup *cgrp,
|
|
||||||
struct bpf_prog *prog, struct bpf_prog *replace_prog,
|
|
||||||
struct bpf_cgroup_link *link,
|
|
||||||
enum bpf_attach_type type, u32 flags);
|
|
||||||
int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
|
|
||||||
struct bpf_cgroup_link *link,
|
|
||||||
enum bpf_attach_type type);
|
|
||||||
int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
|
||||||
union bpf_attr __user *uattr);
|
|
||||||
|
|
||||||
/* Wrapper for __cgroup_bpf_*() protected by cgroup_mutex */
|
|
||||||
int cgroup_bpf_attach(struct cgroup *cgrp,
|
|
||||||
struct bpf_prog *prog, struct bpf_prog *replace_prog,
|
|
||||||
struct bpf_cgroup_link *link, enum bpf_attach_type type,
|
|
||||||
u32 flags);
|
|
||||||
int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
|
|
||||||
enum bpf_attach_type type);
|
|
||||||
int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
|
||||||
union bpf_attr __user *uattr);
|
|
||||||
|
|
||||||
int __cgroup_bpf_run_filter_skb(struct sock *sk,
|
int __cgroup_bpf_run_filter_skb(struct sock *sk,
|
||||||
struct sk_buff *skb,
|
struct sk_buff *skb,
|
||||||
enum cgroup_bpf_attach_type atype);
|
enum cgroup_bpf_attach_type atype);
|
||||||
|
@ -430,7 +430,7 @@ static struct bpf_prog_list *find_attach_entry(struct list_head *progs,
|
|||||||
* Exactly one of @prog or @link can be non-null.
|
* Exactly one of @prog or @link can be non-null.
|
||||||
* Must be called with cgroup_mutex held.
|
* Must be called with cgroup_mutex held.
|
||||||
*/
|
*/
|
||||||
int __cgroup_bpf_attach(struct cgroup *cgrp,
|
static int __cgroup_bpf_attach(struct cgroup *cgrp,
|
||||||
struct bpf_prog *prog, struct bpf_prog *replace_prog,
|
struct bpf_prog *prog, struct bpf_prog *replace_prog,
|
||||||
struct bpf_cgroup_link *link,
|
struct bpf_cgroup_link *link,
|
||||||
enum bpf_attach_type type, u32 flags)
|
enum bpf_attach_type type, u32 flags)
|
||||||
@ -523,6 +523,20 @@ cleanup:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cgroup_bpf_attach(struct cgroup *cgrp,
|
||||||
|
struct bpf_prog *prog, struct bpf_prog *replace_prog,
|
||||||
|
struct bpf_cgroup_link *link,
|
||||||
|
enum bpf_attach_type type,
|
||||||
|
u32 flags)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
mutex_lock(&cgroup_mutex);
|
||||||
|
ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags);
|
||||||
|
mutex_unlock(&cgroup_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Swap updated BPF program for given link in effective program arrays across
|
/* Swap updated BPF program for given link in effective program arrays across
|
||||||
* all descendant cgroups. This function is guaranteed to succeed.
|
* all descendant cgroups. This function is guaranteed to succeed.
|
||||||
*/
|
*/
|
||||||
@ -672,13 +686,13 @@ static struct bpf_prog_list *find_detach_entry(struct list_head *progs,
|
|||||||
* propagate the change to descendants
|
* propagate the change to descendants
|
||||||
* @cgrp: The cgroup which descendants to traverse
|
* @cgrp: The cgroup which descendants to traverse
|
||||||
* @prog: A program to detach or NULL
|
* @prog: A program to detach or NULL
|
||||||
* @prog: A link to detach or NULL
|
* @link: A link to detach or NULL
|
||||||
* @type: Type of detach operation
|
* @type: Type of detach operation
|
||||||
*
|
*
|
||||||
* At most one of @prog or @link can be non-NULL.
|
* At most one of @prog or @link can be non-NULL.
|
||||||
* Must be called with cgroup_mutex held.
|
* Must be called with cgroup_mutex held.
|
||||||
*/
|
*/
|
||||||
int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
|
static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
|
||||||
struct bpf_cgroup_link *link, enum bpf_attach_type type)
|
struct bpf_cgroup_link *link, enum bpf_attach_type type)
|
||||||
{
|
{
|
||||||
enum cgroup_bpf_attach_type atype;
|
enum cgroup_bpf_attach_type atype;
|
||||||
@ -730,8 +744,19 @@ cleanup:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
|
||||||
|
enum bpf_attach_type type)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
mutex_lock(&cgroup_mutex);
|
||||||
|
ret = __cgroup_bpf_detach(cgrp, prog, NULL, type);
|
||||||
|
mutex_unlock(&cgroup_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Must be called with cgroup_mutex held to avoid races. */
|
/* Must be called with cgroup_mutex held to avoid races. */
|
||||||
int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
||||||
union bpf_attr __user *uattr)
|
union bpf_attr __user *uattr)
|
||||||
{
|
{
|
||||||
__u32 __user *prog_ids = u64_to_user_ptr(attr->query.prog_ids);
|
__u32 __user *prog_ids = u64_to_user_ptr(attr->query.prog_ids);
|
||||||
@ -789,6 +814,17 @@ int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
||||||
|
union bpf_attr __user *uattr)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
mutex_lock(&cgroup_mutex);
|
||||||
|
ret = __cgroup_bpf_query(cgrp, attr, uattr);
|
||||||
|
mutex_unlock(&cgroup_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int cgroup_bpf_prog_attach(const union bpf_attr *attr,
|
int cgroup_bpf_prog_attach(const union bpf_attr *attr,
|
||||||
enum bpf_prog_type ptype, struct bpf_prog *prog)
|
enum bpf_prog_type ptype, struct bpf_prog *prog)
|
||||||
{
|
{
|
||||||
|
@ -6676,44 +6676,6 @@ void cgroup_sk_free(struct sock_cgroup_data *skcd)
|
|||||||
|
|
||||||
#endif /* CONFIG_SOCK_CGROUP_DATA */
|
#endif /* CONFIG_SOCK_CGROUP_DATA */
|
||||||
|
|
||||||
#ifdef CONFIG_CGROUP_BPF
|
|
||||||
int cgroup_bpf_attach(struct cgroup *cgrp,
|
|
||||||
struct bpf_prog *prog, struct bpf_prog *replace_prog,
|
|
||||||
struct bpf_cgroup_link *link,
|
|
||||||
enum bpf_attach_type type,
|
|
||||||
u32 flags)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
mutex_lock(&cgroup_mutex);
|
|
||||||
ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags);
|
|
||||||
mutex_unlock(&cgroup_mutex);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
|
|
||||||
enum bpf_attach_type type)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
mutex_lock(&cgroup_mutex);
|
|
||||||
ret = __cgroup_bpf_detach(cgrp, prog, NULL, type);
|
|
||||||
mutex_unlock(&cgroup_mutex);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
|
|
||||||
union bpf_attr __user *uattr)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
mutex_lock(&cgroup_mutex);
|
|
||||||
ret = __cgroup_bpf_query(cgrp, attr, uattr);
|
|
||||||
mutex_unlock(&cgroup_mutex);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_CGROUP_BPF */
|
|
||||||
|
|
||||||
#ifdef CONFIG_SYSFS
|
#ifdef CONFIG_SYSFS
|
||||||
static ssize_t show_delegatable_files(struct cftype *files, char *buf,
|
static ssize_t show_delegatable_files(struct cftype *files, char *buf,
|
||||||
ssize_t size, const char *prefix)
|
ssize_t size, const char *prefix)
|
||||||
|
Loading…
Reference in New Issue
Block a user