Skip to content

Commit 588e5d8

Browse files
hefengqinghtejun
authored andcommitted
cgroup: bpf: Move wrapper for __cgroup_bpf_*() to kernel/bpf/cgroup.c
In commit 324bda9("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 <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 81c49d3 commit 588e5d8

File tree

3 files changed

+45
-67
lines changed

3 files changed

+45
-67
lines changed

include/linux/bpf-cgroup.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,26 +157,6 @@ struct cgroup_bpf {
157157
int cgroup_bpf_inherit(struct cgroup *cgrp);
158158
void cgroup_bpf_offline(struct cgroup *cgrp);
159159

160-
int __cgroup_bpf_attach(struct cgroup *cgrp,
161-
struct bpf_prog *prog, struct bpf_prog *replace_prog,
162-
struct bpf_cgroup_link *link,
163-
enum bpf_attach_type type, u32 flags);
164-
int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
165-
struct bpf_cgroup_link *link,
166-
enum bpf_attach_type type);
167-
int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
168-
union bpf_attr __user *uattr);
169-
170-
/* Wrapper for __cgroup_bpf_*() protected by cgroup_mutex */
171-
int cgroup_bpf_attach(struct cgroup *cgrp,
172-
struct bpf_prog *prog, struct bpf_prog *replace_prog,
173-
struct bpf_cgroup_link *link, enum bpf_attach_type type,
174-
u32 flags);
175-
int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
176-
enum bpf_attach_type type);
177-
int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
178-
union bpf_attr __user *uattr);
179-
180160
int __cgroup_bpf_run_filter_skb(struct sock *sk,
181161
struct sk_buff *skb,
182162
enum cgroup_bpf_attach_type atype);

kernel/bpf/cgroup.c

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ static struct bpf_prog_list *find_attach_entry(struct list_head *progs,
430430
* Exactly one of @prog or @link can be non-null.
431431
* Must be called with cgroup_mutex held.
432432
*/
433-
int __cgroup_bpf_attach(struct cgroup *cgrp,
434-
struct bpf_prog *prog, struct bpf_prog *replace_prog,
435-
struct bpf_cgroup_link *link,
436-
enum bpf_attach_type type, u32 flags)
433+
static int __cgroup_bpf_attach(struct cgroup *cgrp,
434+
struct bpf_prog *prog, struct bpf_prog *replace_prog,
435+
struct bpf_cgroup_link *link,
436+
enum bpf_attach_type type, u32 flags)
437437
{
438438
u32 saved_flags = (flags & (BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI));
439439
struct bpf_prog *old_prog = NULL;
@@ -523,6 +523,20 @@ int __cgroup_bpf_attach(struct cgroup *cgrp,
523523
return err;
524524
}
525525

526+
static int cgroup_bpf_attach(struct cgroup *cgrp,
527+
struct bpf_prog *prog, struct bpf_prog *replace_prog,
528+
struct bpf_cgroup_link *link,
529+
enum bpf_attach_type type,
530+
u32 flags)
531+
{
532+
int ret;
533+
534+
mutex_lock(&cgroup_mutex);
535+
ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags);
536+
mutex_unlock(&cgroup_mutex);
537+
return ret;
538+
}
539+
526540
/* Swap updated BPF program for given link in effective program arrays across
527541
* all descendant cgroups. This function is guaranteed to succeed.
528542
*/
@@ -672,14 +686,14 @@ static struct bpf_prog_list *find_detach_entry(struct list_head *progs,
672686
* propagate the change to descendants
673687
* @cgrp: The cgroup which descendants to traverse
674688
* @prog: A program to detach or NULL
675-
* @prog: A link to detach or NULL
689+
* @link: A link to detach or NULL
676690
* @type: Type of detach operation
677691
*
678692
* At most one of @prog or @link can be non-NULL.
679693
* Must be called with cgroup_mutex held.
680694
*/
681-
int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
682-
struct bpf_cgroup_link *link, enum bpf_attach_type type)
695+
static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
696+
struct bpf_cgroup_link *link, enum bpf_attach_type type)
683697
{
684698
enum cgroup_bpf_attach_type atype;
685699
struct bpf_prog *old_prog;
@@ -730,9 +744,20 @@ int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
730744
return err;
731745
}
732746

747+
static int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
748+
enum bpf_attach_type type)
749+
{
750+
int ret;
751+
752+
mutex_lock(&cgroup_mutex);
753+
ret = __cgroup_bpf_detach(cgrp, prog, NULL, type);
754+
mutex_unlock(&cgroup_mutex);
755+
return ret;
756+
}
757+
733758
/* Must be called with cgroup_mutex held to avoid races. */
734-
int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
735-
union bpf_attr __user *uattr)
759+
static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
760+
union bpf_attr __user *uattr)
736761
{
737762
__u32 __user *prog_ids = u64_to_user_ptr(attr->query.prog_ids);
738763
enum bpf_attach_type type = attr->query.attach_type;
@@ -789,6 +814,17 @@ int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
789814
return ret;
790815
}
791816

817+
static int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
818+
union bpf_attr __user *uattr)
819+
{
820+
int ret;
821+
822+
mutex_lock(&cgroup_mutex);
823+
ret = __cgroup_bpf_query(cgrp, attr, uattr);
824+
mutex_unlock(&cgroup_mutex);
825+
return ret;
826+
}
827+
792828
int cgroup_bpf_prog_attach(const union bpf_attr *attr,
793829
enum bpf_prog_type ptype, struct bpf_prog *prog)
794830
{

kernel/cgroup/cgroup.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6676,44 +6676,6 @@ void cgroup_sk_free(struct sock_cgroup_data *skcd)
66766676

66776677
#endif /* CONFIG_SOCK_CGROUP_DATA */
66786678

6679-
#ifdef CONFIG_CGROUP_BPF
6680-
int cgroup_bpf_attach(struct cgroup *cgrp,
6681-
struct bpf_prog *prog, struct bpf_prog *replace_prog,
6682-
struct bpf_cgroup_link *link,
6683-
enum bpf_attach_type type,
6684-
u32 flags)
6685-
{
6686-
int ret;
6687-
6688-
mutex_lock(&cgroup_mutex);
6689-
ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags);
6690-
mutex_unlock(&cgroup_mutex);
6691-
return ret;
6692-
}
6693-
6694-
int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
6695-
enum bpf_attach_type type)
6696-
{
6697-
int ret;
6698-
6699-
mutex_lock(&cgroup_mutex);
6700-
ret = __cgroup_bpf_detach(cgrp, prog, NULL, type);
6701-
mutex_unlock(&cgroup_mutex);
6702-
return ret;
6703-
}
6704-
6705-
int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
6706-
union bpf_attr __user *uattr)
6707-
{
6708-
int ret;
6709-
6710-
mutex_lock(&cgroup_mutex);
6711-
ret = __cgroup_bpf_query(cgrp, attr, uattr);
6712-
mutex_unlock(&cgroup_mutex);
6713-
return ret;
6714-
}
6715-
#endif /* CONFIG_CGROUP_BPF */
6716-
67176679
#ifdef CONFIG_SYSFS
67186680
static ssize_t show_delegatable_files(struct cftype *files, char *buf,
67196681
ssize_t size, const char *prefix)

0 commit comments

Comments
 (0)