Lines Matching refs:cgrp
48 bpf_prog_run_array_cg(const struct cgroup_bpf *cgrp, in bpf_prog_run_array_cg() argument
63 array = rcu_dereference(cgrp->effective[atype]); in bpf_prog_run_array_cg()
88 struct cgroup *cgrp; in __cgroup_bpf_run_lsm_sock() local
97 cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_lsm_sock()
98 if (likely(cgrp)) in __cgroup_bpf_run_lsm_sock()
99 ret = bpf_prog_run_array_cg(&cgrp->bpf, in __cgroup_bpf_run_lsm_sock()
110 struct cgroup *cgrp; in __cgroup_bpf_run_lsm_socket() local
119 cgrp = sock_cgroup_ptr(&sock->sk->sk_cgrp_data); in __cgroup_bpf_run_lsm_socket()
120 if (likely(cgrp)) in __cgroup_bpf_run_lsm_socket()
121 ret = bpf_prog_run_array_cg(&cgrp->bpf, in __cgroup_bpf_run_lsm_socket()
131 struct cgroup *cgrp; in __cgroup_bpf_run_lsm_current() local
138 cgrp = task_dfl_cgroup(current); in __cgroup_bpf_run_lsm_current()
139 if (likely(cgrp)) in __cgroup_bpf_run_lsm_current()
140 ret = bpf_prog_run_array_cg(&cgrp->bpf, in __cgroup_bpf_run_lsm_current()
209 void cgroup_bpf_offline(struct cgroup *cgrp) in cgroup_bpf_offline() argument
211 cgroup_get(cgrp); in cgroup_bpf_offline()
212 percpu_ref_kill(&cgrp->bpf.refcnt); in cgroup_bpf_offline()
227 struct cgroup *cgrp) in bpf_cgroup_storages_alloc() argument
233 key.cgroup_inode_id = cgroup_id(cgrp); in bpf_cgroup_storages_alloc()
267 struct cgroup *cgrp, in bpf_cgroup_storages_link() argument
273 bpf_cgroup_storage_link(storages[stype], cgrp, attach_type); in bpf_cgroup_storages_link()
294 struct cgroup *p, *cgrp = container_of(work, struct cgroup, in cgroup_bpf_release() local
297 struct list_head *storages = &cgrp->bpf.storages; in cgroup_bpf_release()
304 for (atype = 0; atype < ARRAY_SIZE(cgrp->bpf.progs); atype++) { in cgroup_bpf_release()
305 struct hlist_head *progs = &cgrp->bpf.progs[atype]; in cgroup_bpf_release()
325 cgrp->bpf.effective[atype], in cgroup_bpf_release()
337 for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p)) in cgroup_bpf_release()
340 percpu_ref_exit(&cgrp->bpf.refcnt); in cgroup_bpf_release()
341 cgroup_put(cgrp); in cgroup_bpf_release()
351 struct cgroup *cgrp = container_of(ref, struct cgroup, bpf.refcnt); in cgroup_bpf_release_fn() local
353 INIT_WORK(&cgrp->bpf.release_work, cgroup_bpf_release); in cgroup_bpf_release_fn()
354 queue_work(cgroup_bpf_destroy_wq, &cgrp->bpf.release_work); in cgroup_bpf_release_fn()
389 static bool hierarchy_allows_attach(struct cgroup *cgrp, in hierarchy_allows_attach() argument
394 p = cgroup_parent(cgrp); in hierarchy_allows_attach()
418 static int compute_effective_progs(struct cgroup *cgrp, in compute_effective_progs() argument
425 struct cgroup *p = cgrp; in compute_effective_progs()
441 p = cgrp; in compute_effective_progs()
462 static void activate_effective_progs(struct cgroup *cgrp, in activate_effective_progs() argument
466 old_array = rcu_replace_pointer(cgrp->bpf.effective[atype], old_array, in activate_effective_progs()
478 int cgroup_bpf_inherit(struct cgroup *cgrp) in cgroup_bpf_inherit() argument
483 #define NR ARRAY_SIZE(cgrp->bpf.effective) in cgroup_bpf_inherit()
488 ret = percpu_ref_init(&cgrp->bpf.refcnt, cgroup_bpf_release_fn, 0, in cgroup_bpf_inherit()
493 for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p)) in cgroup_bpf_inherit()
497 INIT_HLIST_HEAD(&cgrp->bpf.progs[i]); in cgroup_bpf_inherit()
499 INIT_LIST_HEAD(&cgrp->bpf.storages); in cgroup_bpf_inherit()
502 if (compute_effective_progs(cgrp, i, &arrays[i])) in cgroup_bpf_inherit()
506 activate_effective_progs(cgrp, i, arrays[i]); in cgroup_bpf_inherit()
513 for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p)) in cgroup_bpf_inherit()
516 percpu_ref_exit(&cgrp->bpf.refcnt); in cgroup_bpf_inherit()
521 static int update_effective_progs(struct cgroup *cgrp, in update_effective_progs() argument
528 css_for_each_descendant_pre(css, &cgrp->self) { in update_effective_progs()
540 css_for_each_descendant_pre(css, &cgrp->self) { in update_effective_progs()
561 css_for_each_descendant_pre(css, &cgrp->self) { in update_effective_progs()
624 static int __cgroup_bpf_attach(struct cgroup *cgrp, in __cgroup_bpf_attach() argument
654 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_attach()
656 if (!hierarchy_allows_attach(cgrp, atype)) in __cgroup_bpf_attach()
659 if (!hlist_empty(progs) && cgrp->bpf.flags[atype] != saved_flags) in __cgroup_bpf_attach()
675 prog ? : link->link.prog, cgrp)) in __cgroup_bpf_attach()
702 cgrp->bpf.flags[atype] = saved_flags; in __cgroup_bpf_attach()
710 err = update_effective_progs(cgrp, atype); in __cgroup_bpf_attach()
721 bpf_cgroup_storages_link(new_storage, cgrp, type); in __cgroup_bpf_attach()
741 static int cgroup_bpf_attach(struct cgroup *cgrp, in cgroup_bpf_attach() argument
750 ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags); in cgroup_bpf_attach()
758 static void replace_effective_prog(struct cgroup *cgrp, in replace_effective_prog() argument
770 css_for_each_descendant_pre(css, &cgrp->self) { in replace_effective_prog()
810 static int __cgroup_bpf_replace(struct cgroup *cgrp, in __cgroup_bpf_replace() argument
824 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_replace()
839 replace_effective_prog(cgrp, atype, link); in __cgroup_bpf_replace()
910 static void purge_effective_progs(struct cgroup *cgrp, struct bpf_prog *prog, in purge_effective_progs() argument
922 css_for_each_descendant_pre(css, &cgrp->self) { in purge_effective_progs()
967 static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, in __cgroup_bpf_detach() argument
986 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_detach()
987 flags = cgrp->bpf.flags[atype]; in __cgroup_bpf_detach()
1002 if (update_effective_progs(cgrp, atype)) { in __cgroup_bpf_detach()
1006 purge_effective_progs(cgrp, old_prog, link, atype); in __cgroup_bpf_detach()
1015 cgrp->bpf.flags[atype] = 0; in __cgroup_bpf_detach()
1025 static int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, in cgroup_bpf_detach() argument
1031 ret = __cgroup_bpf_detach(cgrp, prog, NULL, type); in cgroup_bpf_detach()
1037 static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, in __cgroup_bpf_query() argument
1067 flags = cgrp->bpf.flags[from_atype]; in __cgroup_bpf_query()
1072 effective = rcu_dereference_protected(cgrp->bpf.effective[atype], in __cgroup_bpf_query()
1076 total_cnt += prog_list_length(&cgrp->bpf.progs[atype]); in __cgroup_bpf_query()
1097 effective = rcu_dereference_protected(cgrp->bpf.effective[atype], in __cgroup_bpf_query()
1107 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_query()
1120 flags = cgrp->bpf.flags[atype]; in __cgroup_bpf_query()
1136 static int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, in cgroup_bpf_query() argument
1142 ret = __cgroup_bpf_query(cgrp, attr, uattr); in cgroup_bpf_query()
1151 struct cgroup *cgrp; in cgroup_bpf_prog_attach() local
1154 cgrp = cgroup_get_from_fd(attr->target_fd); in cgroup_bpf_prog_attach()
1155 if (IS_ERR(cgrp)) in cgroup_bpf_prog_attach()
1156 return PTR_ERR(cgrp); in cgroup_bpf_prog_attach()
1162 cgroup_put(cgrp); in cgroup_bpf_prog_attach()
1167 ret = cgroup_bpf_attach(cgrp, prog, replace_prog, NULL, in cgroup_bpf_prog_attach()
1172 cgroup_put(cgrp); in cgroup_bpf_prog_attach()
1179 struct cgroup *cgrp; in cgroup_bpf_prog_detach() local
1182 cgrp = cgroup_get_from_fd(attr->target_fd); in cgroup_bpf_prog_detach()
1183 if (IS_ERR(cgrp)) in cgroup_bpf_prog_detach()
1184 return PTR_ERR(cgrp); in cgroup_bpf_prog_detach()
1190 ret = cgroup_bpf_detach(cgrp, prog, attr->attach_type); in cgroup_bpf_prog_detach()
1194 cgroup_put(cgrp); in cgroup_bpf_prog_detach()
1295 struct cgroup *cgrp; in cgroup_bpf_link_attach() local
1301 cgrp = cgroup_get_from_fd(attr->link_create.target_fd); in cgroup_bpf_link_attach()
1302 if (IS_ERR(cgrp)) in cgroup_bpf_link_attach()
1303 return PTR_ERR(cgrp); in cgroup_bpf_link_attach()
1312 link->cgroup = cgrp; in cgroup_bpf_link_attach()
1321 err = cgroup_bpf_attach(cgrp, NULL, NULL, link, in cgroup_bpf_link_attach()
1331 cgroup_put(cgrp); in cgroup_bpf_link_attach()
1338 struct cgroup *cgrp; in cgroup_bpf_prog_query() local
1341 cgrp = cgroup_get_from_fd(attr->query.target_fd); in cgroup_bpf_prog_query()
1342 if (IS_ERR(cgrp)) in cgroup_bpf_prog_query()
1343 return PTR_ERR(cgrp); in cgroup_bpf_prog_query()
1345 ret = cgroup_bpf_query(cgrp, attr, uattr); in cgroup_bpf_prog_query()
1347 cgroup_put(cgrp); in cgroup_bpf_prog_query()
1381 struct cgroup *cgrp; in __cgroup_bpf_run_filter_skb() local
1387 cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_skb()
1399 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, skb, in __cgroup_bpf_run_filter_skb()
1425 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, in __cgroup_bpf_run_filter_skb()
1455 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_sk() local
1457 return bpf_prog_run_array_cg(&cgrp->bpf, atype, sk, bpf_prog_run, 0, in __cgroup_bpf_run_filter_sk()
1493 struct cgroup *cgrp; in __cgroup_bpf_run_filter_sock_addr() local
1511 cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_sock_addr()
1512 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, in __cgroup_bpf_run_filter_sock_addr()
1542 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_sock_ops() local
1544 return bpf_prog_run_array_cg(&cgrp->bpf, atype, sock_ops, bpf_prog_run, in __cgroup_bpf_run_filter_sock_ops()
1552 struct cgroup *cgrp; in __cgroup_bpf_check_dev_permission() local
1561 cgrp = task_dfl_cgroup(current); in __cgroup_bpf_check_dev_permission()
1562 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, 0, in __cgroup_bpf_check_dev_permission()
1726 struct cgroup *cgrp; in __cgroup_bpf_run_filter_sysctl() local
1752 cgrp = task_dfl_cgroup(current); in __cgroup_bpf_run_filter_sysctl()
1753 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, 0, in __cgroup_bpf_run_filter_sysctl()
1820 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_setsockopt() local
1847 ret = bpf_prog_run_array_cg(&cgrp->bpf, CGROUP_SETSOCKOPT, in __cgroup_bpf_run_filter_setsockopt()
1912 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_getsockopt() local
1956 ret = bpf_prog_run_array_cg(&cgrp->bpf, CGROUP_GETSOCKOPT, in __cgroup_bpf_run_filter_getsockopt()
1996 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_getsockopt_kern() local
2016 ret = bpf_prog_run_array_cg(&cgrp->bpf, CGROUP_GETSOCKOPT, in __cgroup_bpf_run_filter_getsockopt_kern()