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()
391 static bool hierarchy_allows_attach(struct cgroup *cgrp, in hierarchy_allows_attach() argument
396 p = cgroup_parent(cgrp); in hierarchy_allows_attach()
420 static int compute_effective_progs(struct cgroup *cgrp, in compute_effective_progs() argument
427 struct cgroup *p = cgrp; in compute_effective_progs()
443 p = cgrp; in compute_effective_progs()
478 static void activate_effective_progs(struct cgroup *cgrp, in activate_effective_progs() argument
482 old_array = rcu_replace_pointer(cgrp->bpf.effective[atype], old_array, in activate_effective_progs()
494 int cgroup_bpf_inherit(struct cgroup *cgrp) in cgroup_bpf_inherit() argument
499 #define NR ARRAY_SIZE(cgrp->bpf.effective) in cgroup_bpf_inherit()
504 ret = percpu_ref_init(&cgrp->bpf.refcnt, cgroup_bpf_release_fn, 0, in cgroup_bpf_inherit()
509 for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p)) in cgroup_bpf_inherit()
513 INIT_HLIST_HEAD(&cgrp->bpf.progs[i]); in cgroup_bpf_inherit()
515 INIT_LIST_HEAD(&cgrp->bpf.storages); in cgroup_bpf_inherit()
518 if (compute_effective_progs(cgrp, i, &arrays[i])) in cgroup_bpf_inherit()
522 activate_effective_progs(cgrp, i, arrays[i]); in cgroup_bpf_inherit()
529 for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p)) in cgroup_bpf_inherit()
532 percpu_ref_exit(&cgrp->bpf.refcnt); in cgroup_bpf_inherit()
537 static int update_effective_progs(struct cgroup *cgrp, in update_effective_progs() argument
544 css_for_each_descendant_pre(css, &cgrp->self) { in update_effective_progs()
556 css_for_each_descendant_pre(css, &cgrp->self) { in update_effective_progs()
577 css_for_each_descendant_pre(css, &cgrp->self) { in update_effective_progs()
640 static int __cgroup_bpf_attach(struct cgroup *cgrp, in __cgroup_bpf_attach() argument
670 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_attach()
672 if (!hierarchy_allows_attach(cgrp, atype)) in __cgroup_bpf_attach()
675 if (!hlist_empty(progs) && cgrp->bpf.flags[atype] != saved_flags) in __cgroup_bpf_attach()
691 prog ? : link->link.prog, cgrp)) in __cgroup_bpf_attach()
719 cgrp->bpf.flags[atype] = saved_flags; in __cgroup_bpf_attach()
727 err = update_effective_progs(cgrp, atype); in __cgroup_bpf_attach()
738 bpf_cgroup_storages_link(new_storage, cgrp, type); in __cgroup_bpf_attach()
758 static int cgroup_bpf_attach(struct cgroup *cgrp, in cgroup_bpf_attach() argument
767 ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags); in cgroup_bpf_attach()
775 static void replace_effective_prog(struct cgroup *cgrp, in replace_effective_prog() argument
787 css_for_each_descendant_pre(css, &cgrp->self) { in replace_effective_prog()
827 static int __cgroup_bpf_replace(struct cgroup *cgrp, in __cgroup_bpf_replace() argument
841 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_replace()
856 replace_effective_prog(cgrp, atype, link); in __cgroup_bpf_replace()
927 static void purge_effective_progs(struct cgroup *cgrp, struct bpf_prog *prog, in purge_effective_progs() argument
939 css_for_each_descendant_pre(css, &cgrp->self) { in purge_effective_progs()
984 static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, in __cgroup_bpf_detach() argument
1003 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_detach()
1004 flags = cgrp->bpf.flags[atype]; in __cgroup_bpf_detach()
1019 if (update_effective_progs(cgrp, atype)) { in __cgroup_bpf_detach()
1023 purge_effective_progs(cgrp, old_prog, link, atype); in __cgroup_bpf_detach()
1032 cgrp->bpf.flags[atype] = 0; in __cgroup_bpf_detach()
1042 static int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, in cgroup_bpf_detach() argument
1048 ret = __cgroup_bpf_detach(cgrp, prog, NULL, type); in cgroup_bpf_detach()
1054 static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, in __cgroup_bpf_query() argument
1084 flags = cgrp->bpf.flags[from_atype]; in __cgroup_bpf_query()
1089 effective = rcu_dereference_protected(cgrp->bpf.effective[atype], in __cgroup_bpf_query()
1093 total_cnt += prog_list_length(&cgrp->bpf.progs[atype], NULL); in __cgroup_bpf_query()
1114 effective = rcu_dereference_protected(cgrp->bpf.effective[atype], in __cgroup_bpf_query()
1124 progs = &cgrp->bpf.progs[atype]; in __cgroup_bpf_query()
1137 flags = cgrp->bpf.flags[atype]; in __cgroup_bpf_query()
1153 static int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, in cgroup_bpf_query() argument
1159 ret = __cgroup_bpf_query(cgrp, attr, uattr); in cgroup_bpf_query()
1168 struct cgroup *cgrp; in cgroup_bpf_prog_attach() local
1171 cgrp = cgroup_get_from_fd(attr->target_fd); in cgroup_bpf_prog_attach()
1172 if (IS_ERR(cgrp)) in cgroup_bpf_prog_attach()
1173 return PTR_ERR(cgrp); in cgroup_bpf_prog_attach()
1179 cgroup_put(cgrp); in cgroup_bpf_prog_attach()
1184 ret = cgroup_bpf_attach(cgrp, prog, replace_prog, NULL, in cgroup_bpf_prog_attach()
1189 cgroup_put(cgrp); in cgroup_bpf_prog_attach()
1196 struct cgroup *cgrp; in cgroup_bpf_prog_detach() local
1199 cgrp = cgroup_get_from_fd(attr->target_fd); in cgroup_bpf_prog_detach()
1200 if (IS_ERR(cgrp)) in cgroup_bpf_prog_detach()
1201 return PTR_ERR(cgrp); in cgroup_bpf_prog_detach()
1207 ret = cgroup_bpf_detach(cgrp, prog, attr->attach_type); in cgroup_bpf_prog_detach()
1211 cgroup_put(cgrp); in cgroup_bpf_prog_detach()
1312 struct cgroup *cgrp; in cgroup_bpf_link_attach() local
1318 cgrp = cgroup_get_from_fd(attr->link_create.target_fd); in cgroup_bpf_link_attach()
1319 if (IS_ERR(cgrp)) in cgroup_bpf_link_attach()
1320 return PTR_ERR(cgrp); in cgroup_bpf_link_attach()
1329 link->cgroup = cgrp; in cgroup_bpf_link_attach()
1338 err = cgroup_bpf_attach(cgrp, NULL, NULL, link, in cgroup_bpf_link_attach()
1348 cgroup_put(cgrp); in cgroup_bpf_link_attach()
1355 struct cgroup *cgrp; in cgroup_bpf_prog_query() local
1358 cgrp = cgroup_get_from_fd(attr->query.target_fd); in cgroup_bpf_prog_query()
1359 if (IS_ERR(cgrp)) in cgroup_bpf_prog_query()
1360 return PTR_ERR(cgrp); in cgroup_bpf_prog_query()
1362 ret = cgroup_bpf_query(cgrp, attr, uattr); in cgroup_bpf_prog_query()
1364 cgroup_put(cgrp); in cgroup_bpf_prog_query()
1398 struct cgroup *cgrp; in __cgroup_bpf_run_filter_skb() local
1404 cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_skb()
1416 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, skb, in __cgroup_bpf_run_filter_skb()
1442 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, in __cgroup_bpf_run_filter_skb()
1472 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_sk() local
1474 return bpf_prog_run_array_cg(&cgrp->bpf, atype, sk, bpf_prog_run, 0, in __cgroup_bpf_run_filter_sk()
1510 struct cgroup *cgrp; in __cgroup_bpf_run_filter_sock_addr() local
1528 cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_sock_addr()
1529 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, in __cgroup_bpf_run_filter_sock_addr()
1559 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_sock_ops() local
1561 return bpf_prog_run_array_cg(&cgrp->bpf, atype, sock_ops, bpf_prog_run, in __cgroup_bpf_run_filter_sock_ops()
1569 struct cgroup *cgrp; in __cgroup_bpf_check_dev_permission() local
1578 cgrp = task_dfl_cgroup(current); in __cgroup_bpf_check_dev_permission()
1579 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, 0, in __cgroup_bpf_check_dev_permission()
1743 struct cgroup *cgrp; in __cgroup_bpf_run_filter_sysctl() local
1769 cgrp = task_dfl_cgroup(current); in __cgroup_bpf_run_filter_sysctl()
1770 ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, 0, in __cgroup_bpf_run_filter_sysctl()
1837 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_setsockopt() local
1864 ret = bpf_prog_run_array_cg(&cgrp->bpf, CGROUP_SETSOCKOPT, in __cgroup_bpf_run_filter_setsockopt()
1929 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_getsockopt() local
1973 ret = bpf_prog_run_array_cg(&cgrp->bpf, CGROUP_GETSOCKOPT, in __cgroup_bpf_run_filter_getsockopt()
2013 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); in __cgroup_bpf_run_filter_getsockopt_kern() local
2033 ret = bpf_prog_run_array_cg(&cgrp->bpf, CGROUP_GETSOCKOPT, in __cgroup_bpf_run_filter_getsockopt_kern()